Commit c2817cb9 authored by Venkatesh Duggirala's avatar Venkatesh Duggirala

BUG#14726272- BACKPORT FIX FOR BUG 11746142 TO 5.5 AND 5.1

Details of BUG#11746142: CALLING MYSQLD WHILE ANOTHER 
INSTANCE IS RUNNING, REMOVES PID FILE
Fix: Before removing the pid file, ensure it was created
by the same process, leave it intact otherwise.
parent 3dbf1b3e
...@@ -867,6 +867,7 @@ static void clean_up(bool print_message); ...@@ -867,6 +867,7 @@ static void clean_up(bool print_message);
static int test_if_case_insensitive(const char *dir_name); static int test_if_case_insensitive(const char *dir_name);
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
static bool pid_file_created= false;
static void usage(void); static void usage(void);
static void start_signal_handler(void); static void start_signal_handler(void);
static void close_server_sock(); static void close_server_sock();
...@@ -875,6 +876,7 @@ static void wait_for_signal_thread_to_end(void); ...@@ -875,6 +876,7 @@ static void wait_for_signal_thread_to_end(void);
static void create_pid_file(); static void create_pid_file();
static void end_ssl(); static void end_ssl();
#endif #endif
static void delete_pid_file(myf flags);
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
...@@ -1395,10 +1397,7 @@ void clean_up(bool print_message) ...@@ -1395,10 +1397,7 @@ void clean_up(bool print_message)
debug_sync_end(); debug_sync_end();
#endif /* defined(ENABLED_DEBUG_SYNC) */ #endif /* defined(ENABLED_DEBUG_SYNC) */
#if !defined(EMBEDDED_LIBRARY) delete_pid_file(MYF(0));
if (!opt_bootstrap)
(void) my_delete(pidfile_name,MYF(0)); // This may not always exist
#endif
if (print_message && errmesg && server_start_time) if (print_message && errmesg && server_start_time)
sql_print_information(ER(ER_SHUTDOWN_COMPLETE),my_progname); sql_print_information(ER(ER_SHUTDOWN_COMPLETE),my_progname);
thread_scheduler.end(); thread_scheduler.end();
...@@ -4387,9 +4386,7 @@ we force server id to 2, but this MySQL server will not act as a slave."); ...@@ -4387,9 +4386,7 @@ we force server id to 2, but this MySQL server will not act as a slave.");
(void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL); (void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
#endif /* __NETWARE__ */ #endif /* __NETWARE__ */
if (!opt_bootstrap) delete_pid_file(MYF(MY_WME));
(void) my_delete(pidfile_name,MYF(MY_WME)); // Not needed anymore
if (unix_sock != INVALID_SOCKET) if (unix_sock != INVALID_SOCKET)
unlink(mysqld_unix_port); unlink(mysqld_unix_port);
exit(1); exit(1);
...@@ -9098,12 +9095,13 @@ static void create_pid_file() ...@@ -9098,12 +9095,13 @@ static void create_pid_file()
if ((file = my_create(pidfile_name,0664, if ((file = my_create(pidfile_name,0664,
O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0) O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0)
{ {
char buff[21], *end; char buff[MAX_BIGINT_WIDTH + 1], *end;
end= int10_to_str((long) getpid(), buff, 10); end= int10_to_str((long) getpid(), buff, 10);
*end++= '\n'; *end++= '\n';
if (!my_write(file, (uchar*) buff, (uint) (end-buff), MYF(MY_WME | MY_NABP))) if (!my_write(file, (uchar*) buff, (uint) (end-buff), MYF(MY_WME | MY_NABP)))
{ {
(void) my_close(file, MYF(0)); (void) my_close(file, MYF(0));
pid_file_created= true;
return; return;
} }
(void) my_close(file, MYF(0)); (void) my_close(file, MYF(0));
...@@ -9113,6 +9111,38 @@ static void create_pid_file() ...@@ -9113,6 +9111,38 @@ static void create_pid_file()
} }
#endif /* EMBEDDED_LIBRARY */ #endif /* EMBEDDED_LIBRARY */
/**
Remove the process' pid file.
@param flags file operation flags
*/
static void delete_pid_file(myf flags)
{
#ifndef EMBEDDED_LIBRARY
File file;
if (opt_bootstrap ||
!pid_file_created ||
!(file= my_open(pidfile_name, O_RDONLY, flags)))
return;
/* Make sure that the pid file was created by the same process. */
uchar buff[MAX_BIGINT_WIDTH + 1];
size_t error= my_read(file, buff, sizeof(buff), flags);
my_close(file, flags);
buff[sizeof(buff) - 1]= '\0';
if (error != MY_FILE_ERROR &&
atol((char *) buff) == (long) getpid())
{
my_delete(pidfile_name, flags);
pid_file_created= false;
}
#endif /* EMBEDDED_LIBRARY */
return;
}
/** Clear most status variables. */ /** Clear most status variables. */
void refresh_status(THD *thd) void refresh_status(THD *thd)
{ {
......
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