[Commits] 05c122b: MDEV-8491 - On shutdown, report the user and the host executed that.

Sergey Vojtovich svoj at mariadb.org
Thu Dec 24 17:53:46 EET 2015


revision-id: 05c122b3ccd0102a3414a7d59313e6662a1fd5e4 (mariadb-10.1.8-101-g05c122b)
parent(s): 7c533a17523d2d6ef380487ab35151da0208090f
committer: Sergey Vojtovich
timestamp: 2015-12-24 19:53:44 +0400
message:

MDEV-8491 - On shutdown, report the user and the host executed that.

---
 mysql-test/r/shutdown.result |  4 ++++
 mysql-test/t/shutdown.test   |  7 +++++++
 sql/mysqld.cc                | 35 +++++++++++++++++++++++++++++++--
 sql/mysqld.h                 |  2 +-
 sql/share/errmsg-utf8.txt    | 46 ++++++++++++++++++++++----------------------
 sql/sql_parse.cc             |  4 ++--
 6 files changed, 70 insertions(+), 28 deletions(-)

diff --git a/mysql-test/r/shutdown.result b/mysql-test/r/shutdown.result
index 7039afb..553dab6 100644
--- a/mysql-test/r/shutdown.result
+++ b/mysql-test/r/shutdown.result
@@ -5,3 +5,7 @@ create procedure try_shutdown() shutdown;
 drop procedure try_shutdown;
 shutdown;
 drop user user1 at localhost;
+#
+# MDEV-8491 - On shutdown, report the user and the host executed that.
+#
+FOUND /mysqld \(root\[root\] @ localhost \[\]\): Normal shutdown/ in mysqld.1.err
diff --git a/mysql-test/t/shutdown.test b/mysql-test/t/shutdown.test
index ac7f06b..d764e80 100644
--- a/mysql-test/t/shutdown.test
+++ b/mysql-test/t/shutdown.test
@@ -30,3 +30,10 @@ drop procedure try_shutdown;
 
 drop user user1 at localhost;
 
+--echo #
+--echo # MDEV-8491 - On shutdown, report the user and the host executed that.
+--echo #
+--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err
+--let SEARCH_RANGE= -50000
+--let SEARCH_PATTERN=mysqld \(root\[root\] @ localhost \[\]\): Normal shutdown
+--source include/search_pattern_in_file.inc
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index b3005a3..a159d0e 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -1806,10 +1806,35 @@ static void close_server_sock()
 #endif /*EMBEDDED_LIBRARY*/
 
 
