Skip to content

Commit dfbe369

Browse files
author
Tatiana Azundris Nuernberg
committed
Bug#31788834: ENABLE ADDITONAL DEBUG FOR SD_NOTIFY
Problem: Insufficient debug in sd_notify() Solution: Enable and modify debug for sd_notify() Adds WITH_SYSTEMD_DEBUG option to cmake. Default is off. Update certain test cases so they pass with and without systemd debug mode enabled. Add global exclusions for mysql-test-run. Set up for packaging with systemd debug enabled. Change-Id: I405b93bdfcabe3e738fcfb209175d3d4846aa831
1 parent c9967ff commit dfbe369

File tree

7 files changed

+116
-24
lines changed

7 files changed

+116
-24
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,13 +1147,19 @@ INCLUDE(cmake/boost.cmake)
11471147

11481148
IF (LINUX)
11491149
OPTION(WITH_SYSTEMD "Enable installation of systemd support files" OFF)
1150+
OPTION(WITH_SYSTEMD_DEBUG "Build in systemd debug trace" OFF)
11501151
IF (WITH_SYSTEMD)
11511152
INCLUDE(cmake/systemd.cmake)
1153+
ELSEIF (WITH_SYSTEMD_DEBUG)
1154+
MESSAGE(FATAL_ERROR "systemd-debugging requires systemd, and systemd requires linux")
11521155
ENDIF()
11531156
ELSE()
11541157
IF (WITH_SYSTEMD)
11551158
MESSAGE(FATAL_ERROR "Installation of systemd support files not supported")
11561159
ENDIF()
1160+
IF (WITH_SYSTEMD_DEBUG)
1161+
MESSAGE(FATAL_ERROR "systemd-debugging requires systemd, and systemd requires linux")
1162+
ENDIF()
11571163
ENDIF()
11581164

11591165
# Run platform tests

config.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
#cmakedefine HAVE_LINUX_LARGE_PAGES 1
191191
#cmakedefine HAVE_SOLARIS_LARGE_PAGES 1
192192
#cmakedefine HAVE_SOLARIS_ATOMIC 1
193+
#cmakedefine WITH_SYSTEMD_DEBUG
193194
#define SYSTEM_TYPE "@SYSTEM_TYPE@"
194195
/* This should mean case insensitive file system */
195196
#cmakedefine FN_NO_CASE_SENSE 1

mysql-test/include/mtr_warnings.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ INSERT INTO global_suppressions VALUES
292292
*/
293293
("Channel mysql_main configured to support TLS"),
294294

295+
/*
296+
systemd debug (when built WITH_SYSTEMD and WITH_SYSTEMD_DEBUG,
297+
and systemd logging is not actually available)
298+
*/
299+
("NOTIFY_SOCKET not set in environment. sd_notify messages will not be sent!"),
300+
("Invalid systemd notify socket, cannot send: "),
301+
295302
("THE_LAST_SUPPRESSION");
296303

297304

