mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
initial import of Windows port of IM.
This commit is contained in:
@ -21,7 +21,7 @@
|
||||
#include "options.h"
|
||||
|
||||
#include "priv.h"
|
||||
|
||||
#include "port.h"
|
||||
#include <my_sys.h>
|
||||
#include <my_getopt.h>
|
||||
#include <m_string.h>
|
||||
@ -30,19 +30,29 @@
|
||||
#define QUOTE2(x) #x
|
||||
#define QUOTE(x) QUOTE2(x)
|
||||
|
||||
const char *default_password_file_name = QUOTE(DEFAULT_PASSWORD_FILE_NAME);
|
||||
const char *default_log_file_name = QUOTE(DEFAULT_LOG_FILE_NAME);
|
||||
char default_config_file[FN_REFLEN] = "/etc/my.cnf";
|
||||
|
||||
#ifndef __WIN__
|
||||
char Options::run_as_service;
|
||||
const char *Options::log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
|
||||
const char *Options::user= 0; /* No default value */
|
||||
#else
|
||||
char Options::install_as_service;
|
||||
char Options::remove_service;
|
||||
#endif
|
||||
const char *Options::log_file_name= default_log_file_name;
|
||||
const char *Options::pid_file_name= QUOTE(DEFAULT_PID_FILE_NAME);
|
||||
const char *Options::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME);
|
||||
const char *Options::password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
|
||||
const char *Options::password_file_name= default_password_file_name;
|
||||
const char *Options::default_mysqld_path= QUOTE(DEFAULT_MYSQLD_PATH);
|
||||
const char *Options::first_option= 0; /* No default value */
|
||||
const char *Options::bind_address= 0; /* No default value */
|
||||
const char *Options::user= 0; /* No default value */
|
||||
uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
|
||||
uint Options::port_number= DEFAULT_PORT;
|
||||
/* just to declare */
|
||||
char **Options::saved_argv;
|
||||
const char *Options::config_file = NULL;
|
||||
|
||||
/*
|
||||
List of options, accepted by the instance manager.
|
||||
@ -55,8 +65,13 @@ enum options {
|
||||
OPT_SOCKET,
|
||||
OPT_PASSWORD_FILE,
|
||||
OPT_MYSQLD_PATH,
|
||||
#ifndef __WIN__
|
||||
OPT_RUN_AS_SERVICE,
|
||||
OPT_USER,
|
||||
#else
|
||||
OPT_INSTALL_SERVICE,
|
||||
OPT_REMOVE_SERVICE,
|
||||
#endif
|
||||
OPT_MONITORING_INTERVAL,
|
||||
OPT_PORT,
|
||||
OPT_BIND_ADDRESS
|
||||
@ -107,7 +122,14 @@ static struct my_option my_long_options[] =
|
||||
(gptr *) &Options::monitoring_interval,
|
||||
0, GET_UINT, REQUIRED_ARG, DEFAULT_MONITORING_INTERVAL,
|
||||
0, 0, 0, 0, 0 },
|
||||
|
||||
#ifdef __WIN__
|
||||
{ "install", OPT_INSTALL_SERVICE, "Install as system service.",
|
||||
(gptr *) &Options::install_as_service, (gptr*) &Options::install_as_service,
|
||||
0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 },
|
||||
{ "remove", OPT_REMOVE_SERVICE, "Remove system service.",
|
||||
(gptr *)&Options::remove_service, (gptr*) &Options::remove_service,
|
||||
0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0},
|
||||
#else
|
||||
{ "run-as-service", OPT_RUN_AS_SERVICE,
|
||||
"Daemonize and start angel process.", (gptr *) &Options::run_as_service,
|
||||
0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 },
|
||||
@ -116,7 +138,7 @@ static struct my_option my_long_options[] =
|
||||
(gptr *) &Options::user,
|
||||
(gptr *) &Options::user,
|
||||
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
|
||||
|
||||
#endif
|
||||
{ "version", 'V', "Output version information and exit.", 0, 0, 0,
|
||||
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
|
||||
|
||||
@ -214,20 +236,44 @@ C_MODE_END
|
||||
int Options::load(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
char** argv_ptr = argv;
|
||||
|
||||
#ifdef __WIN__
|
||||
setup_windows_defaults(*argv);
|
||||
#endif
|
||||
|
||||
config_file=NULL;
|
||||
if (argc >= 2)
|
||||
{
|
||||
if (is_prefix(argv[1], "--defaults-file="))
|
||||
config_file=argv[1];
|
||||
if (is_prefix(argv[1],"--defaults-file=") ||
|
||||
is_prefix(argv[1],"--defaults-extra-file="))
|
||||
Options::first_option= argv[1];
|
||||
}
|
||||
|
||||
// we were not given a config file on the command line so we
|
||||
// set have to construct a new argv array
|
||||
if (config_file == NULL)
|
||||
{
|
||||
#ifdef __WIN__
|
||||
::GetModuleFileName(NULL, default_config_file, sizeof(default_config_file));
|
||||
char *filename = strstr(default_config_file, "mysqlmanager.exe");
|
||||
strcpy(filename, "my.ini");
|
||||
#endif
|
||||
config_file = default_config_file;
|
||||
}
|
||||
|
||||
/* config-file options are prepended to command-line ones */
|
||||
load_defaults("my", default_groups, &argc, &argv);
|
||||
load_defaults(config_file, default_groups, &argc, &argv);
|
||||
|
||||
rc= handle_options(&argc, &argv, my_long_options, get_one_option);
|
||||
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
Options::saved_argv= argv;
|
||||
|
||||
if ((rc= handle_options(&argc, &argv, my_long_options, get_one_option)) != 0)
|
||||
return rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -235,4 +281,31 @@ void Options::cleanup()
|
||||
{
|
||||
/* free_defaults returns nothing */
|
||||
free_defaults(Options::saved_argv);
|
||||
|
||||
#ifdef __WIN__
|
||||
free((char*)default_password_file_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __WIN__
|
||||
|
||||
char* change_extension(const char *src, const char *newext)
|
||||
{
|
||||
char *dot = (char*)strrchr(src, '.');
|
||||
if (!dot) return (char*)src;
|
||||
|
||||
int newlen = dot-src+strlen(newext)+1;
|
||||
char *temp = (char*)malloc(newlen);
|
||||
bzero(temp, newlen);
|
||||
strncpy(temp, src, dot-src+1);
|
||||
strcat(temp, newext);
|
||||
return temp;
|
||||
}
|
||||
|
||||
void Options::setup_windows_defaults(const char *progname)
|
||||
{
|
||||
Options::password_file_name = default_password_file_name = change_extension(progname, "passwd");
|
||||
Options::log_file_name = default_log_file_name = change_extension(progname, "log");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user