summaryrefslogtreecommitdiff
path: root/server-tools/instance-manager/instance_options.cc
diff options
context:
space:
mode:
authorunknown <petr@mysql.com>2005-02-11 14:21:59 +0300
committerunknown <petr@mysql.com>2005-02-11 14:21:59 +0300
commitdce2554f9130920ab18e4e31432df7d6ca165ee0 (patch)
tree5a46c104b5146373b9e754ea5691cfa5ef3d2fcf /server-tools/instance-manager/instance_options.cc
parent79ba407d64ad4387b7b279f80a7bf95e68414df5 (diff)
downloadmariadb-git-dce2554f9130920ab18e4e31432df7d6ca165ee0.tar.gz
Post-review fixes + some bugs fixed + several minor features
BitKeeper/deleted/.del-client_func.c~3476a8a85cbd3c29: Delete: server-tools/instance-manager/client_func.c server-tools/instance-manager/Makefile.am: clien_func removed server-tools/instance-manager/buffer.cc: several methods added server-tools/instance-manager/buffer.h: Some error-handling fixes. server-tools/instance-manager/commands.cc: check for Buffer errors server-tools/instance-manager/guardian.cc: Guardian rewiriten. Not it works in a finite state machine-way. server-tools/instance-manager/guardian.h: Appropriate (to .cc) changes in the header + some comment added server-tools/instance-manager/instance.cc: added proxy thread to monitor instance. Two kinds of stop() now -- stop() and kill_instance which only sends a signal server-tools/instance-manager/instance.h: appropriate changes server-tools/instance-manager/instance_map.cc: cleanup server-tools/instance-manager/instance_map.h: cleanup server-tools/instance-manager/instance_options.cc: Caching of the pid-file-name is added. some comments added server-tools/instance-manager/instance_options.h: cleanup server-tools/instance-manager/listener.cc: listener my_thread_init added (though it doesn't use any mysys functions). Just in case server-tools/instance-manager/manager.cc: SIGCHLD handler removed. now instance monitoring is implemented through proxy threads. This is to work nicely with LinuxThreads server-tools/instance-manager/options.cc: added option to create a password file entry (this was implemented by Sergei Vojtovich) server-tools/instance-manager/parse.cc: inline function get_word moved to the header server-tools/instance-manager/parse.h: get_word moved here to use form parse_output server-tools/instance-manager/parse_output.cc: get_word() clone removed. now looking through the output linewise server-tools/instance-manager/protocol.cc: Buffer error chech added server-tools/instance-manager/user_map.cc: typo fixed
Diffstat (limited to 'server-tools/instance-manager/instance_options.cc')
-rw-r--r--server-tools/instance-manager/instance_options.cc91
1 files changed, 51 insertions, 40 deletions
diff --git a/server-tools/instance-manager/instance_options.cc b/server-tools/instance-manager/instance_options.cc
index e7e17691330..ab97c86316b 100644
--- a/server-tools/instance-manager/instance_options.cc
+++ b/server-tools/instance-manager/instance_options.cc
@@ -27,25 +27,50 @@
#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)
+/*
+ Get compiled-in value of default_option
+
+ SYNOPSYS
+ get_default_option()
+ result buffer to put found value
+ result_len buffer size
+ oprion_name the name of the option, prefixed with "--"
+
+ DESCRIPTION
+
+ Get compile-in value of requested option from server
+
+ RETURN
+ 0 - ok
+ 1 - error occured
+*/
+
+int Instance_options::get_default_option(char *result, size_t result_len,
+ const char *option_name)
{
int position= 0;
+ int rc= 1;
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;
+ Buffer cmd(strlen(mysqld_path)+sizeof(verbose_option)+1);
+ if (cmd.get_size()) /* malloc succeeded */
+ {
+ 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);
+
+ if (cmd.is_error())
+ goto err;
+ /* get the value from "mysqld --help --verbose" */
+ rc= parse_output_and_get_value(cmd.buffer, option_name + 2,
+ result, result_len);
+ }
+
+ return rc;
+err:
+ return 1;
}
@@ -56,51 +81,33 @@ void Instance_options::get_pid_filename(char *result)
if (mysqld_datadir == NULL)
{
- get_default_option(datadir, "--datadir", MAX_PATH_LEN);
+ get_default_option(datadir, sizeof(datadir), "--datadir");
}
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);
+ DBUG_ASSERT(mysqld_pid_file);
+ pid_file= strchr(pid_file, '=') + 1;
/* 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);
+ return unlink(pid_file_with_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);
+ FILE *pid_file_stream;
/* get the pid */
- if (FILE *pid_file_stream= my_fopen(pid_file_path,
- O_RDONLY | O_BINARY, MYF(0)))
+ if (pid_file_stream= my_fopen(pid_file_with_path,
+ O_RDONLY | O_BINARY, MYF(0)))
{
pid_t pid;
@@ -140,6 +147,8 @@ int Instance_options::complete_initialization(const char *default_path)
add_option(pidfilename);
}
+ get_pid_filename(pid_file_with_path);
+
/* 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*))))
@@ -244,6 +253,8 @@ int Instance_options::add_to_argv(const char* option)
return 0;
}
+
+/* function for debug purposes */
void Instance_options::print_argv()
{
int i;