summaryrefslogtreecommitdiff
path: root/server-tools/instance-manager/options.cc
diff options
context:
space:
mode:
authorunknown <reggie@fedora.(none)>2005-07-20 10:55:40 -0500
committerunknown <reggie@fedora.(none)>2005-07-20 10:55:40 -0500
commit875b0e6322df380b6fcd4bd4f66d0d3e0142039f (patch)
treefd59532b923e8ee6c5bb48afac93f8d93e48fec6 /server-tools/instance-manager/options.cc
parent6ae060305541019882bcb60bf086458b010faa45 (diff)
downloadmariadb-git-875b0e6322df380b6fcd4bd4f66d0d3e0142039f.tar.gz
initial import of Windows port of IM.
server-tools/instance-manager/commands.cc: type cleanups for compiling on Windows now using Options::config_file for the location of the single my.cnf file we are using server-tools/instance-manager/guardian.cc: pthread_mutex_lock and unlock do not return a value on Windows so we return 0 in all cases server-tools/instance-manager/instance.cc: big changes here. Had to implement Windows versions of launch_and_wait and kill() server-tools/instance-manager/instance.h: added some function defs server-tools/instance-manager/instance_map.cc: pthread_mutex_lock and unlock do not return a value on Windows Also, now using only the file named as Options::config_file server-tools/instance-manager/instance_options.h: added reference to port.h server-tools/instance-manager/listener.cc: reworked and simplified the socket handling code. Added windows versions of the code that sets the sockets to be non-blocking and non-inheritable server-tools/instance-manager/listener.h: change Options to always be a struct. Really surprised GCC was letting this go. Options was declared to be struct in some places and class in other places. server-tools/instance-manager/log.cc: added reference to port.h server-tools/instance-manager/manager.cc: moved all the signal code inside some #ifndef __WIN__ blocks server-tools/instance-manager/manager.h: change Options to always be a struct. Really surprised GCC was letting this go. Options was declared to be struct in some places and class in other places. server-tools/instance-manager/mysqlmanager.cc: added in the Windows service code. server-tools/instance-manager/options.cc: Added in the windows options for running as a service and the code for loading settings only from a single file server-tools/instance-manager/options.h: added definitions for the new Windows service vars and routines server-tools/instance-manager/parse_output.cc: added reference to port.h server-tools/instance-manager/priv.cc: added reference to port.h server-tools/instance-manager/priv.h: linuxthreads should not be visible on Windows server-tools/instance-manager/thread_registry.cc: more __WIN__ blocking server-tools/instance-manager/user_map.cc: fixed passwd file code to handle files with \r\n line endings server-tools/instance-manager/IMService.cpp: New BitKeeper file ``server-tools/instance-manager/IMService.cpp'' server-tools/instance-manager/IMService.h: New BitKeeper file ``server-tools/instance-manager/IMService.h'' server-tools/instance-manager/WindowsService.cpp: New BitKeeper file ``server-tools/instance-manager/WindowsService.cpp'' server-tools/instance-manager/WindowsService.h: New BitKeeper file ``server-tools/instance-manager/WindowsService.h'' server-tools/instance-manager/mysqlmanager.vcproj: New BitKeeper file ``server-tools/instance-manager/mysqlmanager.vcproj'' server-tools/instance-manager/port.h: New BitKeeper file ``server-tools/instance-manager/port.h''
Diffstat (limited to 'server-tools/instance-manager/options.cc')
-rw-r--r--server-tools/instance-manager/options.cc91
1 files changed, 82 insertions, 9 deletions
diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc
index e44e4c6ff34..f563fa783d2 100644
--- a/server-tools/instance-manager/options.cc
+++ b/server-tools/instance-manager/options.cc
@@ -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);
- Options::saved_argv= argv;
+ load_defaults(config_file, default_groups, &argc, &argv);
+
+ rc= handle_options(&argc, &argv, my_long_options, get_one_option);
- if ((rc= handle_options(&argc, &argv, my_long_options, get_one_option)) != 0)
+ if (rc != 0)
return rc;
+
+ Options::saved_argv= argv;
+
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