summaryrefslogtreecommitdiff
path: root/sql/mysqld.cc
diff options
context:
space:
mode:
authorVenkatesh Duggirala <venkatesh.duggirala@oracle.com>2012-12-28 16:21:07 +0530
committerVenkatesh Duggirala <venkatesh.duggirala@oracle.com>2012-12-28 16:21:07 +0530
commitf7ab14d7623cc3596f862177c939b581a18e6025 (patch)
tree1bffedb56e5d6f2aacb421d98dec7dbd20b9edde /sql/mysqld.cc
parent519daab67acd07de18b7eb2b8a06250f63d35a2d (diff)
parentec70b93e7b529dbd0da0eaab317fe0edf9ea1c24 (diff)
downloadmariadb-git-f7ab14d7623cc3596f862177c939b581a18e6025.tar.gz
BUG#14726272- BACKPORT FIX FOR BUG 11746142 TO 5.5 AND 5.1
Merging fix from mysql-5.1
Diffstat (limited to 'sql/mysqld.cc')
-rw-r--r--sql/mysqld.cc48
1 files changed, 40 insertions, 8 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index d71c030efe8..83bd9ed860b 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -993,6 +993,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();
@@ -1001,6 +1002,7 @@ static void wait_for_signal_thread_to_end(void);
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();
@@ -1515,10 +1517,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();
@@ -4517,9 +4517,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 (unix_sock != INVALID_SOCKET)
unlink(mysqld_unix_port);
@@ -7676,13 +7674,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));
@@ -7692,6 +7691,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)
{