dhcp: fix dhclient abnormal exit due to SIGPIPE (bgo #735962)

DHCP client may be killed by SIGPIPE when attempting to write to a broken pipe.
This can be observed, for example, when journald is restarted.

Fix that by redirecting both stdout and stderr to /dev/null. The client logs
into syslog anyway. When NetworkManager is run with '--debug' we duplicate
syslog to stderr, so the messages goes to terminal as well.

Testcase:
- start a NetworkManager service by systemd
- activate an DHCP ethernet connection
- sudo systemctl restart systemd-journald.service
- reactive the ethernet connection (nmcli con up <my-eth>)
- DHCP client is killed by SIGPIPE right after its startup:
    <info> (enp0s25): DHCPv4 client pid 13959 exited with status -1
    <warn> DHCP client died abnormally

Another possible fix would be ignoring SIGPIPE in the DHCP client as it is not
useful in most cases. E.g. systemd ignores SIGPIPE for its services, by
default:
http://cgit.freedesktop.org/systemd/systemd/commit/?id=353e12c2f4a9e96a47eb80b80d2ffb7bc1d44a1b

https://bugzilla.gnome.org/show_bug.cgi?id=735962
This commit is contained in:
Jiří Klimeš 2014-09-09 13:32:46 +02:00
parent 6d659ab2cd
commit b27669612e
2 changed files with 10 additions and 3 deletions

View file

@ -402,6 +402,11 @@ dhclient_start (NMDhcpClient *client,
g_ptr_array_add (argv, (gpointer) "-d");
/* Be quiet. dhclient logs to syslog anyway. And we duplicate the syslog
* to stderr in case of NM running with --debug.
*/
g_ptr_array_add (argv, (gpointer) "-q");
if (release)
g_ptr_array_add (argv, (gpointer) "-r");
@ -445,8 +450,9 @@ dhclient_start (NMDhcpClient *client,
nm_log_dbg (log_domain, "running: %s", cmd_str);
g_free (cmd_str);
if (g_spawn_async (NULL, (char **) argv->pdata, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
&dhclient_child_setup, NULL, &pid, &error)) {
if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
&dhclient_child_setup, NULL, &pid, &error)) {
g_assert (pid > 0);
nm_log_info (log_domain, "dhclient started with pid %d", pid);
if (release == FALSE)

View file

@ -141,7 +141,8 @@ ip4_start (NMDhcpClient *client,
nm_log_dbg (LOGD_DHCP4, "running: %s", cmd_str);
g_free (cmd_str);
if (g_spawn_async (NULL, (char **) argv->pdata, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
&dhcpcd_child_setup, NULL, &pid, &error)) {
g_assert (pid > 0);
nm_log_info (LOGD_DHCP4, "dhcpcd started with pid %d", pid);