mysql-test/t/basedir.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ EOF
200200
print "# Supressing output for initialize:\n";
201201
while(<MYSQLD_OUT>)
202202
{
203-
if (!(/initializing of server has completed/)) {
203+
if (!(/initializing of server has completed/) &&
204+
!(/Invalid systemd notify socket, cannot send:/)) {
204205
print;
205206
}
206207
}
Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,105 @@
1-
21
# BUG#58455
32
# Starting mysqld with defaults file without extension cause
43
# segmentation fault
54

65
source include/not_windows.inc;
76

7+
--let MDF_LOG= $MYSQLTEST_VARDIR/tmp/defaults.$_server_id.log
8+
89
# All these tests refer to configuration files that do not exist
910

10-
--replace_result mysqld-debug mysqld
1111
--error 1
12-
exec $MYSQLD --defaults-file=/path/with/no/extension --print-defaults 2>&1;
12+
exec $MYSQLD --defaults-file=/path/with/no/extension --print-defaults 2>$MDF_LOG;
13+
--perl
14+
use strict;
15+
my $mysqld_log= $ENV{'MDF_LOG'};
16+
open(MYSQLD_LOG, $mysqld_log) || die "1 - Failed to open '$mysqld_log': $!";
17+
while(<MYSQLD_LOG>) {
18+
if (!(/NOTIFY_SOCKET not set in environment/) &&
19+
!(/Invalid systemd notify socket, cannot send: /)) {
20+
s/mysqld-debug/mysqld/;
21+
print; }}
22+
close(MYSQLD_LOG);
23+
EOF
1324

14-
--replace_result mysqld-debug mysqld
1525
--error 1
16-
exec $MYSQLD --defaults-file=/path/with.ext --print-defaults 2>&1;
26+
exec $MYSQLD --defaults-file=/path/with.ext --print-defaults 2>$MDF_LOG;
27+
--perl
28+
use strict;
29+
my $mysqld_log= $ENV{'MDF_LOG'};
30+
open(MYSQLD_LOG, $mysqld_log) || die "2 - Failed to open '$mysqld_log': $!";
31+
while(<MYSQLD_LOG>) {
32+
if (!(/NOTIFY_SOCKET not set in environment/) &&
33+
!(/Invalid systemd notify socket, cannot send: /)) {
34+
s/mysqld-debug/mysqld/;
35+
print; }}
36+
close(MYSQLD_LOG);
37+
EOF
1738

1839
# Using $MYSQL_TEST_DIR_ABS which contains canonical path to the
1940
# test directory since --print-default prints the absolute path.
20-
--replace_result mysqld-debug mysqld $MYSQL_TEST_DIR_ABS MYSQL_TEST_DIR
2141
--error 1
22-
exec $MYSQLD --defaults-file=relative/path/with.ext --print-defaults 2>&1;
42+
exec $MYSQLD --defaults-file=relative/path/with.ext --print-defaults 2>$MDF_LOG;
43+
--perl
44+
use strict;
45+
my $mysqld_log= $ENV{'MDF_LOG'};
46+
my $test_dir= $ENV{'MYSQL_TEST_DIR_ABS'};
47+
open(MYSQLD_LOG, $mysqld_log) || die "3 - Failed to open '$mysqld_log': $!";
48+
while(<MYSQLD_LOG>) {
49+
if (!(/NOTIFY_SOCKET not set in environment/) &&
50+
!(/Invalid systemd notify socket, cannot send: /)) {
51+
s/mysqld-debug/mysqld/;
52+
s/$test_dir/MYSQL_TEST_DIR/;
53+
print; }}
54+
close(MYSQLD_LOG);
55+
EOF
2356

24-
--replace_result mysqld-debug mysqld $MYSQL_TEST_DIR_ABS MYSQL_TEST_DIR
2557
--error 1
26-
exec $MYSQLD --defaults-file=relative/path/without/extension --print-defaults 2>&1;
58+
exec $MYSQLD --defaults-file=relative/path/without/extension --print-defaults 2>$MDF_LOG;
59+
--perl
60+
use strict;
61+
my $mysqld_log= $ENV{'MDF_LOG'};
62+
my $test_dir= $ENV{'MYSQL_TEST_DIR_ABS'};
63+
open(MYSQLD_LOG, $mysqld_log) || die "4 - Failed to open '$mysqld_log': $!";
64+
while(<MYSQLD_LOG>) {
65+
if (!(/NOTIFY_SOCKET not set in environment/) &&
66+
!(/Invalid systemd notify socket, cannot send: /)) {
67+
s/mysqld-debug/mysqld/;
68+
s/$test_dir/MYSQL_TEST_DIR/;
69+
print; }}
70+
close(MYSQLD_LOG);
71+
EOF
2772

28-
--replace_result mysqld-debug mysqld $MYSQL_TEST_DIR_ABS MYSQL_TEST_DIR
2973
--error 1
30-
exec $MYSQLD --defaults-file=with.ext --print-defaults 2>&1;
74+
exec $MYSQLD --defaults-file=with.ext --print-defaults 2>$MDF_LOG;
75+
--perl
76+
use strict;
77+
my $mysqld_log= $ENV{'MDF_LOG'};
78+
my $test_dir= $ENV{'MYSQL_TEST_DIR_ABS'};
79+
open(MYSQLD_LOG, $mysqld_log) || die "5 - Failed to open '$mysqld_log': $!";
80+
while(<MYSQLD_LOG>) {
81+
if (!(/NOTIFY_SOCKET not set in environment/) &&
82+
!(/Invalid systemd notify socket, cannot send: /)) {
83+
s/mysqld-debug/mysqld/;
84+
s/$test_dir/MYSQL_TEST_DIR/;
85+
print; }}
86+
close(MYSQLD_LOG);
87+
EOF
3188

32-
--replace_result mysqld-debug mysqld $MYSQL_TEST_DIR_ABS MYSQL_TEST_DIR
3389
--error 1
34-
exec $MYSQLD --defaults-file=no_extension --print-defaults 2>&1;
90+
exec $MYSQLD --defaults-file=no_extension --print-defaults 2>$MDF_LOG;
91+
--perl
92+
use strict;
93+
my $mysqld_log= $ENV{'MDF_LOG'};
94+
my $test_dir= $ENV{'MYSQL_TEST_DIR_ABS'};
95+
open(MYSQLD_LOG, $mysqld_log) || die "6 - Failed to open '$mysqld_log': $!";
96+
while(<MYSQLD_LOG>) {
97+
if (!(/NOTIFY_SOCKET not set in environment/) &&
98+
!(/Invalid systemd notify socket, cannot send: /)) {
99+
s/mysqld-debug/mysqld/;
100+
s/$test_dir/MYSQL_TEST_DIR/;
101+
print; }}
102+
close(MYSQLD_LOG);
103+
EOF
35104

105+
--remove_file $MDF_LOG

sql/sd_notify.cc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2018, 2020, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -41,7 +41,7 @@
4141

4242
#include <errno.h> // errno
4343
#include <string.h> // strcpy
44-
#include <iostream> // std::cout
44+
#include <iostream> // std::cerr
4545

4646
#include <mysqld_error.h> // error logging
4747
#include "my_sys.h" // my_strerror
@@ -64,12 +64,17 @@ void notify_connect() {
6464
#ifndef _WIN32
6565
const char *sockstr = getenv("NOTIFY_SOCKET");
6666
if (sockstr == nullptr) {
67+
#ifdef WITH_SYSTEMD_DEBUG
68+
sql_print_warning(
69+
"NOTIFY_SOCKET not set in environment. sd_notify messages will not be "
70+
"sent!");
71+
#endif /* WITH_SYSTEMD_DEBUG */
6772
return;
6873
}
6974
size_t sockstrlen = strlen(sockstr);
7075
size_t sunpathlen = sizeof(sockaddr_un::sun_path) - 1;
7176
if (sockstrlen > sunpathlen) {
72-
std::cerr << "NOTIFY_SOCKET too long" << std::endl;
77+
std::cerr << "Error: NOTIFY_SOCKET too long" << std::endl;
7378
LogErr(SYSTEM_LEVEL, ER_SYSTEMD_NOTIFY_PATH_TOO_LONG, sockstr, sockstrlen,
7479
sunpathlen);
7580
return;
@@ -118,12 +123,14 @@ void notify() {
118123
NotifyGlobals::fmt.str(""); // clear the fmt buffer for new notification
119124
});
120125

121-
#ifdef SYSD_DBUG
122-
std::cout << "Send to systemd notify socket:\n" << note << std::endl;
126+
#ifdef WITH_SYSTEMD_DEBUG
123127
if (NotifyGlobals::socket == -1) {
128+
sql_print_warning("Invalid systemd notify socket, cannot send: %s",
129+
note.c_str());
124130
return;
125131
}
126-
#endif /* SYSD_DBUG */
132+
std::cerr << "Send to systemd notify socket: " << note;
133+
#endif /* WITH_SYSTEMD_DEBUG */
127134

128135
while (true) {
129136
size_t remaining = end - src;

sql/sd_notify.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2018, 2020, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -22,7 +22,7 @@
2222

2323
#include <sstream>
2424

25-
//#define SYSD_DBUG 1
25+
// build with -DWITH_SYSTEMD_DEBUG=1 as needed!
2626
namespace sysd {
2727
void notify_connect();
2828
void notify();
@@ -56,11 +56,11 @@ class NotifyGlobals {
5656
template <typename T, typename... Ts>
5757
inline void notify(T t, Ts... ts) {
5858
#ifndef _WIN32
59-
#ifndef SYSD_DBUG
59+
#ifndef WITH_SYSTEMD_DEBUG
6060
if (NotifyGlobals::socket == -1) {
6161
return;
6262
}
63-
#endif /* not defined SYSD_DBUG */
63+
#endif /* WITH_SYSTEMD_DEBUG */
6464
NotifyGlobals::fmt << t;
6565
notify(ts...);
6666
#endif /* not defined _WIN32 */

0 commit comments

Comments
 (0)