mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
changes to IM that came from Petr and JimW's review.
This commit is contained in:
@ -50,7 +50,7 @@ int HandleServiceOptions(Options options)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_info("Service failed to install\n");
|
log_info("Service failed to install\n");
|
||||||
ret_val= -1;
|
ret_val= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (options.remove_service)
|
else if (options.remove_service)
|
||||||
@ -62,10 +62,10 @@ int HandleServiceOptions(Options options)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_info("Service failed to remove\n");
|
log_info("Service failed to remove\n");
|
||||||
ret_val= -1;
|
ret_val= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return (int)winService.Init();
|
ret_val= winService.Init() ? 0 : 1;
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ int HandleServiceOptions(Options options);
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
int return_value= 1;
|
||||||
init_environment(argv[0]);
|
init_environment(argv[0]);
|
||||||
Options options;
|
Options options;
|
||||||
struct passwd *user_info;
|
struct passwd *user_info;
|
||||||
@ -90,10 +91,7 @@ int main(int argc, char *argv[])
|
|||||||
if ((user_info= check_user(options.user)))
|
if ((user_info= check_user(options.user)))
|
||||||
{
|
{
|
||||||
if (set_user(options.user, user_info))
|
if (set_user(options.user, user_info))
|
||||||
{
|
|
||||||
options.cleanup();
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.run_as_service)
|
if (options.run_as_service)
|
||||||
@ -105,17 +103,18 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
return HandleServiceOptions(options);
|
return_value= HandleServiceOptions(options);
|
||||||
|
goto err; /* this is not always an error but we reuse the label */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
manager(options);
|
manager(options);
|
||||||
|
return_value= 0;
|
||||||
|
|
||||||
|
err:
|
||||||
options.cleanup();
|
options.cleanup();
|
||||||
my_end(0);
|
my_end(0);
|
||||||
return 0;
|
return return_value;
|
||||||
err:
|
|
||||||
my_end(0);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************* Auxilary functions implementation **********************/
|
/******************* Auxilary functions implementation **********************/
|
||||||
|
@ -30,18 +30,20 @@
|
|||||||
#define QUOTE2(x) #x
|
#define QUOTE2(x) #x
|
||||||
#define QUOTE(x) QUOTE2(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);
|
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
char windows_config_file[FN_REFLEN];
|
|
||||||
|
|
||||||
char Options::install_as_service;
|
char Options::install_as_service;
|
||||||
char Options::remove_service;
|
char Options::remove_service;
|
||||||
|
char windows_config_file[FN_REFLEN];
|
||||||
|
char default_password_file_name[FN_REFLEN];
|
||||||
|
char default_log_file_name[FN_REFLEN];
|
||||||
|
const char *Options::config_file= windows_config_file;
|
||||||
#else
|
#else
|
||||||
char Options::run_as_service;
|
char Options::run_as_service;
|
||||||
const char *Options::user= 0; /* No default value */
|
const char *Options::user= 0; /* No default value */
|
||||||
#endif
|
const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
|
||||||
|
const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
|
||||||
const char *Options::config_file= QUOTE(DEFAULT_CONFIG_FILE);
|
const char *Options::config_file= QUOTE(DEFAULT_CONFIG_FILE);
|
||||||
|
#endif
|
||||||
const char *Options::log_file_name= default_log_file_name;
|
const char *Options::log_file_name= default_log_file_name;
|
||||||
const char *Options::pid_file_name= QUOTE(DEFAULT_PID_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::socket_file_name= QUOTE(DEFAULT_SOCKET_FILE_NAME);
|
||||||
@ -51,7 +53,7 @@ const char *Options::bind_address= 0; /* No default value */
|
|||||||
uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
|
uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
|
||||||
uint Options::port_number= DEFAULT_PORT;
|
uint Options::port_number= DEFAULT_PORT;
|
||||||
/* just to declare */
|
/* just to declare */
|
||||||
char **Options::saved_argv;
|
char **Options::saved_argv= NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
List of options, accepted by the instance manager.
|
List of options, accepted by the instance manager.
|
||||||
@ -262,30 +264,8 @@ int Options::load(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
setup_windows_defaults(*argv);
|
if (setup_windows_defaults())
|
||||||
|
goto err;
|
||||||
/*
|
|
||||||
On Windows, there are two possibilities. Either we are given
|
|
||||||
a defaults file on the command line or we use the my.ini file
|
|
||||||
that is in our app dir
|
|
||||||
*/
|
|
||||||
if (Options::config_file == NULL)
|
|
||||||
{
|
|
||||||
char *filename;
|
|
||||||
static const char default_win_config_file_name[]= "\\my.ini";
|
|
||||||
|
|
||||||
if (!GetModuleFileName(NULL, windows_config_file,
|
|
||||||
sizeof(windows_config_file)))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
filename= strrchr(windows_config_file, "\\");
|
|
||||||
/*
|
|
||||||
Don't check for the overflow as strlen("\\my.ini") is less
|
|
||||||
then strlen("mysqlmanager") (the binary name)
|
|
||||||
*/
|
|
||||||
strcpy(filename, default_win_config_file_name);
|
|
||||||
Options::config_file= windows_config_file;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* config-file options are prepended to command-line ones */
|
/* config-file options are prepended to command-line ones */
|
||||||
@ -305,33 +285,32 @@ err:
|
|||||||
void Options::cleanup()
|
void Options::cleanup()
|
||||||
{
|
{
|
||||||
/* free_defaults returns nothing */
|
/* free_defaults returns nothing */
|
||||||
free_defaults(Options::saved_argv);
|
if (Options::saved_argv != NULL)
|
||||||
#ifdef __WIN__
|
free_defaults(Options::saved_argv);
|
||||||
free((char*)default_password_file_name);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WIN__
|
#ifdef __WIN__
|
||||||
|
|
||||||
char* change_extension(const char *src, const char *newext)
|
void Options::setup_windows_defaults()
|
||||||
{
|
{
|
||||||
char *dot= (char*)strrchr(src, '.');
|
if (!GetModuleFileName(NULL, default_password_file_name,
|
||||||
if (!dot) return (char*)src;
|
sizeof(default_password_file_name)))
|
||||||
|
return -1;
|
||||||
|
char *filename = strstr(default_password_file_name, ".exe");
|
||||||
|
strcpy(filename, ".passwd");
|
||||||
|
|
||||||
|
if (!GetModuleFileName(NULL, default_log_file_name,
|
||||||
|
sizeof(default_log_file_name)))
|
||||||
|
return -1;
|
||||||
|
filename = strstr(default_log_file_name, ".exe");
|
||||||
|
strcpy(filename, ".log");
|
||||||
|
|
||||||
int newlen= dot-src+strlen(newext)+1;
|
if (!GetModuleFileName(NULL, windows_config_file,
|
||||||
char *temp= (char*)malloc(newlen);
|
sizeof(windows_config_file)))
|
||||||
bzero(temp, newlen);
|
return -1;
|
||||||
strncpy(temp, src, dot-src+1);
|
char *slash = strrchr(windows_config_file, '\\');
|
||||||
strcat(temp, newext);
|
strcpy(slash, "\\my.ini");
|
||||||
return temp;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
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
|
#endif
|
||||||
|
Reference in New Issue
Block a user