List:Commits« Previous MessageNext Message »
From:Ramil Kalimullin Date:March 20 2012 9:37am
Subject:bzr push into mysql-trunk branch (ramil.kalimullin:3804 to 3805) Bug#11746142
View as plain text  
 3805 Ramil Kalimullin	2012-03-20
      Fix BUG#11746142: CALLING MYSQLD WHILE ANOTHER INSTANCE IS RUNNING,
      REMOVES PID FILE
      
      Removing the pid file, ensure it was created by the same process.
      Leave it intact otherwise.
     @ sql/mysqld.cc
        Fix BUG#11746142: CALLING MYSQLD WHILE ANOTHER INSTANCE IS RUNNING,
        REMOVES PID FILE
          - delete_pid_file() introduced, which checks that the pid file 
        belongs to the process before removing it.

    modified:
      sql/mysqld.cc
 3804 Tor Didriksen	2012-03-20
      BUG#11748924, oops revert previous push

    modified:
      sql/unireg.cc
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2012-03-14 09:52:49 +0000
+++ b/sql/mysqld.cc	2012-03-20 09:36:51 +0000
@@ -1115,6 +1115,7 @@ static void clean_up(bool print_message)
 static int test_if_case_insensitive(const char *dir_name);
 
 #ifndef EMBEDDED_LIBRARY
+static bool pid_file_created= false;
 static void usage(void);
 static void start_signal_handler(void);
 static void close_server_sock();
@@ -1123,6 +1124,7 @@ static void wait_for_signal_thread_to_en
 static void create_pid_file();
 static void mysqld_exit(int exit_code) __attribute__((noreturn));
 #endif
+static void delete_pid_file(myf flags);
 static void end_ssl();
 
 
@@ -1642,10 +1644,8 @@ void clean_up(bool print_message)
   debug_sync_end();
 #endif /* defined(ENABLED_DEBUG_SYNC) */
 
-#if !defined(EMBEDDED_LIBRARY)
-  if (!opt_bootstrap)
-    mysql_file_delete(key_file_pid, pidfile_name, MYF(0)); // This may not always exist
-#endif
+  delete_pid_file(MYF(0));
+
   if (print_message && my_default_lc_messages && server_start_time)
     sql_print_information(ER_DEFAULT(ER_SHUTDOWN_COMPLETE),my_progname);
   cleanup_errmsgs();
@@ -5043,9 +5043,7 @@ int mysqld_main(int argc, char **argv)
 
     (void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
 
-
-    if (!opt_bootstrap)
-      mysql_file_delete(key_file_pid, pidfile_name, MYF(MY_WME)); // Not needed anymore
+    delete_pid_file(MYF(MY_WME));
 
     if (mysql_socket_getfd(unix_sock) != INVALID_SOCKET)
       unlink(mysqld_unix_port);
@@ -8478,13 +8476,14 @@ static void create_pid_file()
   if ((file= mysql_file_create(key_file_pid, pidfile_name, 0664,
                                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++= '\n';
     if (!mysql_file_write(file, (uchar*) buff, (uint) (end-buff),
                           MYF(MY_WME | MY_NABP)))
     {
       mysql_file_close(file, MYF(0));
+      pid_file_created= true;
       return;
     }
     mysql_file_close(file, MYF(0));
@@ -8494,6 +8493,39 @@ static void create_pid_file()
 }
 #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= mysql_file_open(key_file_pid, 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= mysql_file_read(file, buff, sizeof(buff), flags);
+  mysql_file_close(file, flags);
+  buff[sizeof(buff) - 1]= '\0'; 
+  if (error != MY_FILE_ERROR &&
+      atol((char *) buff) == (long) getpid())
+  {
+    mysql_file_delete(key_file_pid, pidfile_name, flags);
+    pid_file_created= false;
+  }
+#endif /* EMBEDDED_LIBRARY */
+  return;
+}
+
+
 /** Clear most status variables. */
 void refresh_status(THD *thd)
 {

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (ramil.kalimullin:3804 to 3805) Bug#11746142Ramil Kalimullin20 Mar