-void kill_mysql(void)
+/**
+  Set shutdown user
+
+  @note this function may be called by multiple threads concurrently, thus
+  it performs safe update of shutdown_user (first thread wins).
+*/
+
+static volatile char *shutdown_user;
+static void set_shutdown_user(THD *thd)
+{
+  char user_host_buff[MAX_USER_HOST_SIZE + 1];
+  char *user, *expected_shutdown_user= 0;
+
+  make_user_name(thd, user_host_buff);
+
+  if ((user= my_strdup(user_host_buff, MYF(0))) &&
+      !my_atomic_casptr((void **) &shutdown_user,
+                        (void **) &expected_shutdown_user, user))
+    my_free(user);
+}
+
+
+void kill_mysql(THD *thd)
 {
   DBUG_ENTER("kill_mysql");
 
+  if (thd)
+    set_shutdown_user(thd);
+
 #if defined(SIGNALS_DONT_BREAK_READ) && !defined(EMBEDDED_LIBRARY)
   abort_loop=1;					// Break connection loops
   close_server_sock();				// Force accept to wake up
@@ -1888,7 +1913,13 @@ static void __cdecl kill_server(int sig_ptr)
   if (sig != 0) // 0 is not a valid signal number
     my_sigset(sig, SIG_IGN);                    /* purify inspected */
   if (sig == MYSQL_KILL_SIGNAL || sig == 0)
-    sql_print_information(ER_DEFAULT(ER_NORMAL_SHUTDOWN),my_progname);
+  {
+    char *user= (char *) my_atomic_loadptr((void**) &shutdown_user);
+    sql_print_information(ER_DEFAULT(ER_NORMAL_SHUTDOWN), my_progname,
+                          user ? user : "unknown");
+    if (user)
+      my_free(user);
+  }
   else
     sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */
 
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 5c27f86..e06c70a 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -78,7 +78,7 @@ enum enum_slave_parallel_mode {
 };
 
 /* Function prototypes */
-void kill_mysql(void);
+void kill_mysql(THD *thd= 0);
 void close_connection(THD *thd, uint sql_errno= 0);
 void handle_connection_in_main_thread(THD *thd);
 void create_thread_to_handle_connection(THD *thd);
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 59908dc..0afd13e 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -1735,29 +1735,29 @@ ER_WRONG_AUTO_KEY 42000 S1009
 ER_UNUSED_9
         eng "You should never see it"
 ER_NORMAL_SHUTDOWN  
-        cze "%s: normální ukončení\n"
-        dan "%s: Normal nedlukning\n"
-        nla "%s: Normaal afgesloten \n"
-        eng "%s: Normal shutdown\n"
-        est "%s: MariaDB lõpetas\n"
-        fre "%s: Arrêt normal du serveur\n"
-        ger "%s: Normal heruntergefahren\n"
-        greek "%s: Φυσιολογική διαδικασία shutdown\n"
-        hun "%s: Normal leallitas\n"
-        ita "%s: Shutdown normale\n"
-        jpn "%s: 通常シャットダウン\n"
-        kor "%s: 정상적인 shutdown\n"
-        nor "%s: Normal avslutning\n"
-        norwegian-ny "%s: Normal nedkopling\n"
-        pol "%s: Standardowe zakończenie działania\n"
-        por "%s: 'Shutdown' normal\n"
-        rum "%s: Terminare normala\n"
-        rus "%s: Корректная остановка\n"
-        serbian "%s: Normalno gašenje\n"
-        slo "%s: normálne ukončenie\n"
-        spa "%s: Apagado normal\n"
-        swe "%s: Normal avslutning\n"
-        ukr "%s: Нормальне завершення\n"
+        cze "%s (%s): normální ukončení\n"
+        dan "%s (%s): Normal nedlukning\n"
+        nla "%s (%s): Normaal afgesloten \n"
+        eng "%s (%s): Normal shutdown\n"
+        est "%s (%s): MariaDB lõpetas\n"
+        fre "%s (%s): Arrêt normal du serveur\n"
+        ger "%s (%s): Normal heruntergefahren\n"
+        greek "%s (%s): Φυσιολογική διαδικασία shutdown\n"
+        hun "%s (%s): Normal leallitas\n"
+        ita "%s (%s): Shutdown normale\n"
+        jpn "%s (%s): 通常シャットダウン\n"
+        kor "%s (%s): 정상적인 shutdown\n"
+        nor "%s (%s): Normal avslutning\n"
+        norwegian-ny "%s (%s): Normal nedkopling\n"
+        pol "%s (%s): Standardowe zakończenie działania\n"
+        por "%s (%s): 'Shutdown' normal\n"
+        rum "%s (%s): Terminare normala\n"
+        rus "%s (%s): Корректная остановка\n"
+        serbian "%s (%s): Normalno gašenje\n"
+        slo "%s (%s): normálne ukončenie\n"
+        spa "%s (%s): Apagado normal\n"
+        swe "%s (%s): Normal avslutning\n"
+        ukr "%s (%s): Нормальне завершення\n"
 ER_GOT_SIGNAL  
         cze "%s: přijat signal %d, končím\n"
         dan "%s: Fangede signal %d. Afslutter!!\n"
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 52dcc7e..96985aa 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1804,7 +1804,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     DBUG_PRINT("quit",("Got shutdown command for level %u", level));
     general_log_print(thd, command, NullS);
     my_eof(thd);
-    kill_mysql();
+    kill_mysql(thd);
     error=TRUE;
     break;
   }
@@ -4907,7 +4907,7 @@ mysql_execute_command(THD *thd)
 #ifndef EMBEDDED_LIBRARY
     if (check_global_access(thd,SHUTDOWN_ACL))
       goto error;
-    kill_mysql();
+    kill_mysql(thd);
     my_ok(thd);
 #else
     my_error(ER_NOT_SUPPORTED_YET, MYF(0), "embedded server");


More information about the commits mailing list