Commit ea578c9d authored by Sergey Vojtovich's avatar Sergey Vojtovich

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

parent 5c5034f9
...@@ -5,3 +5,7 @@ create procedure try_shutdown() shutdown; ...@@ -5,3 +5,7 @@ create procedure try_shutdown() shutdown;
drop procedure try_shutdown; drop procedure try_shutdown;
shutdown; shutdown;
drop user user1@localhost; drop user user1@localhost;
#
# MDEV-8491 - On shutdown, report the user and the host executed that.
#
FOUND /mysqld \(root\[root\] @ localhost \[\]\): Normal shutdown/ in mysqld.1.err
...@@ -30,3 +30,10 @@ drop procedure try_shutdown; ...@@ -30,3 +30,10 @@ drop procedure try_shutdown;
drop user user1@localhost; drop user user1@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
...@@ -1806,10 +1806,35 @@ static void close_server_sock() ...@@ -1806,10 +1806,35 @@ static void close_server_sock()
#endif /*EMBEDDED_LIBRARY*/ #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"); DBUG_ENTER("kill_mysql");
if (thd)
set_shutdown_user(thd);
#if defined(SIGNALS_DONT_BREAK_READ) && !defined(EMBEDDED_LIBRARY) #if defined(SIGNALS_DONT_BREAK_READ) && !defined(EMBEDDED_LIBRARY)
abort_loop=1; // Break connection loops abort_loop=1; // Break connection loops
close_server_sock(); // Force accept to wake up close_server_sock(); // Force accept to wake up
...@@ -1888,7 +1913,13 @@ static void __cdecl kill_server(int sig_ptr) ...@@ -1888,7 +1913,13 @@ static void __cdecl kill_server(int sig_ptr)
if (sig != 0) // 0 is not a valid signal number if (sig != 0) // 0 is not a valid signal number
my_sigset(sig, SIG_IGN); /* purify inspected */ my_sigset(sig, SIG_IGN); /* purify inspected */
if (sig == MYSQL_KILL_SIGNAL || sig == 0) 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 else
sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */ sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */
......
...@@ -78,7 +78,7 @@ enum enum_slave_parallel_mode { ...@@ -78,7 +78,7 @@ enum enum_slave_parallel_mode {
}; };
/* Function prototypes */ /* Function prototypes */
void kill_mysql(void); void kill_mysql(THD *thd= 0);
void close_connection(THD *thd, uint sql_errno= 0); void close_connection(THD *thd, uint sql_errno= 0);
void handle_connection_in_main_thread(THD *thd); void handle_connection_in_main_thread(THD *thd);
void create_thread_to_handle_connection(THD *thd); void create_thread_to_handle_connection(THD *thd);
......
...@@ -1735,29 +1735,29 @@ ER_WRONG_AUTO_KEY 42000 S1009 ...@@ -1735,29 +1735,29 @@ ER_WRONG_AUTO_KEY 42000 S1009
ER_UNUSED_9 ER_UNUSED_9
eng "You should never see it" eng "You should never see it"
ER_NORMAL_SHUTDOWN ER_NORMAL_SHUTDOWN
cze "%s: normální ukončení\n" cze "%s (%s): normální ukončení\n"
dan "%s: Normal nedlukning\n" dan "%s (%s): Normal nedlukning\n"
nla "%s: Normaal afgesloten \n" nla "%s (%s): Normaal afgesloten \n"
eng "%s: Normal shutdown\n" eng "%s (%s): Normal shutdown\n"
est "%s: MariaDB lõpetas\n" est "%s (%s): MariaDB lõpetas\n"
fre "%s: Arrêt normal du serveur\n" fre "%s (%s): Arrêt normal du serveur\n"
ger "%s: Normal heruntergefahren\n" ger "%s (%s): Normal heruntergefahren\n"
greek "%s: Φυσιολογική διαδικασία shutdown\n" greek "%s (%s): Φυσιολογική διαδικασία shutdown\n"
hun "%s: Normal leallitas\n" hun "%s (%s): Normal leallitas\n"
ita "%s: Shutdown normale\n" ita "%s (%s): Shutdown normale\n"
jpn "%s: 通常シャットダウン\n" jpn "%s (%s): 通常シャットダウン\n"
kor "%s: 정상적인 shutdown\n" kor "%s (%s): 정상적인 shutdown\n"
nor "%s: Normal avslutning\n" nor "%s (%s): Normal avslutning\n"
norwegian-ny "%s: Normal nedkopling\n" norwegian-ny "%s (%s): Normal nedkopling\n"
pol "%s: Standardowe zakończenie działania\n" pol "%s (%s): Standardowe zakończenie działania\n"
por "%s: 'Shutdown' normal\n" por "%s (%s): 'Shutdown' normal\n"
rum "%s: Terminare normala\n" rum "%s (%s): Terminare normala\n"
rus "%s: Корректная остановка\n" rus "%s (%s): Корректная остановка\n"
serbian "%s: Normalno gašenje\n" serbian "%s (%s): Normalno gašenje\n"
slo "%s: normálne ukončenie\n" slo "%s (%s): normálne ukončenie\n"
spa "%s: Apagado normal\n" spa "%s (%s): Apagado normal\n"
swe "%s: Normal avslutning\n" swe "%s (%s): Normal avslutning\n"
ukr "%s: Нормальне завершення\n" ukr "%s (%s): Нормальне завершення\n"
ER_GOT_SIGNAL ER_GOT_SIGNAL
cze "%s: přijat signal %d, končím\n" cze "%s: přijat signal %d, končím\n"
dan "%s: Fangede signal %d. Afslutter!!\n" dan "%s: Fangede signal %d. Afslutter!!\n"
......
...@@ -1804,7 +1804,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -1804,7 +1804,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
DBUG_PRINT("quit",("Got shutdown command for level %u", level)); DBUG_PRINT("quit",("Got shutdown command for level %u", level));
general_log_print(thd, command, NullS); general_log_print(thd, command, NullS);
my_eof(thd); my_eof(thd);
kill_mysql(); kill_mysql(thd);
error=TRUE; error=TRUE;
break; break;
} }
...@@ -4907,7 +4907,7 @@ mysql_execute_command(THD *thd) ...@@ -4907,7 +4907,7 @@ mysql_execute_command(THD *thd)
#ifndef EMBEDDED_LIBRARY #ifndef EMBEDDED_LIBRARY
if (check_global_access(thd,SHUTDOWN_ACL)) if (check_global_access(thd,SHUTDOWN_ACL))
goto error; goto error;
kill_mysql(); kill_mysql(thd);
my_ok(thd); my_ok(thd);
#else #else
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "embedded server"); my_error(ER_NOT_SUPPORTED_YET, MYF(0), "embedded server");
......
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