mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
IM mostly fixed according to Brian's directions. Will need to do some additional option handling and cleanups
This commit is contained in:
@ -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 (!(tmp= strdup_root(&alloc, "--no-defaults")))
|
||||
goto err;
|
||||
|
||||
if (mysqld_pid_file == NULL)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
/* the following options are not for argv */
|
||||
if (mysqld_user == NULL)
|
||||
{
|
||||
if (!(mysqld_user= strdup_root(&alloc, default_user)))
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (mysqld_password == NULL)
|
||||
{
|
||||
if (!(mysqld_password= strdup_root(&alloc, default_password)))
|
||||
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}
|
||||
};
|
||||
|
Reference in New Issue
Block a user