From e67639a6822c906b65b25850cd6c00738c2db648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 5 Dec 2021 15:25:26 +0100 Subject: [PATCH] main: ignore SIGPIPE We want to handle SIGPIPEs without crashing... One way to trigger this was to use e.g. pipe-visible=[cat /foo/bar] Control+Shift+q That is, pipe output to something that did not consume it. This led to a SIGPIPE when we tried to write the terminal contents to the pipe, and crashed the whole foot instance. --- main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 4f2dc7b6..b5a610e2 100644 --- a/main.c +++ b/main.c @@ -556,8 +556,11 @@ main(int argc, char *const *argv) goto out; } - if (sigaction(SIGHUP, &(struct sigaction){.sa_handler = SIG_IGN}, NULL) < 0) { - LOG_ERRNO("failed to ignore SIGHUP"); + const struct sigaction sig_ign = {.sa_handler = SIG_IGN}; + if (sigaction(SIGHUP, &sig_ign, NULL) < 0 || + sigaction(SIGPIPE, &sig_ign, NULL) < 0) + { + LOG_ERRNO("failed to ignore SIGHUP+SIGPIPE"); goto out; }