2003-08-16 19:44:24 +02:00
|
|
|
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
2003-08-19 17:55:20 +02:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2003-08-16 19:44:24 +02:00
|
|
|
#include "options.h"
|
|
|
|
|
|
|
|
#include <my_global.h>
|
|
|
|
#include <my_sys.h>
|
|
|
|
#include <my_getopt.h>
|
|
|
|
|
|
|
|
|
|
|
|
#define QUOTE2(x) #x
|
|
|
|
#define QUOTE(x) QUOTE2(x)
|
|
|
|
|
|
|
|
char Options::run_as_service;
|
|
|
|
const char *Options::log_file_name= QUOTE(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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
List of options, accepted by the instance manager.
|
|
|
|
List must be closed with empty option.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum options {
|
|
|
|
OPT_LOG= 256,
|
|
|
|
OPT_PID_FILE,
|
|
|
|
OPT_SOCKET,
|
|
|
|
OPT_RUN_AS_SERVICE
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct my_option my_long_options[] =
|
|
|
|
{
|
|
|
|
{ "help", '?', "Display this help and exit.",
|
|
|
|
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
|
|
|
|
|
|
|
|
{ "log", OPT_LOG, "Path to log file. Used only with --run-as-service.",
|
|
|
|
(gptr *) &Options::log_file_name, (gptr *) &Options::log_file_name,
|
|
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
|
|
|
|
|
|
|
|
{ "pid-file", OPT_PID_FILE, "Pid file to use.",
|
|
|
|
(gptr *) &Options::pid_file_name, (gptr *) &Options::pid_file_name,
|
|
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
|
|
|
|
|
|
|
|
{ "socket", OPT_SOCKET, "Socket file to use for connection.",
|
|
|
|
(gptr *) &Options::socket_file_name, (gptr *) &Options::socket_file_name,
|
|
|
|
0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
|
|
|
|
|
|
|
|
{ "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 },
|
|
|
|
|
|
|
|
{ "version", 'V', "Output version information and exit.", 0, 0, 0,
|
|
|
|
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 },
|
|
|
|
|
|
|
|
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void version()
|
|
|
|
{
|
|
|
|
static const char mysqlmanager_version[] = "0.1-alpha";
|
|
|
|
printf("%s Ver %s for %s on %s\n", my_progname, mysqlmanager_version,
|
|
|
|
SYSTEM_TYPE, MACHINE_TYPE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void usage()
|
|
|
|
{
|
|
|
|
version();
|
|
|
|
my_print_help(my_long_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
C_MODE_START
|
|
|
|
|
|
|
|
static my_bool
|
|
|
|
get_one_option(int optid,
|
|
|
|
const struct my_option *opt __attribute__((unused)),
|
|
|
|
char *argument __attribute__((unused)))
|
|
|
|
{
|
|
|
|
switch(optid) {
|
|
|
|
case 'V':
|
|
|
|
version();
|
|
|
|
exit(0);
|
|
|
|
case 'I':
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
C_MODE_END
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
- call load_defaults to load configuration file section
|
|
|
|
- call handle_options to assign defaults and command-line arguments
|
|
|
|
to the class members
|
|
|
|
if either of these function fail, exit the program
|
|
|
|
May not return.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Options::load(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (int rc= handle_options(&argc, &argv, my_long_options, get_one_option))
|
|
|
|
exit(rc);
|
|
|
|
}
|
|
|
|
|