summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorunknown <sasha@mysql.sashanet.com>2001-11-07 16:53:11 -0700
committerunknown <sasha@mysql.sashanet.com>2001-11-07 16:53:11 -0700
commit91fb1d23770503d29744fc0c973065decd1bf0a1 (patch)
treed3db56314fc156ded359f4215bf7323fce62b131 /tools
parent356003a8c9d939dc5c95f50539d3916e404d25a9 (diff)
parent3c4e170d806a1c3c623bf8a777fa1f6ba4bb6015 (diff)
downloadmariadb-git-91fb1d23770503d29744fc0c973065decd1bf0a1.tar.gz
Merge work:/home/bk/mysql-4.0
into mysql.sashanet.com:/home/sasha/src/bk/mysql-4.0 BitKeeper/etc/ignore: auto-union mysql-test/mysql-test-run.sh: Auto merged sql/mysqld.cc: Auto merged tools/mysqlmanager.c: Auto merged
Diffstat (limited to 'tools')
-rw-r--r--tools/mysqlmanager.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/tools/mysqlmanager.c b/tools/mysqlmanager.c
index c9307bf5d0c..896d889cdcc 100644
--- a/tools/mysqlmanager.c
+++ b/tools/mysqlmanager.c
@@ -189,6 +189,8 @@ static void run_launcher_loop();
int to_launcher_pipe[2],from_launcher_pipe[2];
pid_t launcher_pid;
int in_segfault=0;
+const char* pid_file = "/var/run/mysqlmanager.pid";
+int created_pid_file = 0;
struct manager_cmd
{
@@ -283,6 +285,7 @@ struct option long_options[] =
{"one-thread",no_argument,0,'d'},
{"connect-retries",required_argument,0,'C'},
{"password-file",required_argument,0,'p'},
+ {"pid-file",required_argument,0,'f'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0}
};
@@ -327,6 +330,17 @@ LOG_MSG_FUNC(log_debug,LOG_DEBUG)
void log_debug(const char* __attribute__((unused)) fmt,...) {}
#endif
+static void handle_sigterm(int sig)
+{
+ log_info("Got SIGTERM");
+ if (!one_thread)
+ {
+ kill(launcher_pid,SIGTERM);
+ pthread_kill(loop_th,SIGTERM);
+ }
+ clean_up();
+ exit(0);
+}
static void handle_segfault(int sig)
{
@@ -1250,6 +1264,8 @@ static void clean_up()
if (errfp != stderr)
fclose(errfp);
hash_free(&exec_hash);
+ if (created_pid_file)
+ my_delete(pid_file, MYF(0));
}
static void print_version(void)
@@ -1287,7 +1303,7 @@ static void usage()
static int parse_args(int argc, char **argv)
{
int c, option_index = 0;
- while ((c=getopt_long(argc,argv,"P:?#:Vl:b:B:g:m:dC:p:",
+ while ((c=getopt_long(argc,argv,"P:?#:Vl:b:B:g:m:dC:p:f:",
long_options,&option_index)) != EOF)
{
switch (c)
@@ -1301,6 +1317,9 @@ static int parse_args(int argc, char **argv)
case 'p':
manager_pw_file=optarg;
break;
+ case 'f':
+ pid_file=optarg;
+ break;
case 'C':
manager_connect_retries=atoi(optarg);
break;
@@ -1662,6 +1681,16 @@ static void init_user_hash()
fclose(f);
}
+static void init_pid_file()
+{
+ FILE* fp = fopen(pid_file, "w");
+ if (!fp)
+ die("Could not open pid file %s", pid_file);
+ created_pid_file=1;
+ fprintf(fp, "%d\n", getpid());
+ fclose(fp);
+}
+
static void init_globals()
{
pthread_attr_t thr_attr;
@@ -1680,8 +1709,10 @@ static void init_globals()
/* (void) pthread_attr_destroy(&thr_attr); */
}
init_user_hash();
+ init_pid_file();
loop_th=pthread_self();
signal(SIGPIPE,handle_sigpipe);
+ signal(SIGTERM,handle_sigterm);
}
static int open_and_dup(int fd,char* path)