74 lines
2.2 KiB
Diff
74 lines
2.2 KiB
Diff
|
|
From fa50623394f491b975dbd7ad73193519dd721771 Mon Sep 17 00:00:00 2001
|
||
|
|
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
|
||
|
|
Date: Sun, 20 Jan 2019 00:13:15 -0800
|
||
|
|
Subject: [PATCH 46/87] tail: fix handling of broken pipes with SIGPIPE ignored
|
||
|
|
|
||
|
|
* init.cfg (trap_sigpipe_or_skip_): A new function refactored from...
|
||
|
|
* tests/misc/printf-surprise.sh: ...here.
|
||
|
|
* tests/misc/seq-epipe.sh. Likewise.
|
||
|
|
* src/tail.c (die_pipe): Ensure we exit upon sending SIGPIPE.
|
||
|
|
* tests/tail-2/pipe-f.sh: Ensure we exit even if SIGPIPE is ignored.
|
||
|
|
* NEWS: Mention the bug fix.
|
||
|
|
---
|
||
|
|
init.cfg | 6 ++++++
|
||
|
|
src/tail.c | 12 ++++++++++--
|
||
|
|
2 files changed, 16 insertions(+), 2 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/init.cfg b/init.cfg
|
||
|
|
index d99a0e3dd..739ba33df 100644
|
||
|
|
--- a/init.cfg
|
||
|
|
+++ b/init.cfg
|
||
|
|
@@ -610,6 +610,12 @@ mkfifo_or_skip_()
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
+trap_sigpipe_or_skip_()
|
||
|
|
+{
|
||
|
|
+ (trap '' PIPE && yes | :) 2>&1 | grep -qF 'Broken pipe' ||
|
||
|
|
+ skip_ 'trapping SIGPIPE is not supported'
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
# Disable the current test if the working directory seems to have
|
||
|
|
# the setgid bit set.
|
||
|
|
skip_if_setgid_()
|
||
|
|
diff --git a/src/tail.c b/src/tail.c
|
||
|
|
index c63b61631..b8064853f 100644
|
||
|
|
--- a/src/tail.c
|
||
|
|
+++ b/src/tail.c
|
||
|
|
@@ -330,6 +330,14 @@ named file in a way that accommodates renaming, removal and creation.\n\
|
||
|
|
exit (status);
|
||
|
|
}
|
||
|
|
|
||
|
|
+/* Ensure exit, either with SIGPIPE or EXIT_FAILURE status. */
|
||
|
|
+static void ATTRIBUTE_NORETURN
|
||
|
|
+die_pipe (void)
|
||
|
|
+{
|
||
|
|
+ raise (SIGPIPE);
|
||
|
|
+ exit (EXIT_FAILURE);
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
/* If the output has gone away, then terminate
|
||
|
|
as we would if we had written to this output. */
|
||
|
|
static void
|
||
|
|
@@ -348,7 +356,7 @@ check_output_alive (void)
|
||
|
|
/* readable event on STDOUT is equivalent to POLLERR,
|
||
|
|
and implies an error condition on output like broken pipe. */
|
||
|
|
if (select (STDOUT_FILENO + 1, &rfd, NULL, NULL, &delay) == 1)
|
||
|
|
- raise (SIGPIPE);
|
||
|
|
+ die_pipe();
|
||
|
|
}
|
||
|
|
|
||
|
|
static bool
|
||
|
|
@@ -1645,7 +1653,7 @@ tail_forever_inotify (int wd, struct File_spec *f, size_t n_files,
|
||
|
|
{
|
||
|
|
/* readable event on STDOUT is equivalent to POLLERR,
|
||
|
|
and implies an error on output like broken pipe. */
|
||
|
|
- raise (SIGPIPE);
|
||
|
|
+ die_pipe();
|
||
|
|
}
|
||
|
|
else
|
||
|
|
break;
|
||
|
|
--
|
||
|
|
2.19.1
|
||
|
|
|