From 20085b9da8cada6e59b8d08c0a05f710add71708 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 11 Oct 2014 13:45:23 +0200 Subject: [PATCH] core: ignore SIGPIPE Ignoring SIGPIPE signal, otherwise it causes problems. For example, running `NetworkManager --debug 2>&1 | tee log.txt` in a terminal and killing it with CTRL+C (SIGINT), will abruplty terminate NetworkManager without clean shutdown. Note, that with this patch and above example, NetworkManager will both receive SIGINT and SIGPIPE. Since we now ignore SIGPIPE, NetworkManager will shut down cleanly. Any logging output after killing `tee` is of lost however. Also, there might be other cases where NM reads/writes to a pipe/socket and unexpectedly received SIGPIPE. For example nm-dns-manager.c spawns netconfig (run_netconfig()) and writes the configuration to its stdin. If netconfig dies, the write might fail with EPIPE. Signed-off-by: Thomas Haller --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index 17769587a9..f4f693d1e4 100644 --- a/src/main.c +++ b/src/main.c @@ -99,6 +99,9 @@ signal_handling_thread (void *arg) /* Reread config stuff like system config files, VPN service files, etc */ nm_log_info (LOGD_CORE, "caught signal %d, not supported yet.", signo); break; + case SIGPIPE: + /* silently ignore signal */ + break; default: nm_log_err (LOGD_CORE, "caught unexpected signal %d", signo); break; @@ -124,6 +127,7 @@ setup_signals (void) sigaddset (&signal_set, SIGHUP); sigaddset (&signal_set, SIGINT); sigaddset (&signal_set, SIGTERM); + sigaddset (&signal_set, SIGPIPE); /* Block all signals of interest. */ status = pthread_sigmask (SIG_BLOCK, &signal_set, &old_sig_mask);