Instead we'll add a --quiet option to support more robust operation
in edge cases that might warrant it.
* src/timeout.c (cleanup): Restore diagnostic of --kill without -f.
Also remove the complexity and (small races) with unblocking SIGALRM.
* NEWS: Adjust accordingly.
---
NEWS | 9 +++------
src/timeout.c | 35 +++++++++--------------------------
2 files changed, 12 insertions(+), 32 deletions(-)
diff --git a/NEWS b/NEWS
index 5e7ffe693..8a5c71124 100644
--- a/NEWS
+++ b/NEWS
@@ -387,12 +387,9 @@ GNU coreutils NEWS -*-
outline -*-
or hangs as it has done since coreutils-8.27, once the command exits.
[bugs introduced in coreutils-8.14]
- 'timeout --verbose' no longer hangs or loops forever in the edge case
- where writing the diagnostics would block or generate a signal respectively.
- Instead these edge cases will not have a corresponding diagnostic issued.
- Also --kill-after without --foreground, will not have a diagnostic issued,
- but will now be resilient to a blocked standard error, and no longer hangs.
- [hang bug introduced in coreutils-8.29, and loop bug in coreutils 9.10]
+ 'timeout --verbose' no longer loops when writing a diagnostic
+ generates a SIGPIPE or SIGXFSZ signal.
+ [bug introduced in coreutils-9.10]
'unexpand' no longer overflows a heap buffer on non-GLIBC platforms,
given whitespace characters whose display width is negative. E.g.,
diff --git a/src/timeout.c b/src/timeout.c
index e2d1ccdca..c297259f0 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -277,6 +277,14 @@ cleanup (int sig)
/* Send the signal directly to the monitored child,
in case it has itself become group leader,
or is not running in a separate group. */
+ if (diagnose)
+ {
+ char signame[MAX (SIG2STR_MAX, INT_BUFSIZE_BOUND (int))];
+ if (sig == 0 || sig2str (sig, signame) != 0)
+ snprintf (signame, sizeof signame, "%d", sig);
+ error (0, 0, _("sending signal %s to command %s"),
+ signame, quote (command));
+ }
send_sig (monitored_pid, sig);
/* The normal case is the job has remained in our
@@ -291,8 +299,7 @@ cleanup (int sig)
}
}
- /* Do this after send_sig() so the new SIGALRM can't be discarded,
- but before diagnosing, as the diagnostic could block. */
+ /* Do this after send_sig() so the new SIGALRM can't be discarded. */
if (kill_after)
{
int saved_errno = errno; /* settimeout may reset. */
@@ -302,30 +309,6 @@ cleanup (int sig)
kill_after = 0; /* Don't let later signals reset kill alarm. */
errno = saved_errno;
}
-
- /* Diagnose only after sending signals, since stderr could block.
- Note this implies we don't diagnose a --kill-after without -f,
- but being killed will be apparent in the exit status and
- corresponding shell diagnostic at least. */
- if (diagnose)
- {
- char signame[MAX (SIG2STR_MAX, INT_BUFSIZE_BOUND (int))];
- if (sig == 0 || sig2str (sig, signame) != 0)
- snprintf (signame, sizeof signame, "%d", sig);
-
- /* Let --kill-after interrupt a blocked diagnostic. Without -f,
- its group-wide SIGKILL terminates us before diagnosing again. */
- sigset_t alarm_set, old_set;
- sigemptyset (&alarm_set);
- sigaddset (&alarm_set, SIGALRM);
- bool restore_mask = (!foreground
- && sigprocmask (SIG_UNBLOCK, &alarm_set,
- &old_set) == 0);
- error (0, 0, _("sending signal %s to command %s"),
- signame, quote (command));
- if (restore_mask)
- sigprocmask (SIG_SETMASK, &old_set, NULL);
- }
}
else if (monitored_pid == -1)
{ /* were in the parent, so let it continue to exit below. */
--
2.56.0