On 02/03/17 22:27, Pádraig Brady wrote:
> On 02/03/17 20:59, Assaf Gordon wrote:
>> Additional strange thing is that on two OpenSolaris systems (SunOS 5.11 x86 
>> and sparc),
>> it seems the test '/tests/misc/timeout.sh' hangs (the command "timeout .5 sh 
>> -c 'sleep 2; echo foo'" does not terminate).
>> That could be a problem in my setup. I haven't had a chance to investigate 
>> further.
>> But so far I don't have test results for any OpenSolaris system.
> 
> Well drats. timeout(1) has changed to use sigsuspend()
> I'll have a look around for a solaris system...

Found one. The attached should fix this up.

cheers,
Pádraig.

>From 6555f418839a81e215898b2a7d6612d4d642f1ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Fri, 3 Mar 2017 00:30:20 -0800
Subject: [PATCH] timeout: handle multiple children on solaris

* src/timeout.c (install_sigchld): A new function to
install the SIGCHLD handler using sigaction() rather
than signal(), because with the latter on solaris
the signal handler is reset to default and thus
sigsuspend() only returns for the first finished child.
Reported by Assaf Gordon.
---
 src/timeout.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/timeout.c b/src/timeout.c
index 6fe0542..2f1ec64 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -324,6 +324,18 @@ parse_duration (const char* str)
 }
 
 static void
+install_sigchld (void)
+{
+  struct sigaction sa;
+  sigemptyset (&sa.sa_mask);  /* Allow concurrent calls to handler */
+  sa.sa_handler = chld;
+  sa.sa_flags = SA_RESTART;   /* Restart syscalls if possible, as that's
+                                 more likely to work cleanly.  */
+
+  sigaction (SIGCHLD, &sa, NULL);
+}
+
+static void
 install_cleanup (int sigterm)
 {
   struct sigaction sa;
@@ -457,7 +469,7 @@ main (int argc, char **argv)
   install_cleanup (term_signal);
   signal (SIGTTIN, SIG_IGN);   /* Don't stop if background child needs tty.  */
   signal (SIGTTOU, SIG_IGN);   /* Don't stop if background child needs tty.  */
-  signal (SIGCHLD, chld);      /* Interrupt sigsuspend() when child exits.   */
+  install_sigchld ();          /* Interrupt sigsuspend() when child exits.   */
 
   monitored_pid = fork ();
   if (monitored_pid == -1)
-- 
2.9.3

Reply via email to