Commit 079fa53f authored by unknown's avatar unknown

Add 'my_kill' - portable version of "kill"

Straigthen code to be more explicit

parent 3674c72d
...@@ -3820,21 +3820,46 @@ int query_get_string(MYSQL* mysql, const char* query, ...@@ -3820,21 +3820,46 @@ int query_get_string(MYSQL* mysql, const char* query,
MYSQL_RES *res= NULL; MYSQL_RES *res= NULL;
MYSQL_ROW row; MYSQL_ROW row;
if (mysql_query(mysql,query) || !(res=mysql_store_result(mysql))) if (mysql_query(mysql, query))
die("'%s' failed: %d %s", query, die("'%s' failed: %d %s", query,
mysql_errno(mysql), mysql_error(mysql)); mysql_errno(mysql), mysql_error(mysql));
if (!(row=mysql_fetch_row(res)) || !row[column]) if ((res= mysql_store_result(mysql)) == NULL)
die("Failed to store result: %d %s",
mysql_errno(mysql), mysql_error(mysql));
if ((row= mysql_fetch_row(res)) == NULL)
{ {
mysql_free_result(res); mysql_free_result(res);
ds= 0; ds= 0;
return 1; return 1;
} }
init_dynamic_string(ds, row[1], strlen(row[column]), 32); init_dynamic_string(ds, (row[column] ? row[column] : "NULL"), ~0, 32);
mysql_free_result(res); mysql_free_result(res);
return 0; return 0;
} }
static int my_kill(int pid, int sig)
{
#ifdef __WIN__
HANDLE proc;
if ((proc= OpenProcess(PROCESS_TERMINATE, FALSE, pid)) == NULL)
return -1;
if (sig == 0)
{
CloseHandle(proc);
return 0;
}
(void)TerminateProcess(proc, 201);
CloseHandle(proc);
return 1;
#else
return kill(pid, sig);
#endif
}
/* /*
Shutdown the server of current connection and Shutdown the server of current connection and
make sure it goes away within <timeout> seconds make sure it goes away within <timeout> seconds
...@@ -3885,31 +3910,28 @@ void do_shutdown_server(struct st_command *command) ...@@ -3885,31 +3910,28 @@ void do_shutdown_server(struct st_command *command)
if ((fd= my_open(ds_pidfile_name.str, O_RDONLY, MYF(0))) < 0) if ((fd= my_open(ds_pidfile_name.str, O_RDONLY, MYF(0))) < 0)
die("Failed to open file '%s'", ds_pidfile_name.str); die("Failed to open file '%s'", ds_pidfile_name.str);
dynstr_free(&ds_pidfile_name);
if (my_read(fd, (uchar*)&buff, if (my_read(fd, (uchar*)&buff,
sizeof(buff), MYF(0)) <= 0){ sizeof(buff), MYF(0)) <= 0){
my_close(fd, MYF(0)); my_close(fd, MYF(0));
die("pid file was empty"); die("pid file was empty");
} }
pid= atoi(buff);
if (pid == 0){
my_close(fd, MYF(0));
die("pid file was empty");
}
DBUG_PRINT("info", ("Read pid %d from '%s'", pid, ds_pidfile_name.str));
my_close(fd, MYF(0)); my_close(fd, MYF(0));
dynstr_free(&ds_pidfile_name); pid= atoi(buff);
if (pid == 0)
die("Pidfile didn't contain a valid number");
} }
DBUG_PRINT("info", ("Got pid %d", pid)); DBUG_PRINT("info", ("Got pid %d", pid));
/* Tell server to shutdown if timeout > 0*/ /* Tell server to shutdown if timeout > 0*/
if (timeout && mysql_shutdown(&cur_con->mysql, SHUTDOWN_DEFAULT)) if (timeout && mysql_shutdown(mysql, SHUTDOWN_DEFAULT))
die("mysql_shutdown failed"); die("mysql_shutdown failed");
/* Check that server dies */ /* Check that server dies */
while(timeout--){ while(timeout--){
if (kill(0, pid) < 0){ if (my_kill(0, pid) < 0){
DBUG_PRINT("info", ("Sleeping, timeout: %d", timeout)); DBUG_PRINT("info", ("Sleeping, timeout: %d", timeout));
break; break;
} }
...@@ -3919,7 +3941,7 @@ void do_shutdown_server(struct st_command *command) ...@@ -3919,7 +3941,7 @@ void do_shutdown_server(struct st_command *command)
/* Kill the server */ /* Kill the server */
DBUG_PRINT("info", ("Killing server, pid: %d", pid)); DBUG_PRINT("info", ("Killing server, pid: %d", pid));
(void)kill(9, pid); (void)my_kill(9, pid);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment