summaryrefslogtreecommitdiff
path: root/server-tools/instance-manager/instance_options.cc
diff options
context:
space:
mode:
authorunknown <petr@mysql.com>2005-01-25 13:54:56 +0300
committerunknown <petr@mysql.com>2005-01-25 13:54:56 +0300
commitfb3d6c39a0dc128f5310aac2906cc1e6c6b7db59 (patch)
treeada085796e1dc8387942522e6233d9a1b1a1d6d3 /server-tools/instance-manager/instance_options.cc
parent28f86d8ff1d042a2224c64712e31c65b1d6b7476 (diff)
downloadmariadb-git-fb3d6c39a0dc128f5310aac2906cc1e6c6b7db59.tar.gz
IM mostly fixed according to Brian's directions. Will need to do some additional option handling and cleanups
server-tools/instance-manager/Makefile.am: New file added server-tools/instance-manager/client_func.c: typo fixed server-tools/instance-manager/commands.cc: there are no admin-user snd admin-password fields anymore, so no need to show their values server-tools/instance-manager/guardian.cc: Syncronization added -- now guardian wakes up whenever SIGCLD has been catched server-tools/instance-manager/guardian.h: Condition variable declared server-tools/instance-manager/instance.cc: Persistent connection to the instance removed. Now we use SIGTERM instead of com_shutdown for STOP. We also manage SIGCHLD ourselves now (therefore no double fork). server-tools/instance-manager/instance.h: Pointer to the instance_map added, MySQL connection structures removed server-tools/instance-manager/instance_map.cc: More syncronization added (to make proper STOP) server-tools/instance-manager/instance_map.h: added condition variable and mutex for connection threads to wait for SIGCHLD server-tools/instance-manager/instance_options.cc: defaults-handling methods have been added. server-tools/instance-manager/instance_options.h: New functions and constants declared server-tools/instance-manager/listener.cc: No changes here (bk bug?) server-tools/instance-manager/manager.cc: SIGCHLD handling added
Diffstat (limited to 'server-tools/instance-manager/instance_options.cc')
-rw-r--r--server-tools/instance-manager/instance_options.cc131
1 files changed, 113 insertions, 18 deletions
diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc
index fab69865c85..c29f136955e 100644
--- a/server-tools/instance-manager/instance_options.cc
+++ b/server-tools/instance-manager/instance_options.cc
@@ -19,20 +19,105 @@
#endif
#include "instance_options.h"
+#include "parse_output.h"
+#include "buffer.h"
#include <my_sys.h>
#include <mysql.h>
#include <signal.h>
#include <m_string.h>
+
+/* option_name should be prefixed with "--" */
+int Instance_options::get_default_option(char *result, const char *option_name,
+ size_t result_len)
+{
+ int position= 0;
+ char verbose_option[]= " --no-defaults --verbose --help";
+ Buffer cmd;
+
+ cmd.append(position, mysqld_path, strlen(mysqld_path));
+ position+= strlen(mysqld_path);
+ cmd.append(position, verbose_option, sizeof(verbose_option) - 1);
+ position+= sizeof(verbose_option) - 1;
+ cmd.append(position, "\0", 1);
+ /* get the value from "mysqld --help --verbose" */
+ if (parse_output_and_get_value(cmd.buffer, option_name + 2,
+ result, result_len))
+ return 1;
+
+ return 0;
+}
+
+
+void Instance_options::get_pid_filename(char *result)
+{
+ const char *pid_file= mysqld_pid_file;
+ char datadir[MAX_PATH_LEN];
+
+ if (mysqld_datadir == NULL)
+ {
+ get_default_option(datadir, "--datadir", MAX_PATH_LEN);
+ }
+ else
+ strxnmov(datadir, MAX_PATH_LEN - 1, strchr(mysqld_datadir, '=') + 1,
+ "/", NullS);
+
+ /* well, we should never get it */
+ if (mysqld_pid_file != NULL)
+ pid_file= strchr(pid_file, '=') + 1;
+ else
+ DBUG_ASSERT(0);
+
+ /* get the full path to the pidfile */
+ my_load_path(result, pid_file, datadir);
+
+}
+
+
+int Instance_options::unlink_pidfile()
+{
+ char pid_file_path[MAX_PATH_LEN];
+
+ /*
+ This works as we know that pid_file_path is of
+ MAX_PATH_LEN == FN_REFLEN length
+ */
+ get_pid_filename((char *)&pid_file_path);
+
+ return unlink(pid_file_path);
+}
+
+
+pid_t Instance_options::get_pid()
+{
+ char pid_file_path[MAX_PATH_LEN];
+
+ /*
+ This works as we know that pid_file_path is of
+ MAX_PATH_LEN == FN_REFLEN length
+ */
+ get_pid_filename((char *)&pid_file_path);
+
+ /* get the pid */
+ if (FILE *pid_file_stream= my_fopen(pid_file_path,
+ O_RDONLY | O_BINARY, MYF(0)))
+ {
+ pid_t pid;
+
+ fscanf(pid_file_stream, "%i", &pid);
+ my_fclose(pid_file_stream, MYF(0));
+ return pid;
+ }
+ else
+ return 0;
+}
+
+
int Instance_options::complete_initialization(const char *default_path,
const char *default_user,
const char *default_password)
{
- /* we need to reserve space for the final zero + possible default options */
- if (!(argv= (char**) alloc_root(&alloc, (options_array.elements + 1
- + MAX_NUMBER_OF_DEFAULT_OPTIONS) * sizeof(char*))))
- goto err;
-
+ const char *tmp;
if (mysqld_path == NULL)
{
@@ -40,22 +125,34 @@ int Instance_options::complete_initialization(const char *default_path,
goto err;
}
- /* this option must be first in the argv */
- if (add_to_argv(mysqld_path))
+ if (!(tmp= strdup_root(&alloc, "--no-defaults")))
goto err;
- /* the following options are not for argv */
- if (mysqld_user == NULL)
+ if (mysqld_pid_file == NULL)
{
- if (!(mysqld_user= strdup_root(&alloc, default_user)))
- goto err;
+ char pidfilename[MAX_PATH_LEN];
+ char hostname[MAX_PATH_LEN];
+ if (!gethostname(hostname, sizeof(hostname) - 1))
+ strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", hostname, "-",
+ instance_name, ".pid", NullS);
+ else
+ strxnmov(pidfilename, MAX_PATH_LEN - 1, "--pid-file=", instance_name,
+ ".pid", NullS);
+
+ add_option(pidfilename);
}
- if (mysqld_password == NULL)
- {
- if (!(mysqld_password= strdup_root(&alloc, default_password)))
- goto err;
- }
+ /* we need to reserve space for the final zero + possible default options */
+ if (!(argv= (char**) alloc_root(&alloc, (options_array.elements + 1
+ + MAX_NUMBER_OF_DEFAULT_OPTIONS) * sizeof(char*))))
+ goto err;
+
+ /* the path must be first in the argv */
+ if (add_to_argv(mysqld_path))
+ goto err;
+
+ if (add_to_argv(tmp))
+ goto err;
memcpy((gptr) (argv + filled_default_options), options_array.buffer,
options_array.elements*sizeof(char*));
@@ -102,8 +199,6 @@ int Instance_options::add_option(const char* option)
{"--bind-address=", 15, &mysqld_bind_address, SAVE_WHOLE_AND_ADD},
{"--pid-file=", 11, &mysqld_pid_file, SAVE_WHOLE_AND_ADD},
{"--mysqld-path=", 14, &mysqld_path, SAVE_VALUE},
- {"--admin-user=", 13, &mysqld_user, SAVE_VALUE},
- {"--admin-password=", 17, &mysqld_password, SAVE_VALUE},
{"--guarded", 9, &is_guarded, SAVE_WHOLE},
{NULL, 0, NULL, 0}
};