Skip to content

Commit ea578c9

Browse files
committed
MDEV-8491 - On shutdown, report the user and the host executed that.
1 parent 5c5034f commit ea578c9

File tree

6 files changed

+70
-28
lines changed

6 files changed

+70
-28
lines changed

mysql-test/r/shutdown.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ create procedure try_shutdown() shutdown;
55
drop procedure try_shutdown;
66
shutdown;
77
drop user user1@localhost;
8+
#
9+
# MDEV-8491 - On shutdown, report the user and the host executed that.
10+
#
11+
FOUND /mysqld \(root\[root\] @ localhost \[\]\): Normal shutdown/ in mysqld.1.err

mysql-test/t/shutdown.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ drop procedure try_shutdown;
3030

3131
drop user user1@localhost;
3232

33+
--echo #
34+
--echo # MDEV-8491 - On shutdown, report the user and the host executed that.
35+
--echo #
36+
--let SEARCH_FILE= $MYSQLTEST_VARDIR/log/mysqld.1.err
37+
--let SEARCH_RANGE= -50000
38+
--let SEARCH_PATTERN=mysqld \(root\[root\] @ localhost \[\]\): Normal shutdown
39+
--source include/search_pattern_in_file.inc

sql/mysqld.cc

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,10 +1806,35 @@ static void close_server_sock()
18061806
#endif /*EMBEDDED_LIBRARY*/
18071807

18081808

1809-
void kill_mysql(void)
1809+
/**
1810+
Set shutdown user
1811+
1812+
@note this function may be called by multiple threads concurrently, thus
1813+
it performs safe update of shutdown_user (first thread wins).
1814+
*/
1815+
1816+
static volatile char *shutdown_user;
1817+
static void set_shutdown_user(THD *thd)
1818+
{
1819+
char user_host_buff[MAX_USER_HOST_SIZE + 1];
1820+
char *user, *expected_shutdown_user= 0;
1821+
1822+
make_user_name(thd, user_host_buff);
1823+
1824+
if ((user= my_strdup(user_host_buff, MYF(0))) &&
1825+
!my_atomic_casptr((void **) &shutdown_user,
1826+
(void **) &expected_shutdown_user, user))
1827+
my_free(user);
1828+
}
1829+
1830+
1831+
void kill_mysql(THD *thd)
18101832
{
18111833
DBUG_ENTER("kill_mysql");
18121834

1835+
if (thd)
1836+
set_shutdown_user(thd);
1837+
18131838
#if defined(SIGNALS_DONT_BREAK_READ) && !defined(EMBEDDED_LIBRARY)
18141839
abort_loop=1; // Break connection loops
18151840
close_server_sock(); // Force accept to wake up
@@ -1888,7 +1913,13 @@ static void __cdecl kill_server(int sig_ptr)
18881913
if (sig != 0) // 0 is not a valid signal number
18891914
my_sigset(sig, SIG_IGN); /* purify inspected */
18901915
if (sig == MYSQL_KILL_SIGNAL || sig == 0)
1891-
sql_print_information(ER_DEFAULT(ER_NORMAL_SHUTDOWN),my_progname);
1916+
{
1917+
char *user= (char *) my_atomic_loadptr((void**) &shutdown_user);
1918+
sql_print_information(ER_DEFAULT(ER_NORMAL_SHUTDOWN), my_progname,
1919+
user ? user : "unknown");
1920+
if (user)
1921+
my_free(user);
1922+
}
18921923
else
18931924
sql_print_error(ER_DEFAULT(ER_GOT_SIGNAL),my_progname,sig); /* purecov: inspected */
18941925

sql/mysqld.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ enum enum_slave_parallel_mode {
7878
};
7979

8080
/* Function prototypes */
81-
void kill_mysql(void);
81+
void kill_mysql(THD *thd= 0);
8282
void close_connection(THD *thd, uint sql_errno= 0);
8383
void handle_connection_in_main_thread(THD *thd);
8484
void create_thread_to_handle_connection(THD *thd);

sql/share/errmsg-utf8.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,29 +1735,29 @@ ER_WRONG_AUTO_KEY 42000 S1009
17351735
ER_UNUSED_9
17361736
eng "You should never see it"
17371737
ER_NORMAL_SHUTDOWN
1738-
cze "%s: normální ukončení\n"
1739-
dan "%s: Normal nedlukning\n"
1740-
nla "%s: Normaal afgesloten \n"
1741-
eng "%s: Normal shutdown\n"
1742-
est "%s: MariaDB lõpetas\n"
1743-
fre "%s: Arrêt normal du serveur\n"
1744-
ger "%s: Normal heruntergefahren\n"
1745-
greek "%s: Φυσιολογική διαδικασία shutdown\n"
1746-
hun "%s: Normal leallitas\n"
1747-
ita "%s: Shutdown normale\n"
1748-
jpn "%s: 通常シャットダウン\n"
1749-
kor "%s: 정상적인 shutdown\n"
1750-
nor "%s: Normal avslutning\n"
1751-
norwegian-ny "%s: Normal nedkopling\n"
1752-
pol "%s: Standardowe zakończenie działania\n"
1753-
por "%s: 'Shutdown' normal\n"
1754-
rum "%s: Terminare normala\n"
1755-
rus "%s: Корректная остановка\n"
1756-
serbian "%s: Normalno gašenje\n"
1757-
slo "%s: normálne ukončenie\n"
1758-
spa "%s: Apagado normal\n"
1759-
swe "%s: Normal avslutning\n"
1760-
ukr "%s: Нормальне завершення\n"
1738+
cze "%s (%s): normální ukončení\n"
1739+
dan "%s (%s): Normal nedlukning\n"
1740+
nla "%s (%s): Normaal afgesloten \n"
1741+
eng "%s (%s): Normal shutdown\n"
1742+
est "%s (%s): MariaDB lõpetas\n"
1743+
fre "%s (%s): Arrêt normal du serveur\n"
1744+
ger "%s (%s): Normal heruntergefahren\n"
1745+
greek "%s (%s): Φυσιολογική διαδικασία shutdown\n"
1746+
hun "%s (%s): Normal leallitas\n"
1747+
ita "%s (%s): Shutdown normale\n"
1748+
jpn "%s (%s): 通常シャットダウン\n"
1749+
kor "%s (%s): 정상적인 shutdown\n"
1750+
nor "%s (%s): Normal avslutning\n"
1751+
norwegian-ny "%s (%s): Normal nedkopling\n"
1752+
pol "%s (%s): Standardowe zakończenie działania\n"
1753+
por "%s (%s): 'Shutdown' normal\n"
1754+
rum "%s (%s): Terminare normala\n"
1755+
rus "%s (%s): Корректная остановка\n"
1756+
serbian "%s (%s): Normalno gašenje\n"
1757+
slo "%s (%s): normálne ukončenie\n"
1758+
spa "%s (%s): Apagado normal\n"
1759+
swe "%s (%s): Normal avslutning\n"
1760+
ukr "%s (%s): Нормальне завершення\n"
17611761
ER_GOT_SIGNAL
17621762
cze "%s: přijat signal %d, končím\n"
17631763
dan "%s: Fangede signal %d. Afslutter!!\n"

sql/sql_parse.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
18041804
DBUG_PRINT("quit",("Got shutdown command for level %u", level));
18051805
general_log_print(thd, command, NullS);
18061806
my_eof(thd);
1807-
kill_mysql();
1807+
kill_mysql(thd);
18081808
error=TRUE;
18091809
break;
18101810
}
@@ -4907,7 +4907,7 @@ mysql_execute_command(THD *thd)
49074907
#ifndef EMBEDDED_LIBRARY
49084908
if (check_global_access(thd,SHUTDOWN_ACL))
49094909
goto error;
4910-
kill_mysql();
4910+
kill_mysql(thd);
49114911
my_ok(thd);
49124912
#else
49134913
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "embedded server");

0 commit comments

Comments
 (0)