From unknown Sat Sep 06 02:03:47 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#8938 <8938@debbugs.gnu.org> To: bug#8938 <8938@debbugs.gnu.org> Subject: Status: make timeout and CTRL-C Reply-To: bug#8938 <8938@debbugs.gnu.org> Date: Sat, 06 Sep 2025 09:03:47 +0000 retitle 8938 make timeout and CTRL-C reassign 8938 coreutils submitter 8938 shay shimony severity 8938 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Jun 26 17:47:22 2011 Received: (at submit) by debbugs.gnu.org; 26 Jun 2011 21:47:22 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QaxAn-0001YL-3k for submit@debbugs.gnu.org; Sun, 26 Jun 2011 17:47:21 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QautJ-0007Y2-21 for submit@debbugs.gnu.org; Sun, 26 Jun 2011 15:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QautC-0001bO-LW for submit@debbugs.gnu.org; Sun, 26 Jun 2011 15:21:03 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:40681) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QautC-0001bK-B6 for submit@debbugs.gnu.org; Sun, 26 Jun 2011 15:21:02 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QautA-0006Jq-Kn for bug-coreutils@gnu.org; Sun, 26 Jun 2011 15:21:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qaut8-0001aq-MT for bug-coreutils@gnu.org; Sun, 26 Jun 2011 15:21:00 -0400 Received: from mail-vx0-f169.google.com ([209.85.220.169]:54906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qaut8-0001aj-AM for bug-coreutils@gnu.org; Sun, 26 Jun 2011 15:20:58 -0400 Received: by vxg38 with SMTP id 38so3777210vxg.0 for ; Sun, 26 Jun 2011 12:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type; bh=lCpS3pjlcS4kFnjFjL7ogShpEJdy4Nk/LYMdg71YXIs=; b=dhn7/DtDLwL7bOdumHL+prQEJxTkmknF/gTWT0une8IiXGL4tao6fzU4j07/1x4lgS 7Id2bdq3GI7QmObeU+MEqhUsBqwujswDcMTBq6vPS85MxQwsr4jSz5zrKoPiO1+n22Jn 8NIlU6SjHUDYM3M/Pf2kElIsoOoo5SmZ7d8bE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=mBmx22sjVZXrAGozHUbXnyP9rXdYgayJXzpwgaQJHtEukLgv7np38ynke3w4RMsu2u uRO3IjT9de/D2Vw7K8g7hBDNU+l2zoTx/v3iI7vCHPKawoEQan6uTZgJKbSi8q8RW2kh I5hRXth2E5CRb+ctgioRZGPw3GrBU04h1gFMQ= Received: by 10.52.176.10 with SMTP id ce10mr7402924vdc.280.1309116057139; Sun, 26 Jun 2011 12:20:57 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.170.170 with HTTP; Sun, 26 Jun 2011 12:20:37 -0700 (PDT) From: shay shimony Date: Sun, 26 Jun 2011 22:20:37 +0300 Message-ID: Subject: make timeout and CTRL-C To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary=bcaec51a81848e3a5a04a6a255c6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 26 Jun 2011 17:47:20 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) --bcaec51a81848e3a5a04a6a255c6 Content-Type: text/plain; charset=ISO-8859-1 Hello coreutils team, I found that if you run timeout inside make file then CTRL-C doesn't work. Really frustrating because I use timeout to terminate deadlocked tests, but can't stop them with CTRL-C as I used to. To reproduce copy the following into file named Makefile: all: timeout 12 sleep 10 Note there is a tab before "timeout 12 sleep 10". Then run at same directory where the file is located "make" and try to press CTRL-C. Notes: CTRL-Z works. When executing timeout without make CTRL-C works. When executing make without timeout CTRL-C works. Thanks, Shay --bcaec51a81848e3a5a04a6a255c6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hello coreutils team,

I found that if you run timeo= ut inside make file then CTRL-C doesn't work. Really frustrating becaus= e I use timeout to terminate deadlocked tests, but can't stop them with= CTRL-C as I used to.

To reproduce copy the following into file named Makefile:

all:=A0=A0=A0=A0=A0=A0=A0 timeout 12 sleep 10

Note there is a tab befo= re "timeout 12 sleep 10".
Then run at same directory where the= file is located "make" and try to press CTRL-C.

Notes:
CTRL-Z works.
When executing timeout without make CTRL-C w= orks.
When executing make without timeout CTRL-C works.

Thanks,Shay
--bcaec51a81848e3a5a04a6a255c6-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 27 08:03:38 2011 Received: (at 8938) by debbugs.gnu.org; 27 Jun 2011 12:03:39 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbAXS-0004up-CM for submit@debbugs.gnu.org; Mon, 27 Jun 2011 08:03:38 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbAXP-0004ub-KH for 8938@debbugs.gnu.org; Mon, 27 Jun 2011 08:03:36 -0400 Received: (qmail 27357 invoked from network); 27 Jun 2011 12:03:29 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 27 Jun 2011 12:03:29 -0000 Message-ID: <4E087174.9020402@draigBrady.com> Date: Mon, 27 Jun 2011 13:03:00 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: shay shimony Subject: Re: bug#8938: make timeout and CTRL-C References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) On 26/06/11 20:20, shay shimony wrote: > Hello coreutils team, > > I found that if you run timeout inside make file then CTRL-C doesn't work. > Really frustrating because I use timeout to terminate deadlocked tests, but > can't stop them with CTRL-C as I used to. > > To reproduce copy the following into file named Makefile: > > all: > timeout 12 sleep 10 > > Note there is a tab before "timeout 12 sleep 10". > Then run at same directory where the file is located "make" and try to press > CTRL-C. > > Notes: > CTRL-Z works. > When executing timeout without make CTRL-C works. > When executing make without timeout CTRL-C works. Drats, That because SIGINT is sent by the terminal to the foreground group. The issue is that `make` and `timeout` use much the same method to control their jobs. I.E. they create their own process group so they can terminate all sub-processes. So in your case, make creates its own program group and is in the foreground. Because timeout does too, it will not get SIGINT from the terminal. Really `make` should propagate the SIGINT down, though I suppose the same thing could be said for `timeout`. I.E. the following demonstrates the same issue and times out after 10s and is also unresponsive to CTRL-C: timeout 5 timeout 10 sleep 20 Note a handy way to see the process structure of timeout and make is: ps -C make -C timeout -o ppid,pgid,pgrp,pid,tty,sess,comm So what to do. The cascaded timeouts could be handled by timeout sending a signal to the child process as well as the process group. But that won't fix the make case as `make` would have to do something similar. Maybe I could add an option to not create a separate group. I'll need to think a bit about this. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 27 16:12:55 2011 Received: (at 8938) by debbugs.gnu.org; 27 Jun 2011 20:12:55 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbIAw-0006Xr-S8 for submit@debbugs.gnu.org; Mon, 27 Jun 2011 16:12:55 -0400 Received: from c-67-162-90-113.hsd1.in.comcast.net ([67.162.90.113] helo=kosh.dhis.org) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbIAt-0006Xe-QR for 8938@debbugs.gnu.org; Mon, 27 Jun 2011 16:12:52 -0400 Received: (qmail 16471 invoked by uid 1000); 27 Jun 2011 20:12:45 -0000 Message-ID: <20110627201245.16470.qmail@kosh.dhis.org> From: "Alan Curry" Subject: Re: bug#8938: make timeout and CTRL-C To: P@draigBrady.com (=?UTF-8?Q?P=C3=A1draig?= Brady) Date: Mon, 27 Jun 2011 15:12:45 -0500 (GMT+5) In-Reply-To: <4E087174.9020402@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Score: -0.8 (/) X-Debbugs-Envelope-To: 8938 Cc: shay shimony , 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.8 (/) =?UTF-8?Q?P=C3=A1draig?= Brady writes: > > On 26/06/11 20:20, shay shimony wrote: > > all: > > timeout 12 sleep 10 > > > > Note there is a tab before "timeout 12 sleep 10". > > Then run at same directory where the file is located "make" and try to press > > CTRL-C. > > > > Notes: > > CTRL-Z works. > > When executing timeout without make CTRL-C works. > > When executing make without timeout CTRL-C works. > > Drats, > > That because SIGINT is sent by the terminal to the foreground group. > The issue is that `make` and `timeout` use much the same method > to control their jobs. I.E. they create their own process group > so they can terminate all sub-processes. Are you sure? I see no evidence of that. When I run make with the above makefile, the processes look like this: PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND 1 1451 1451 1451 6 16407 S 1000 0:06 -zsh 1451 16407 16407 1451 6 16407 S 1000 0:00 make 16407 16408 16408 1451 6 16407 S 1000 0:00 timeout 60 sleep 30 16408 16409 16408 1451 6 16407 S 1000 0:00 sleep 30 The first PGID is the login shell. The second PGID is make, which was put into its own process group by the shell because the shell has job control enabled. The last PGID is timeout, which put itself into a process group. make never noticed any of them. In the source for GNU make 3.82 there are no calls to setpgrp or setpgid (unless obfuscated from grep). There is the following comment: /* A termination signal won't be sent to the entire process group, but it means we want to kill the children. */ That's above the handling of SIGTERM, which iterates over child processes and passes along the SIGTERM to them. After that is the handling of SIGINT, which doesn't kill child processes (unless they're "remote", which is... news to me that make does remote things) but just waits for them. What seems to be happening is that make *doesn't* create a process group, therefore assumes that when it gets a SIGINT, its children have already gotten it too, and it just waits for them to die. A child that puts itself into a new process group screws this up (as would kill -2 `pidof make`). I think the answer is that timeout should put itself into the foreground. That way it would get the SIGINT. make wouldn't get it, but wouldn't need to. timeout would exit quickly after SIGINT and make would proceed or abort according to the exit code. -- Alan Curry From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 27 18:23:47 2011 Received: (at 8938) by debbugs.gnu.org; 27 Jun 2011 22:23:48 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbKDa-00082J-Mi for submit@debbugs.gnu.org; Mon, 27 Jun 2011 18:23:47 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbKDY-000825-3d for 8938@debbugs.gnu.org; Mon, 27 Jun 2011 18:23:45 -0400 Received: (qmail 30512 invoked from network); 27 Jun 2011 22:23:37 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 27 Jun 2011 22:23:37 -0000 Message-ID: <4E0902CB.2010005@draigBrady.com> Date: Mon, 27 Jun 2011 23:23:07 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Alan Curry Subject: Re: bug#8938: make timeout and CTRL-C References: <20110627201245.16470.qmail@kosh.dhis.org> In-Reply-To: <20110627201245.16470.qmail@kosh.dhis.org> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------000003030307000505070101" X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8938 Cc: shay shimony , 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) This is a multi-part message in MIME format. --------------000003030307000505070101 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 27/06/11 21:12, Alan Curry wrote: > =?UTF-8?Q?P=C3=A1draig?= Brady writes: >> >> On 26/06/11 20:20, shay shimony wrote: >>> all: >>> timeout 12 sleep 10 >>> >>> Note there is a tab before "timeout 12 sleep 10". >>> Then run at same directory where the file is located "make" and try to press >>> CTRL-C. >>> >>> Notes: >>> CTRL-Z works. >>> When executing timeout without make CTRL-C works. >>> When executing make without timeout CTRL-C works. >> >> Drats, >> >> That because SIGINT is sent by the terminal to the foreground group. >> The issue is that `make` and `timeout` use much the same method >> to control their jobs. I.E. they create their own process group >> so they can terminate all sub-processes. > > Are you sure? I see no evidence of that. When I run make with the above > makefile, the processes look like this: > > PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND > 1 1451 1451 1451 6 16407 S 1000 0:06 -zsh > 1451 16407 16407 1451 6 16407 S 1000 0:00 make > 16407 16408 16408 1451 6 16407 S 1000 0:00 timeout 60 sleep 30 > 16408 16409 16408 1451 6 16407 S 1000 0:00 sleep 30 > > The first PGID is the login shell. The second PGID is make, which was put > into its own process group by the shell because the shell has job control > enabled. The last PGID is timeout, which put itself into a process group. > make never noticed any of them. > > In the source for GNU make 3.82 there are no calls to setpgrp or setpgid > (unless obfuscated from grep). There is the following comment: > > /* A termination signal won't be sent to the entire > process group, but it means we want to kill the children. */ > > That's above the handling of SIGTERM, which iterates over child processes and > passes along the SIGTERM to them. > > After that is the handling of SIGINT, which doesn't kill child processes > (unless they're "remote", which is... news to me that make does remote > things) but just waits for them. > > What seems to be happening is that make *doesn't* create a process group, > therefore assumes that when it gets a SIGINT, its children have already > gotten it too, and it just waits for them to die. A child that puts itself > into a new process group screws this up (as would kill -2 `pidof make`). Thanks for the analysis Alan. Yes you're right I think. In any case the important point is that timeout sets itself as group leader, and is not the foreground group. > > I think the answer is that timeout should put itself into the foreground. > That way it would get the SIGINT. make wouldn't get it, but wouldn't need to. > timeout would exit quickly after SIGINT and make would proceed or abort > according to the exit code. I've a version locally here actually that calls tcsetpgrp() but I discounted that as it's not timeout's place to call that I think. timeout sets itself as group leader so that it can kill everything it starts, but it shouldn't need to grab the foreground group as the shell (or make) may be starting it in the background etc. So really `make` should not assume children stay in the same group, and propagate signals down (like it does for TERM). It might be appropriate for `make` to call tcsetpgrp() before exec..() but given remote & parallel jobs etc. signal propagation might be best. I've fixed up `timeout` itself not assume children stay in the same group, and pass signals on, in the attached patch. cheers, Pádraig. --------------000003030307000505070101 Content-Type: text/x-patch; name="timeout-timeout.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="timeout-timeout.diff" >From 60f225e8806707bc899c53732d2796cdfd1d9b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Mon, 27 Jun 2011 19:33:16 +0100 Subject: [PATCH] timeout: support cascaded timeouts * src/timeout.c (cleanup): Send signals directly to the child in case it has started its own process group (like a cascaded timeout command would for example). * test/misc/timeout: Add a test case. * NEWS: Mention the fix. Reported by Shay Shimony --- NEWS | 3 +++ src/timeout.c | 10 +++++++++- tests/misc/timeout | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletions(-) diff --git a/NEWS b/NEWS index 619fbdd..e18a6ec 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,9 @@ GNU coreutils NEWS -*- outline -*- split --number l/... no longer creates extraneous files in certain cases. [bug introduced in coreutils-8.8] + timeout now sends signals to commands that create their own process group. + [bug introduced in coreutils-7.0] + ** Changes in behavior chmod, chown and chgrp now output the original attributes in messages, diff --git a/src/timeout.c b/src/timeout.c index a686225..3877fae 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -108,9 +108,17 @@ cleanup (int sig) alarm (kill_after); kill_after = 0; /* Don't let later signals reset kill alarm. */ } + /* Send the signal directly to the monitored child, + in case it has itself become group leader. */ + send_sig (monitored_pid, sig); + /* The normal case is the job has remained in our + newly created process group, so send to all processes in that. */ send_sig (0, sig); if (sig != SIGKILL && sig != SIGCONT) - send_sig (0, SIGCONT); + { + send_sig (monitored_pid, SIGCONT); + send_sig (0, SIGCONT); + } } else /* we're the child or the child is not exec'd yet. */ _exit (128 + sig); diff --git a/tests/misc/timeout b/tests/misc/timeout index 7506e7c..080436c 100755 --- a/tests/misc/timeout +++ b/tests/misc/timeout @@ -51,4 +51,21 @@ test $? = 124 && fail=1 exec timeout 10 true ) || fail=1 +cat <<\EOF > sleep_usr1 +#!/bin/sh +trap 'echo USR1; exit' USR1 +sleep $1& +wait +EOF +chmod a+x sleep_usr1 + +# Ensure the first timeout kills the processes, +# which was not the case before 8.13. +# Note the first timeout must send a signal that +# the second is handling for it to be propagated to the command. +# SIGINT, SIGTERM, SIGALRM etc. are implicit. +timeout -sALRM 1 timeout -sUSR1 10 ./sleep_usr1 5 > out +echo USR1 > exp +compare out exp || fail=1 + Exit $fail -- 1.7.5.2 --------------000003030307000505070101-- From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 27 18:55:21 2011 Received: (at 8938) by debbugs.gnu.org; 27 Jun 2011 22:55:21 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbKi8-0001rm-Nf for submit@debbugs.gnu.org; Mon, 27 Jun 2011 18:55:21 -0400 Received: from c-67-162-90-113.hsd1.in.comcast.net ([67.162.90.113] helo=kosh.dhis.org) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbKi7-0001rY-1G for 8938@debbugs.gnu.org; Mon, 27 Jun 2011 18:55:19 -0400 Received: (qmail 7507 invoked by uid 1000); 27 Jun 2011 22:55:13 -0000 Message-ID: <20110627225513.7506.qmail@kosh.dhis.org> From: "Alan Curry" Subject: Re: bug#8938: make timeout and CTRL-C To: P@draigBrady.com (=?UTF-8?Q?P=C3=A1draig?= Brady) Date: Mon, 27 Jun 2011 17:55:13 -0500 (GMT+5) In-Reply-To: <4E0902CB.2010005@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Score: -0.8 (/) X-Debbugs-Envelope-To: 8938 Cc: shay shimony , 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.8 (/) =?UTF-8?Q?P=C3=A1draig?= Brady writes: > > This is a multi-part message in MIME format. > --------------000003030307000505070101 > Content-Type: text/plain; charset=ISO-8859-1 > Content-Transfer-Encoding: 8bit > > On 27/06/11 21:12, Alan Curry wrote: > > > > What seems to be happening is that make *doesn't* create a process group, > > therefore assumes that when it gets a SIGINT, its children have already > > gotten it too, and it just waits for them to die. A child that puts itself > > into a new process group screws this up (as would kill -2 `pidof make`). > > Thanks for the analysis Alan. > Yes you're right I think. > In any case the important point is that timeout sets itself as group leader, > and is not the foreground group. Right, we have a tree of process groups that goes roughly shell->make->timeout and the one in the middle of the tree is the foreground, receiving tty-based signals. > > > > > I think the answer is that timeout should put itself into the foreground. > > That way it would get the SIGINT. make wouldn't get it, but wouldn't need to. > > timeout would exit quickly after SIGINT and make would proceed or abort > > according to the exit code. > > I've a version locally here actually that calls tcsetpgrp() but I discounted > that as it's not timeout's place to call that I think. > timeout sets itself as group leader so that it can kill everything it starts, > but it shouldn't need to grab the foreground group as the shell (or make) > may be starting it in the background etc. It seems like this is a misuse of process groups, using them as if they were a handle for killing a whole tree of processes. That's not what they're for. Process groups were invented to support job control, which means the only program that was supposed to mess with them was csh. Only the lack of a "kill process tree" primitive (and the fact that you can't even query the process tree easily) tempts us into using process groups as a shortcut. Any non-job-control-aware parent process will have a problem with timeout's behavior. We've already seen what GNU make does. pmake simply dies of the SIGINT and leaves the child processes lingering (it probably also assumes they got the SIGINT, and doesn't bother waiting for them). In an interactive shell with job control disabled (set +m in most Bourne-ish shells), the behavior is not good there either. dash, bash, and posh all act like GNU make, appearing to ignore the SIGINT. zsh acts more like pmake, printing a new prompt but leaving the timeout and its child running. timeout's pgrp behavior only appears harmless when the parent process is a shell with job control, which expects its children to be in separate process groups. But in that case, timeout doesn't need to put itself in a new process group because the shell has already done so. So I suggest that if you create a process group, you take on the responsibility of behaving like a job control shell in other ways, including managing the foreground group. (An important piece of that is remembering the original value and restoring it before you exit). -- Alan Curry From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 14:19:35 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 18:19:35 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbcso-0005fK-LI for submit@debbugs.gnu.org; Tue, 28 Jun 2011 14:19:34 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbcsl-0005f5-ME for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 14:19:32 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 5DB4339E80F7; Tue, 28 Jun 2011 11:19:25 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qHX6U2NTEzBC; Tue, 28 Jun 2011 11:19:25 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 12FF239E80E0; Tue, 28 Jun 2011 11:19:25 -0700 (PDT) Message-ID: <4E0A1B2C.7060004@cs.ucla.edu> Date: Tue, 28 Jun 2011 11:19:24 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Thunderbird/3.1.10 MIME-Version: 1.0 To: =?ISO-8859-1?Q?P=E1draig_Brady?= Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> In-Reply-To: <4E087174.9020402@draigBrady.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: -3.1 (---) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.1 (---) I'd like to have an option to 'timeout' so that it merely calls alarm(2) and then execs COMMAND. This would be simple and fast would avoid the problem in question. This approach has its own issues, but when it works it works great, and it'd be a nice option. From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 14:42:35 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 18:42:35 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbdF4-0006yY-2v for submit@debbugs.gnu.org; Tue, 28 Jun 2011 14:42:34 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbdF0-0006yK-Uq for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 14:42:31 -0400 Received: (qmail 37754 invoked from network); 28 Jun 2011 18:42:24 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 28 Jun 2011 18:42:24 -0000 Message-ID: <4E0A206E.70902@draigBrady.com> Date: Tue, 28 Jun 2011 19:41:50 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> In-Reply-To: <4E0A1B2C.7060004@cs.ucla.edu> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) On 28/06/11 19:19, Paul Eggert wrote: > I'd like to have an option to 'timeout' so that > it merely calls alarm(2) and then execs COMMAND. > This would be simple and fast would avoid the problem > in question. This approach has its own issues, but > when it works it works great, and it'd be a nice option. The main problem with that is would only send the signal to the first process, and any processes it started would keep running. I think we should be able to figure out something more general. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 14:45:43 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 18:45:43 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbdI5-0007p5-Vu for submit@debbugs.gnu.org; Tue, 28 Jun 2011 14:45:42 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbdI2-0007lT-7U for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 14:45:39 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 3666139E8116; Tue, 28 Jun 2011 11:45:32 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sN5SNGPsYnvg; Tue, 28 Jun 2011 11:45:31 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id C3AB339E80E0; Tue, 28 Jun 2011 11:45:31 -0700 (PDT) Message-ID: <4E0A214B.4060607@cs.ucla.edu> Date: Tue, 28 Jun 2011 11:45:31 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Thunderbird/3.1.10 MIME-Version: 1.0 To: =?ISO-8859-1?Q?P=E1draig_Brady?= Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> In-Reply-To: <4E0A206E.70902@draigBrady.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -3.1 (---) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.1 (---) On 06/28/11 11:41, P=E1draig Brady wrote: > The main problem with that is would only > send the signal to the first process, and > any processes it started would keep running. Yes, that's the main issue with it. Still, it's handy for programs where you either know it doesn't use subprocesses, or you *want* to kill just the main program and not its subprocesses. I don't think it should be the default option, but it'd be nice to have it as an option. From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 14:50:31 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 18:50:31 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbdMl-0007vk-A1 for submit@debbugs.gnu.org; Tue, 28 Jun 2011 14:50:31 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbdMh-0007vX-Ua for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 14:50:29 -0400 Received: (qmail 39233 invoked from network); 28 Jun 2011 18:50:21 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 28 Jun 2011 18:50:21 -0000 Message-ID: <4E0A224B.2070705@draigBrady.com> Date: Tue, 28 Jun 2011 19:49:47 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Alan Curry Subject: Re: bug#8938: make timeout and CTRL-C References: <20110627225513.7506.qmail@kosh.dhis.org> In-Reply-To: <20110627225513.7506.qmail@kosh.dhis.org> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------000004000602040508040006" X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8938 Cc: shay shimony , 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) This is a multi-part message in MIME format. --------------000004000602040508040006 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 27/06/11 23:55, Alan Curry wrote: > =?UTF-8?Q?P=C3=A1draig?= Brady writes: >> >> This is a multi-part message in MIME format. >> --------------000003030307000505070101 >> Content-Type: text/plain; charset=ISO-8859-1 >> Content-Transfer-Encoding: 8bit >> >> On 27/06/11 21:12, Alan Curry wrote: >>> >>> What seems to be happening is that make *doesn't* create a process group, >>> therefore assumes that when it gets a SIGINT, its children have already >>> gotten it too, and it just waits for them to die. A child that puts itself >>> into a new process group screws this up (as would kill -2 `pidof make`). >> >> Thanks for the analysis Alan. >> Yes you're right I think. >> In any case the important point is that timeout sets itself as group leader, >> and is not the foreground group. > > Right, we have a tree of process groups that goes roughly > shell->make->timeout and the one in the middle of the tree is the > foreground, receiving tty-based signals. > >> >>> >>> I think the answer is that timeout should put itself into the foreground. >>> That way it would get the SIGINT. make wouldn't get it, but wouldn't need to. >>> timeout would exit quickly after SIGINT and make would proceed or abort >>> according to the exit code. >> >> I've a version locally here actually that calls tcsetpgrp() but I discounted >> that as it's not timeout's place to call that I think. >> timeout sets itself as group leader so that it can kill everything it starts, >> but it shouldn't need to grab the foreground group as the shell (or make) >> may be starting it in the background etc. > > It seems like this is a misuse of process groups, using them as if they > were a handle for killing a whole tree of processes. That's not what > they're for. Process groups were invented to support job control, which > means the only program that was supposed to mess with them was csh. Only > the lack of a "kill process tree" primitive (and the fact that you can't > even query the process tree easily) tempts us into using process groups > as a shortcut. > > Any non-job-control-aware parent process will have a problem with > timeout's behavior. We've already seen what GNU make does. pmake simply > dies of the SIGINT and leaves the child processes lingering (it probably > also assumes they got the SIGINT, and doesn't bother waiting for them). > > In an interactive shell with job control disabled (set +m in most > Bourne-ish shells), the behavior is not good there either. dash, bash, > and posh all act like GNU make, appearing to ignore the SIGINT. zsh acts > more like pmake, printing a new prompt but leaving the timeout and its > child running. > > timeout's pgrp behavior only appears harmless when the parent process is > a shell with job control, which expects its children to be in separate > process groups. But in that case, timeout doesn't need to put itself in > a new process group because the shell has already done so. > > So I suggest that if you create a process group, you take on the > responsibility of behaving like a job control shell in other ways, > including managing the foreground group. (An important piece of that is > remembering the original value and restoring it before you exit). I'm still not convinced we need to be messing with tcsetpgrp() but you're right in that the disconnect between the timeout process group and that of whatever starts `timeout` should be bridged. I'm testing the attached patch at the moment (which I'll split into 2). It only creates a separate group for the child that `timeout` execs, leaving the timeout process in the original group to propagate signals down. I'll need to do lots of testing with this before I commit. cheers, Pádraig. --------------000004000602040508040006 Content-Type: text/x-patch; name="timeout-groups.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="timeout-groups.diff" diff --git a/src/timeout.c b/src/timeout.c index a686225..3d5e8db 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -26,9 +26,6 @@ EXIT_ENOENT 127 couldn't find job to exec Caveats: - If user specifies the KILL (9) signal is to be sent on timeout, - the monitor is killed and so exits with 128+9 rather than 124. - If you start a command in the background, which reads from the tty and so is immediately sent SIGTTIN to stop, then the timeout process will ignore this so it can timeout the command as expected. @@ -108,9 +105,9 @@ cleanup (int sig) alarm (kill_after); kill_after = 0; /* Don't let later signals reset kill alarm. */ } - send_sig (0, sig); + send_sig (-monitored_pid, sig); if (sig != SIGKILL && sig != SIGCONT) - send_sig (0, SIGCONT); + send_sig (-monitored_pid, SIGCONT); } else /* we're the child or the child is not exec'd yet. */ _exit (128 + sig); @@ -283,12 +280,6 @@ main (int argc, char **argv) argv += optind; - /* Ensure we're in our own group so all subprocesses can be killed. - Note we don't just put the child in a separate group as - then we would need to worry about foreground and background groups - and propagating signals between them. */ - setpgid (0, 0); - /* Setup handlers before fork() so that we handle any signals caused by child, without races. */ install_signal_handlers (term_signal); @@ -310,6 +301,9 @@ main (int argc, char **argv) signal (SIGTTIN, SIG_DFL); signal (SIGTTOU, SIG_DFL); + /* Ensure we're in our own group so all subprocesses can be killed. */ + setpgid (0, 0); + execvp (argv[0], argv); /* FIXME: should we use "sh -c" ... here? */ /* exit like sh, env, nohup, ... */ @@ -341,7 +335,16 @@ main (int argc, char **argv) if (WIFEXITED (status)) status = WEXITSTATUS (status); else if (WIFSIGNALED (status)) - status = WTERMSIG (status) + 128; /* what sh does at least. */ + { + int sig = WTERMSIG (status); + if (!timed_out) + { + /* FIXME: use sigaction to ensure exit without cores etc. */ + signal (sig, SIG_DFL); + raise (sig); /* Exit with signal flag set. */ + } + status = sig + 128; /* Exit with this if didn't exit above. */ + } else { /* shouldn't happen. */ diff --git a/tests/misc/timeout b/tests/misc/timeout index 7506e7c..c7867c6 100755 --- a/tests/misc/timeout +++ b/tests/misc/timeout @@ -39,8 +39,13 @@ test $? = 124 || fail=1 # kill delay. Note once the initial timeout triggers, # the exit status will be 124 even if the command # exits on its own accord. -timeout -s0 -k1 1 sleep 10 -test $? = 124 && fail=1 +cat <<\EOF > sleep_msg +sleep $1 +echo completed +EOF +chmod a+x sleep_msg +timeout -s0 -k1 1 ./sleep_msg 10 > out +test -s out && fail=1 # Ensure `timeout` is immune to parent's SIGCHLD handler # Use a subshell and an exec to work around a bug in FreeBSD 5.0 /bin/sh. --------------000004000602040508040006-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 15:06:35 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 19:06:35 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbdcH-0000dx-SI for submit@debbugs.gnu.org; Tue, 28 Jun 2011 15:06:34 -0400 Received: from mail-vw0-f44.google.com ([209.85.212.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbd6q-0006ks-Np for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 14:34:05 -0400 Received: by vws12 with SMTP id 12so360355vws.3 for <8938@debbugs.gnu.org>; Tue, 28 Jun 2011 11:33:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=OEOD7gMnTItgYLvgbVmBtLU7nJRhHKYPH75whe13bvY=; b=oMiJB2dskJ9ymNAuWoNURs09FoTkIrtD5V6cGR7FCh/TKX/fiS5N8SppJD3hO1zOg4 j/KY1//FtqXilFCArVvEG/VDOMeRKOovE+yG3WRmJ4HQ8dsPvsPXKDpx/0wsbA1RtdfJ tXA11Tup8fTtUfObr+GvKdUhanuetHUdvrA7Y= Received: by 10.52.76.131 with SMTP id k3mr7752987vdw.80.1309286039064; Tue, 28 Jun 2011 11:33:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.170.170 with HTTP; Tue, 28 Jun 2011 11:33:39 -0700 (PDT) In-Reply-To: <4E0902CB.2010005@draigBrady.com> References: <20110627201245.16470.qmail@kosh.dhis.org> <4E0902CB.2010005@draigBrady.com> From: shay shimony Date: Tue, 28 Jun 2011 21:33:39 +0300 Message-ID: Subject: Re: bug#8938: make timeout and CTRL-C To: =?ISO-8859-1?Q?P=E1draig_Brady?= Content-Type: multipart/alternative; boundary=bcaec50160e3448fdb04a6c9e91b X-Spam-Score: -4.8 (----) X-Debbugs-Envelope-To: 8938 X-Mailman-Approved-At: Tue, 28 Jun 2011 15:06:32 -0400 Cc: Alan Curry , 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.4 (----) --bcaec50160e3448fdb04a6c9e91b Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks for taking care for this! Interesting stuff as well. 2011/6/28 P=E1draig Brady > On 27/06/11 21:12, Alan Curry wrote: > > =3D?UTF-8?Q?P=3DC3=3DA1draig?=3D Brady writes: > >> > >> On 26/06/11 20:20, shay shimony wrote: > >>> all: > >>> timeout 12 sleep 10 > >>> > >>> Note there is a tab before "timeout 12 sleep 10". > >>> Then run at same directory where the file is located "make" and try t= o > press > >>> CTRL-C. > >>> > >>> Notes: > >>> CTRL-Z works. > >>> When executing timeout without make CTRL-C works. > >>> When executing make without timeout CTRL-C works. > >> > >> Drats, > >> > >> That because SIGINT is sent by the terminal to the foreground group. > >> The issue is that `make` and `timeout` use much the same method > >> to control their jobs. I.E. they create their own process group > >> so they can terminate all sub-processes. > > > > Are you sure? I see no evidence of that. When I run make with the above > > makefile, the processes look like this: > > > > PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND > > 1 1451 1451 1451 6 16407 S 1000 0:06 -zsh > > 1451 16407 16407 1451 6 16407 S 1000 0:00 make > > 16407 16408 16408 1451 6 16407 S 1000 0:00 timeout 60 sleep 30 > > 16408 16409 16408 1451 6 16407 S 1000 0:00 sleep 30 > > > > The first PGID is the login shell. The second PGID is make, which was p= ut > > into its own process group by the shell because the shell has job contr= ol > > enabled. The last PGID is timeout, which put itself into a process grou= p. > > make never noticed any of them. > > > > In the source for GNU make 3.82 there are no calls to setpgrp or setpgi= d > > (unless obfuscated from grep). There is the following comment: > > > > /* A termination signal won't be sent to the entire > > process group, but it means we want to kill the children. */ > > > > That's above the handling of SIGTERM, which iterates over child process= es > and > > passes along the SIGTERM to them. > > > > After that is the handling of SIGINT, which doesn't kill child processe= s > > (unless they're "remote", which is... news to me that make does remote > > things) but just waits for them. > > > > What seems to be happening is that make *doesn't* create a process grou= p, > > therefore assumes that when it gets a SIGINT, its children have already > > gotten it too, and it just waits for them to die. A child that puts > itself > > into a new process group screws this up (as would kill -2 `pidof make`)= . > > Thanks for the analysis Alan. > Yes you're right I think. > In any case the important point is that timeout sets itself as group > leader, > and is not the foreground group. > > > > > I think the answer is that timeout should put itself into the foregroun= d. > > That way it would get the SIGINT. make wouldn't get it, but wouldn't ne= ed > to. > > timeout would exit quickly after SIGINT and make would proceed or abort > > according to the exit code. > > I've a version locally here actually that calls tcsetpgrp() but I > discounted > that as it's not timeout's place to call that I think. > timeout sets itself as group leader so that it can kill everything it > starts, > but it shouldn't need to grab the foreground group as the shell (or make) > may be starting it in the background etc. > > So really `make` should not assume children stay in the same group, > and propagate signals down (like it does for TERM). > It might be appropriate for `make` to call tcsetpgrp() before exec..() > but given remote & parallel jobs etc. signal propagation might be best. > > I've fixed up `timeout` itself not assume children stay in > the same group, and pass signals on, in the attached patch. > > cheers, > P=E1draig. > --bcaec50160e3448fdb04a6c9e91b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks for taking care for this! Interesting stuff as well= .


2011/6/28 P=E1draig Brady <P@draigbrady.com>
On 27/06/11 21:12, Alan Curry wrote:
> =3D?UTF-8?Q?P=3DC3=3DA1draig?=3D Brady writes:
>>
>> On 26/06/11 20:20, shay shimony wrote:
>>> all:
>>> =A0 =A0 =A0 =A0 timeout 12 sleep 10
>>>
>>> Note there is a tab before "timeout 12 sleep 10". >>> Then run at same directory where the file is located "mak= e" and try to press
>>> CTRL-C.
>>>
>>> Notes:
>>> CTRL-Z works.
>>> When executing timeout without make CTRL-C works.
>>> When executing make without timeout CTRL-C works.
>>
>> Drats,
>>
>> That because SIGINT is sent by the terminal to the foreground grou= p.
>> The issue is that `make` and `timeout` use much the same method >> to control their jobs. I.E. they create their own process group >> so they can terminate all sub-processes.
>
> Are you sure? I see no evidence of that. When I run make with th= e above
> makefile, the processes look like this:
>
> =A0PPID =A0 PID =A0PGID =A0 SID TTY TPGID =A0STAT =A0UID =A0 TIME COMM= AND
> =A0 =A0 1 =A01451 =A01451 =A01451 =A0 6 16407 =A0S =A0 =A01000 =A0 0:0= 6 -zsh
> =A01451 16407 16407 =A01451 =A0 6 16407 =A0S =A0 =A01000 =A0 0:00 make=
> 16407 16408 16408 =A01451 =A0 6 16407 =A0S =A0 =A01000 =A0 0:00 timeou= t 60 sleep 30
> 16408 16409 16408 =A01451 =A0 6 16407 =A0S =A0 =A01000 =A0 0:00 sleep = 30
>
> The first PGID is the login shell. The second PGID is make, which was = put
> into its own process group by the shell because the shell has job cont= rol
> enabled. The last PGID is timeout, which put itself into a process gro= up.
> make never noticed any of them.
>
> In the source for GNU make 3.82 there are no calls to setpgrp or setpg= id
> (unless obfuscated from grep). There is the following comment:
>
> =A0 /* A termination signal won't be sent to the entire
> =A0 =A0 =A0process group, but it means we want to kill the children. = =A0*/
>
> That's above the handling of SIGTERM, which iterates over child pr= ocesses and
> passes along the SIGTERM to them.
>
> After that is the handling of SIGINT, which doesn't kill child pro= cesses
> (unless they're "remote", which is... news to me that ma= ke does remote
> things) but just waits for them.
>
> What seems to be happening is that make *doesn't* create a process= group,
> therefore assumes that when it gets a SIGINT, its children have alread= y
> gotten it too, and it just waits for them to die. A child that puts it= self
> into a new process group screws this up (as would kill -2 `pidof make`= ).

Thanks for the analysis Alan.
Yes you're right I think.
In any case the important point is that timeout sets itself as group leader= ,
and is not the foreground group.

>
> I think the answer is that timeout should put itself into the foregrou= nd.
> That way it would get the SIGINT. make wouldn't get it, but wouldn= 't need to.
> timeout would exit quickly after SIGINT and make would proceed or abor= t
> according to the exit code.

I've a version locally here actually that calls tcsetpgrp() but I disco= unted
that as it's not timeout's place to call that I think.
timeout sets itself as group leader so that it can kill everything it start= s,
but it shouldn't need to grab the foreground group as the shell (or mak= e)
may be starting it in the background etc.

So really `make` should not assume children stay in the same group,
and propagate signals down (like it does for TERM).
It might be appropriate for `make` to call tcsetpgrp() before exec..()
but given remote & parallel jobs etc. signal propagation might be best.=

I've fixed up `timeout` itself not assume children stay in
the same group, and pass signals on, in the attached patch.

cheers,
P=E1draig.

--bcaec50160e3448fdb04a6c9e91b-- From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 15:10:54 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 19:10:55 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbdgU-0000kH-IH for submit@debbugs.gnu.org; Tue, 28 Jun 2011 15:10:54 -0400 Received: from c-67-162-90-113.hsd1.in.comcast.net ([67.162.90.113] helo=kosh.dhis.org) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbdgT-0000k6-Fg for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 15:10:53 -0400 Received: (qmail 2680 invoked by uid 1000); 28 Jun 2011 19:10:47 -0000 Message-ID: <20110628191047.2679.qmail@kosh.dhis.org> From: "Alan Curry" Subject: Re: bug#8938: make timeout and CTRL-C To: P@draigBrady.com (=?ISO-8859-1?Q?P=E1draig_Brady?=) Date: Tue, 28 Jun 2011 14:10:47 -0500 (GMT+5) In-Reply-To: <4E0A224B.2070705@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Score: -0.8 (/) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.8 (/) =?ISO-8859-1?Q?P=E1draig_Brady?= writes: > > I'm still not convinced we need to be messing with tcsetpgrp() > but you're right in that the disconnect between the timeout > process group and that of whatever starts `timeout` should be bridged. > > I'm testing the attached patch at the moment (which I'll split into 2). > It only creates a separate group for the child that `timeout` execs, > leaving the timeout process in the original group to propagate signals down. > > I'll need to do lots of testing with this before I commit. With this patch the child is guaranteed to not be in the foreground (as far as the tty knows) so it will be getting SIGTTIN and possibly SIGTTOU on tty operations. I don't think there's anything that will make every scenario happy. (Except for a recursive-kill that doesn't use pgrps!). -- Alan Curry From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 16:27:36 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 20:27:36 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbesh-0006G4-Bm for submit@debbugs.gnu.org; Tue, 28 Jun 2011 16:27:35 -0400 Received: from joseki.proulx.com ([216.17.153.58]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbesf-0006Fr-8x for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 16:27:34 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 42E9D21312 for <8938@debbugs.gnu.org>; Tue, 28 Jun 2011 14:27:27 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id EF0102DC6C; Tue, 28 Jun 2011 14:27:26 -0600 (MDT) Date: Tue, 28 Jun 2011 14:27:26 -0600 From: Bob Proulx To: 8938@debbugs.gnu.org Subject: Re: bug#8938: make timeout and CTRL-C Message-ID: <20110628202726.GA18839@hysteria.proulx.com> References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <4E0A206E.70902@draigBrady.com> User-Agent: Mutt/1.5.21 (2010-09-15) Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.4 (--) X-Debbugs-Envelope-To: 8938 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.4 (--) P=E1draig Brady wrote: > Paul Eggert wrote: > > I'd like to have an option to 'timeout' so that > > it merely calls alarm(2) and then execs COMMAND. > > This would be simple and fast would avoid the problem > > in question. This approach has its own issues, but > > when it works it works great, and it'd be a nice option. I agree. It is nice and simple and well understood. > The main problem with that is would only send the signal to the > first process, and any processes it started would keep running. Then that is a problem for that parent process to keep track of its own children. It is a recursive situation. If all processes are well behaved then it works okay. And if you ask about processes that are not well behaved then my response would be to fix them so that they are better behaved. Bob From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 16:32:53 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 20:32:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbexo-00079c-W6 for submit@debbugs.gnu.org; Tue, 28 Jun 2011 16:32:53 -0400 Received: from c-67-162-90-113.hsd1.in.comcast.net ([67.162.90.113] helo=kosh.dhis.org) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qbexn-00079Q-3z for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 16:32:51 -0400 Received: (qmail 3156 invoked by uid 1000); 28 Jun 2011 20:32:45 -0000 Message-ID: <20110628203245.3155.qmail@kosh.dhis.org> From: "Alan Curry" Subject: Re: bug#8938: make timeout and CTRL-C To: bob@proulx.com (Bob Proulx) Date: Tue, 28 Jun 2011 15:32:45 -0500 (GMT+5) In-Reply-To: <20110628202726.GA18839@hysteria.proulx.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Score: -0.8 (/) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.8 (/) Bob Proulx writes: > > P=E1draig Brady wrote: > > Paul Eggert wrote: > > > I'd like to have an option to 'timeout' so that > > > it merely calls alarm(2) and then execs COMMAND. > > > This would be simple and fast would avoid the problem > > > in question. This approach has its own issues, but > > > when it works it works great, and it'd be a nice option. > > I agree. It is nice and simple and well understood. > > > The main problem with that is would only send the signal to the > > first process, and any processes it started would keep running. > > Then that is a problem for that parent process to keep track of its > own children. It is a recursive situation. If all processes are well > behaved then it works okay. And if you ask about processes that are > not well behaved then my response would be to fix them so that they > are better behaved. That sounds reasonable, but then if something is about to be killed by timeout, there's reason to believe it's not behaving well at the moment. -- Alan Curry From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 16:43:06 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 20:43:07 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbf7i-0007PM-7V for submit@debbugs.gnu.org; Tue, 28 Jun 2011 16:43:06 -0400 Received: from joseki.proulx.com ([216.17.153.58]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qbf7g-0007Ot-EL for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 16:43:05 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 94C5421312 for <8938@debbugs.gnu.org>; Tue, 28 Jun 2011 14:42:58 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 71A8E2DC6C; Tue, 28 Jun 2011 14:42:58 -0600 (MDT) Date: Tue, 28 Jun 2011 14:42:58 -0600 From: Bob Proulx To: 8938@debbugs.gnu.org Subject: Re: bug#8938: make timeout and CTRL-C Message-ID: <20110628204258.GA21828@hysteria.proulx.com> References: <20110628203245.3155.qmail@kosh.dhis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110628203245.3155.qmail@kosh.dhis.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: -2.4 (--) X-Debbugs-Envelope-To: 8938 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.4 (--) Alan Curry wrote: > That sounds reasonable, but then if something is about to be killed by > timeout, there's reason to believe it's not behaving well at the moment. Not necessarily. For example many things depend upon something across the network. If the network wire is unplugged then they might never complete and therefore need a timeout. But that doesn't mean that they are not well behaved otherwise. Bob From debbugs-submit-bounces@debbugs.gnu.org Tue Jun 28 17:16:52 2011 Received: (at 8938) by debbugs.gnu.org; 28 Jun 2011 21:16:52 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbfeN-00021Y-Qo for submit@debbugs.gnu.org; Tue, 28 Jun 2011 17:16:52 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbfeK-00021J-Kj for 8938@debbugs.gnu.org; Tue, 28 Jun 2011 17:16:49 -0400 Received: (qmail 63230 invoked from network); 28 Jun 2011 21:16:42 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 28 Jun 2011 21:16:42 -0000 Message-ID: <4E0A4497.8090009@draigBrady.com> Date: Tue, 28 Jun 2011 22:16:07 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Alan Curry Subject: Re: bug#8938: make timeout and CTRL-C References: <20110628203245.3155.qmail@kosh.dhis.org> In-Reply-To: <20110628203245.3155.qmail@kosh.dhis.org> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org, Bob Proulx X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) On 28/06/11 21:32, Alan Curry wrote: > Bob Proulx writes: >> >> P=E1draig Brady wrote: >>> Paul Eggert wrote: >>>> I'd like to have an option to 'timeout' so that >>>> it merely calls alarm(2) and then execs COMMAND. >>>> This would be simple and fast would avoid the problem >>>> in question. This approach has its own issues, but >>>> when it works it works great, and it'd be a nice option. >> >> I agree. It is nice and simple and well understood. >> >>> The main problem with that is would only send the signal to the >>> first process, and any processes it started would keep running. >> >> Then that is a problem for that parent process to keep track of its >> own children. It is a recursive situation. If all processes are well >> behaved then it works okay. And if you ask about processes that are >> not well behaved then my response would be to fix them so that they >> are better behaved. > > That sounds reasonable, but then if something is about to be killed by > timeout, there's reason to believe it's not behaving well at the moment. > Well think of a shell script that has started lots of processes. Many (most) will rely on signal propagation to the group to clean things up. cheers, Pâdraig. From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 29 05:56:13 2011 Received: (at 8938) by debbugs.gnu.org; 29 Jun 2011 09:56:14 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QbrVF-0006Y1-4o for submit@debbugs.gnu.org; Wed, 29 Jun 2011 05:56:13 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QbrVC-0006Xp-Pv for 8938@debbugs.gnu.org; Wed, 29 Jun 2011 05:56:11 -0400 Received: (qmail 4067 invoked from network); 29 Jun 2011 09:56:04 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 29 Jun 2011 09:56:04 -0000 Message-ID: <4E0AF68F.5060705@draigBrady.com> Date: Wed, 29 Jun 2011 10:55:27 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Alan Curry Subject: Re: bug#8938: make timeout and CTRL-C References: <20110628191047.2679.qmail@kosh.dhis.org> In-Reply-To: <20110628191047.2679.qmail@kosh.dhis.org> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) On 28/06/11 20:10, Alan Curry wrote: > =?ISO-8859-1?Q?P=E1draig_Brady?= writes: >> >> I'm still not convinced we need to be messing with tcsetpgrp() >> but you're right in that the disconnect between the timeout >> process group and that of whatever starts `timeout` should be bridged. >> >> I'm testing the attached patch at the moment (which I'll split into 2). >> It only creates a separate group for the child that `timeout` execs, >> leaving the timeout process in the original group to propagate signals down. >> >> I'll need to do lots of testing with this before I commit. > > With this patch the child is guaranteed to not be in the foreground (as far > as the tty knows) so it will be getting SIGTTIN and possibly SIGTTOU on tty > operations. Oh right. This will immediately put dd in sTop state: timeout 10 dd That was one of the main reasons I didn't split the groups in the first place. I should read my own comments :) I'm very wary of changing the foreground group (with tcsetpgrp), which would fix this, but in turn may cause other issues. > I don't think there's anything that will make every scenario happy. (Except > for a recursive-kill that doesn't use pgrps!). Yes, an ideal solution is elusive. Maybe `make` needs to handle things differently? If you put the following in a Makefile, how should make respond to Ctrl-C? all: setsid sleep 10 cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 02 14:37:13 2011 Received: (at 8938) by debbugs.gnu.org; 2 Jul 2011 18:37:13 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qd545-0006Ux-3d for submit@debbugs.gnu.org; Sat, 02 Jul 2011 14:37:13 -0400 Received: from mail-vw0-f44.google.com ([209.85.212.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qd542-0006U7-Km for 8938@debbugs.gnu.org; Sat, 02 Jul 2011 14:37:11 -0400 Received: by vws12 with SMTP id 12so3025419vws.3 for <8938@debbugs.gnu.org>; Sat, 02 Jul 2011 11:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=jzgM+I9jp5IbLqErBkVb8cS1Uqaf9j0KgF2GiPslZdQ=; b=htLhUwMlcguqYHEVtXiZKxB8v8DD0jfyL/rKV5nIb4vdQC7c+vf4SoLCmsbQ0Aqjlc qy32EFKWf15Gq2vFBpvasbv/Q84/0EG8Gm4PUq7v+TzAYndwjpJivE5SNZHbwDQxkRRq TZg0Zu/PRVHn76Yj9AIDniviPuY5mpFgIhnTU= Received: by 10.52.95.148 with SMTP id dk20mr2748343vdb.120.1309631825082; Sat, 02 Jul 2011 11:37:05 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.170.170 with HTTP; Sat, 2 Jul 2011 11:36:45 -0700 (PDT) From: shay shimony Date: Sat, 2 Jul 2011 21:36:45 +0300 Message-ID: Subject: Re: bug#8938: make timeout and CTRL-C To: P@draigbrady.com, pacman-cu@kosh.dhis.org, 8938@debbugs.gnu.org Content-Type: multipart/alternative; boundary=20cf307f374cb877df04a71a6b6a X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 8938 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.1 (----) --20cf307f374cb877df04a71a6b6a Content-Type: text/plain; charset=ISO-8859-1 > With this patch the child is guaranteed to not be in the foreground (as far > as the tty knows) so it will be getting SIGTTIN and possibly SIGTTOU on tty > operations. You may need to correct me. In practice we see that the "timeouted" program perform successfully writes to the terminal, though it belongs to a different group then the foreground (in my case "make"'s group is in the foreground and timeout+compiler/test group is in the background, and all output of the compiler and test seem to appear correctly on the terminal). And regarding read, I think it makes sense enough that users will not use timeout for interactive programs that wait for input from the user. So maybe the fact that the timeouted program will not be able to get SIGTTIN and SIGTTOU is not such a disaster? --20cf307f374cb877df04a71a6b6a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
> With this patch the child is guaranteed to not b=
e in the foreground (as far
> as the tty knows) so it will be getting SIGTTIN and possibly SIGTTOU o=
n tty
> operations.
You may need to correct me. In practice we see that t= he "timeouted" program perform successfully writes to the termina= l, though it belongs to a different group then the foreground (in my case &= quot;make"'s group is in the foreground and timeout+compiler/test = group is in the background, and all output of the compiler and test seem to= appear correctly on the terminal). And regarding read, I think it makes se= nse enough that users will not use timeout for interactive programs that wa= it for input from the user.
So maybe the fact that the timeouted program will not be able to get SIGTTI= N and SIGTTOU is not such a disaster?


--20cf307f374cb877df04a71a6b6a-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 02 16:14:55 2011 Received: (at 8938) by debbugs.gnu.org; 2 Jul 2011 20:14:55 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qd6ad-0000CI-3J for submit@debbugs.gnu.org; Sat, 02 Jul 2011 16:14:55 -0400 Received: from c-67-162-90-113.hsd1.in.comcast.net ([67.162.90.113] helo=kosh.dhis.org) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qd6aa-0000C2-Ev for 8938@debbugs.gnu.org; Sat, 02 Jul 2011 16:14:53 -0400 Received: (qmail 23306 invoked by uid 1000); 2 Jul 2011 20:14:46 -0000 Message-ID: <20110702201446.23305.qmail@kosh.dhis.org> From: "Alan Curry" Subject: Re: bug#8938: make timeout and CTRL-C To: shayshim@gmail.com (shay shimony) Date: Sat, 2 Jul 2011 15:14:46 -0500 (GMT+5) In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Score: -0.8 (/) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.8 (/) shay shimony writes: > > > With this patch the child is guaranteed to not be in the foreground (as far > > as the tty knows) so it will be getting SIGTTIN and possibly SIGTTOU on tty > > operations. > > You may need to correct me. In practice we see that the "timeouted" program > perform successfully writes to the terminal, though it belongs to a > different group then the foreground (in my case "make"'s group is in the > foreground and timeout+compiler/test group is in the background, and all > output of the compiler and test seem to appear correctly on the terminal). > And regarding read, I think it makes sense enough that users will not use > timeout for interactive programs that wait for input from the user. > So maybe the fact that the timeouted program will not be able to get SIGTTIN > and SIGTTOU is not such a disaster? > Notice that I wrote "possibly" before SIGTTOU. There was a reason for that. A background process that writes to the tty will get SIGTTOU if "stty tostop" is in effect. This is a user preference thing. You can set it if you get annoyed by processes writing to the terminal after you backgrounded them expecting them to be quiet. It's not enabled by default. If the process ignores SIGTTOU, the write will proceed, overriding the user's expressed preference. SIGTTIN is more forceful. There's no stty flag to turn it off, and ignoring it results in EIO. Keyboard input always belongs exclusively to the foreground job. For completeness I'll also mention that SIGTTOU will also be sent to a background process that attempts to change the tty settings, even if tostop is not enabled. -- Alan Curry From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 02 17:11:40 2011 Received: (at 8938) by debbugs.gnu.org; 2 Jul 2011 21:11:40 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qd7TY-0001Xk-HB for submit@debbugs.gnu.org; Sat, 02 Jul 2011 17:11:40 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qd7TW-0001XY-96 for 8938@debbugs.gnu.org; Sat, 02 Jul 2011 17:11:39 -0400 Received: (qmail 78646 invoked from network); 2 Jul 2011 21:11:32 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 2 Jul 2011 21:11:32 -0000 Message-ID: <4E0F894E.5060706@draigBrady.com> Date: Sat, 02 Jul 2011 22:10:38 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: shay shimony Subject: Re: bug#8938: make timeout and CTRL-C References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 Cc: pacman-cu@kosh.dhis.org, 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 02/07/11 19:36, shay shimony wrote: >> With this patch the child is guaranteed to not be in the foreground (as far >> as the tty knows) so it will be getting SIGTTIN and possibly SIGTTOU on tty >> operations. > > You may need to correct me. In practice we see that the "timeouted" > program perform successfully writes to the terminal, though it belongs > to a different group then the foreground (in my case "make"'s group is > in the foreground and timeout+compiler/test group is in the background, > and all output of the compiler and test seem to appear correctly on the > terminal). And regarding read, I think it makes sense enough that users > will not use timeout for interactive programs that wait for input from > the user. > So maybe the fact that the timeouted program will not be able to get > SIGTTIN and SIGTTOU is not such a disaster? Whether output in a background group triggers SIGTTOU is configurable. Also, in general a long running job might need input from the terminal at the start. So I think it would be too restrictive to disallow programs that read from tty from being timed out. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 02 17:25:25 2011 Received: (at 8938) by debbugs.gnu.org; 2 Jul 2011 21:25:25 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qd7gr-0002hy-8N for submit@debbugs.gnu.org; Sat, 02 Jul 2011 17:25:25 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qd7gp-0002hl-1j for 8938@debbugs.gnu.org; Sat, 02 Jul 2011 17:25:23 -0400 Received: (qmail 80420 invoked from network); 2 Jul 2011 21:25:17 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 2 Jul 2011 21:25:17 -0000 Message-ID: <4E0F8C86.7040506@draigBrady.com> Date: Sat, 02 Jul 2011 22:24:22 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Alan Curry Subject: Re: bug#8938: make timeout and CTRL-C References: <20110628191047.2679.qmail@kosh.dhis.org> <4E0AF68F.5060705@draigBrady.com> In-Reply-To: <4E0AF68F.5060705@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 Cc: bug-make@gnu.org, 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 29/06/11 10:55, Pádraig Brady wrote: > On 28/06/11 20:10, Alan Curry wrote: >> =?ISO-8859-1?Q?P=E1draig_Brady?= writes: >>> >>> I'm still not convinced we need to be messing with tcsetpgrp() >>> but you're right in that the disconnect between the timeout >>> process group and that of whatever starts `timeout` should be bridged. >>> >>> I'm testing the attached patch at the moment (which I'll split into 2). >>> It only creates a separate group for the child that `timeout` execs, >>> leaving the timeout process in the original group to propagate signals down. >>> >>> I'll need to do lots of testing with this before I commit. >> >> With this patch the child is guaranteed to not be in the foreground (as far >> as the tty knows) so it will be getting SIGTTIN and possibly SIGTTOU on tty >> operations. > > Oh right. This will immediately put dd in sTop state: > timeout 10 dd > That was one of the main reasons I didn't split the groups > in the first place. I should read my own comments :) > I'm very wary of changing the foreground group (with tcsetpgrp), > which would fix this, but in turn may cause other issues. > >> I don't think there's anything that will make every scenario happy. (Except >> for a recursive-kill that doesn't use pgrps!). > > Yes, an ideal solution is elusive. > Maybe `make` needs to handle things differently? > If you put the following in a Makefile, how should make respond to Ctrl-C? > > all: > setsid sleep 10 I've been doing a quick test here with a version of timeout that calls tcsetpgrp() in the child background group, and it works for these cases. However I still don't think we should be grabbing the foreground group, and instead this responsibility should be passed down? Given the above setsid make example (which hangs for 10s ignoring Ctrl-C, I'm leaning towards `make` needing to be more shell like, or at least forward the SIGINT etc. to the job, and not assume jobs run in the foreground group). There is also the suggestion from Paul Eggert, to add an option to timeout, so that it doesn't create a separate group, and so only times out the exec'd process and nothing beneath that. We might call this --single (process/group). cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 02 17:38:53 2011 Received: (at 8938) by debbugs.gnu.org; 2 Jul 2011 21:38:53 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qd7tt-00030m-13 for submit@debbugs.gnu.org; Sat, 02 Jul 2011 17:38:53 -0400 Received: from c-67-162-90-113.hsd1.in.comcast.net ([67.162.90.113] helo=kosh.dhis.org) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qd7tr-00030Y-L8 for 8938@debbugs.gnu.org; Sat, 02 Jul 2011 17:38:52 -0400 Received: (qmail 23785 invoked by uid 1000); 2 Jul 2011 21:38:46 -0000 Message-ID: <20110702213846.23784.qmail@kosh.dhis.org> From: "Alan Curry" Subject: Re: bug#8938: make timeout and CTRL-C To: P@draigBrady.com (=?ISO-8859-1?Q?P=E1draig_Brady?=) Date: Sat, 2 Jul 2011 16:38:46 -0500 (GMT+5) In-Reply-To: <4E0F8C86.7040506@draigBrady.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Score: -0.8 (/) X-Debbugs-Envelope-To: 8938 Cc: bug-make@gnu.org, 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.8 (/) =?ISO-8859-1?Q?P=E1draig_Brady?= writes: > > Given the above setsid make example (which hangs for 10s > ignoring Ctrl-C, I'm leaning towards `make` needing to > be more shell like, or at least forward the SIGINT etc. > to the job, and not assume jobs run in the foreground group). I'm a little worried that you're focusing too much on make, which is just one way to demonstrate the problems of process group abuse. This simple shell script: #!/bin/sh timeout 12 sleep 10 is also nonresponsive to ^C for the same reason as the original makefile. Are you going to argue that the shell is doing something wrong there too? -- Alan Curry From debbugs-submit-bounces@debbugs.gnu.org Sat Jul 02 19:39:12 2011 Received: (at 8938) by debbugs.gnu.org; 2 Jul 2011 23:39:12 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qd9mK-0000cx-Av for submit@debbugs.gnu.org; Sat, 02 Jul 2011 19:39:12 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qd9mI-0000cl-7S for 8938@debbugs.gnu.org; Sat, 02 Jul 2011 19:39:11 -0400 Received: (qmail 96904 invoked from network); 2 Jul 2011 23:39:04 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 2 Jul 2011 23:39:04 -0000 Message-ID: <4E0FABE2.7070907@draigBrady.com> Date: Sun, 03 Jul 2011 00:38:10 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Alan Curry Subject: Re: bug#8938: make timeout and CTRL-C References: <20110702213846.23784.qmail@kosh.dhis.org> In-Reply-To: <20110702213846.23784.qmail@kosh.dhis.org> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 Cc: bug-make@gnu.org, 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 02/07/11 22:38, Alan Curry wrote: > =?ISO-8859-1?Q?P=E1draig_Brady?= writes: >> >> Given the above setsid make example (which hangs for 10s >> ignoring Ctrl-C, I'm leaning towards `make` needing to >> be more shell like, or at least forward the SIGINT etc. >> to the job, and not assume jobs run in the foreground group). > > I'm a little worried that you're focusing too much on make, which is just one > way to demonstrate the problems of process group abuse. > > This simple shell script: > > #!/bin/sh > timeout 12 sleep 10 > > is also nonresponsive to ^C for the same reason as the original makefile. > > Are you going to argue that the shell is doing something wrong there too? Oh good point. The shell script above becomes the foreground group, rather than the timeout command as is the case when started directly. I guess there are good reasons for the shell not to propagate signals down to its children. So we're left with Paul's "--single" option to support this, with the tradeoff that it only signals the child but nothing below that. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 06 18:38:42 2011 Received: (at 8938) by debbugs.gnu.org; 6 Jul 2011 22:38:42 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qeajx-0008Kp-Vz for submit@debbugs.gnu.org; Wed, 06 Jul 2011 18:38:42 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qeaju-0008Kc-Qq for 8938@debbugs.gnu.org; Wed, 06 Jul 2011 18:38:40 -0400 Received: (qmail 19680 invoked from network); 6 Jul 2011 22:38:31 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 6 Jul 2011 22:38:31 -0000 Message-ID: <4E14E39E.6070207@draigBrady.com> Date: Wed, 06 Jul 2011 23:37:18 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> <4E0A214B.4060607@cs.ucla.edu> In-Reply-To: <4E0A214B.4060607@cs.ucla.edu> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------030308060502090108000604" X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) This is a multi-part message in MIME format. --------------030308060502090108000604 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 28/06/11 19:45, Paul Eggert wrote: > On 06/28/11 11:41, Pádraig Brady wrote: >> The main problem with that is would only >> send the signal to the first process, and >> any processes it started would keep running. > > Yes, that's the main issue with it. Still, > it's handy for programs where you either know > it doesn't use subprocesses, or you *want* to > kill just the main program and not its subprocesses. > > I don't think it should be the default option, > but it'd be nice to have it as an option. OK I've added --foreground to support this. Note it still maintains a separate timeout monitor process to return 124 on timeout etc. cheers, Pádraig. --------------030308060502090108000604 Content-Type: text/x-patch; name="timeout--foreground.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="timeout--foreground.diff" >From 035ecef5820cc774b287ea3243da2cace2531514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Wed, 6 Jul 2011 23:17:10 +0100 Subject: [PATCH] timeout: add --foreground to timeout interactive commands Or more accurately, commands not started from the shell prompt, that are interactive, or need to receive Ctrl-C etc. from the terminal. * doc/coreutils.texi (timeout invocation): Document --foreground * src/timeout.c (main): Set the foreground flag and don't create a separate group. (cleanup): Only send a signal directly to the monitored command if foreground flag is set. (usage): Describe --foreground. Analysis of the issue by Alan Curry. Idea to resolve this from Paul Eggert. --- doc/coreutils.texi | 17 +++++++++++++++++ src/timeout.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/doc/coreutils.texi b/doc/coreutils.texi index c59af2f..e04806d 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -15651,6 +15651,23 @@ The program accepts the following options. Also see @ref{Common options}. Options must precede operands. @table @samp +@itemx --foreground +@opindex --foreground +Don't create a separate background program group, so that +the managed @var{COMMAND} can use the foreground TTY normally. +This is needed to support timing out commands not started +directly from an interactive shell, in two situations. +@enumerate +@item +@var{command} is interactive and needs to read from the terminal for example +@item +the user wants to support sending signals directly to @var{command} +from the terminal (like Ctrl-C for example) +@end enumerate + +Note in this mode of operation, any children of @var{command} +will not be timed out. + @item -k @var{duration} @itemx --kill-after=@var{duration} @opindex -k diff --git a/src/timeout.c b/src/timeout.c index a686225..5dc5f85 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -67,11 +67,19 @@ static int term_signal = SIGTERM; /* same default as kill command. */ static int monitored_pid; static int sigs_to_ignore[NSIG]; /* so monitor can ignore sigs it resends. */ static unsigned long kill_after; +static bool foreground; /* whether to use another program group. */ + +/* for long options with no corresponding short option, use enum */ +enum +{ + FOREGROUND_OPTION = CHAR_MAX + 1 +}; static struct option const long_options[] = { {"kill-after", required_argument, NULL, 'k'}, {"signal", required_argument, NULL, 's'}, + {"foreground", no_argument, NULL, FOREGROUND_OPTION}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} @@ -96,6 +104,8 @@ cleanup (int sig) } if (monitored_pid) { + int where = foreground ? monitored_pid : 0; + if (sigs_to_ignore[sig]) { sigs_to_ignore[sig] = 0; @@ -108,9 +118,10 @@ cleanup (int sig) alarm (kill_after); kill_after = 0; /* Don't let later signals reset kill alarm. */ } - send_sig (0, sig); + + send_sig (where, sig); if (sig != SIGKILL && sig != SIGCONT) - send_sig (0, SIGCONT); + send_sig (where, SIGCONT); } else /* we're the child or the child is not exec'd yet. */ _exit (128 + sig); @@ -134,13 +145,17 @@ Start COMMAND, and kill it if still running after DURATION.\n\ Mandatory arguments to long options are mandatory for short options too.\n\ "), stdout); fputs (_("\ + --foreground\n\ + Don't create a separate background program group, so that\n\ + the managed COMMAND can use the foreground TTY normally.\n\ + Note this will not timeout any children of COMMAND.\n\ -k, --kill-after=DURATION\n\ - also send a KILL signal if COMMAND is still running\n\ - this long after the initial signal was sent.\n\ + also send a KILL signal if COMMAND is still running\n\ + this long after the initial signal was sent.\n\ -s, --signal=SIGNAL\n\ - specify the signal to be sent on timeout.\n\ - SIGNAL may be a name like `HUP' or a number.\n\ - See `kill -l` for a list of signals\n"), stdout); + specify the signal to be sent on timeout.\n\ + SIGNAL may be a name like `HUP' or a number.\n\ + See `kill -l` for a list of signals\n"), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); @@ -266,6 +281,10 @@ main (int argc, char **argv) usage (EXIT_CANCELED); break; + case FOREGROUND_OPTION: + foreground = true; + break; + case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); @@ -287,7 +306,8 @@ main (int argc, char **argv) Note we don't just put the child in a separate group as then we would need to worry about foreground and background groups and propagating signals between them. */ - setpgid (0, 0); + if (!foreground) + setpgid (0, 0); /* Setup handlers before fork() so that we handle any signals caused by child, without races. */ -- 1.7.5.2 --------------030308060502090108000604-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 07 06:06:47 2011 Received: (at 8938) by debbugs.gnu.org; 7 Jul 2011 10:06:47 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QelTq-00074X-MU for submit@debbugs.gnu.org; Thu, 07 Jul 2011 06:06:47 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QelTo-00074J-0p for 8938@debbugs.gnu.org; Thu, 07 Jul 2011 06:06:45 -0400 Received: (qmail 14604 invoked from network); 7 Jul 2011 10:06:37 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 7 Jul 2011 10:06:37 -0000 Message-ID: <4E1584E1.6010008@draigBrady.com> Date: Thu, 07 Jul 2011 11:05:21 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> <4E0A214B.4060607@cs.ucla.edu> <4E14E39E.6070207@draigBrady.com> In-Reply-To: <4E14E39E.6070207@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------060908030305030005090107" X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) This is a multi-part message in MIME format. --------------060908030305030005090107 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 06/07/11 23:37, Pádraig Brady wrote: > OK I've added --foreground to support this. > Note it still maintains a separate timeout > monitor process to return 124 on timeout etc. Updated wording and NEWS entry now included. I'll push this later today. cheers, Pádraig. --------------060908030305030005090107 Content-Type: text/x-patch; name="timeout--foreground.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="timeout--foreground.diff" >From b7326b5b54cfa44a022ec5e894a36985bf764525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Wed, 6 Jul 2011 23:17:10 +0100 Subject: [PATCH] timeout: add --foreground to support interactive commands Or more accurately, commands not started from the shell prompt, that are interactive, or need to receive Ctrl-C etc. from the terminal. * doc/coreutils.texi (timeout invocation): Document --foreground. * src/timeout.c (main): Set the foreground flag and don't create a separate group. (cleanup): Only send a signal directly to the monitored command when the foreground flag is set. (usage): Describe --foreground. NEWS: Mention the new option. Reported by Shay Shimony Analysis by Alan Curry Fix suggested by Paul Eggert --- NEWS | 4 ++++ doc/coreutils.texi | 17 +++++++++++++++++ src/timeout.c | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index d58df26..cde68d3 100644 --- a/NEWS +++ b/NEWS @@ -29,6 +29,10 @@ GNU coreutils NEWS -*- outline -*- Note the use of single quotes, not double quotes. That creates files named xaa.xz, xab.xz and xac.xz. + timeout accepts a new --foreground option, to support commands not started + directly from a shell prompt, where the command is interactive or needs to + receive signals initiated from the terminal. + ** Improvements shuf outputs small subsets of large permutations much more efficiently. diff --git a/doc/coreutils.texi b/doc/coreutils.texi index c59af2f..e04806d 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -15651,6 +15651,23 @@ The program accepts the following options. Also see @ref{Common options}. Options must precede operands. @table @samp +@itemx --foreground +@opindex --foreground +Don't create a separate background program group, so that +the managed @var{COMMAND} can use the foreground TTY normally. +This is needed to support timing out commands not started +directly from an interactive shell, in two situations. +@enumerate +@item +@var{command} is interactive and needs to read from the terminal for example +@item +the user wants to support sending signals directly to @var{command} +from the terminal (like Ctrl-C for example) +@end enumerate + +Note in this mode of operation, any children of @var{command} +will not be timed out. + @item -k @var{duration} @itemx --kill-after=@var{duration} @opindex -k diff --git a/src/timeout.c b/src/timeout.c index a686225..8f0980b 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -67,11 +67,19 @@ static int term_signal = SIGTERM; /* same default as kill command. */ static int monitored_pid; static int sigs_to_ignore[NSIG]; /* so monitor can ignore sigs it resends. */ static unsigned long kill_after; +static bool foreground; /* whether to use another program group. */ + +/* for long options with no corresponding short option, use enum */ +enum +{ + FOREGROUND_OPTION = CHAR_MAX + 1 +}; static struct option const long_options[] = { {"kill-after", required_argument, NULL, 'k'}, {"signal", required_argument, NULL, 's'}, + {"foreground", no_argument, NULL, FOREGROUND_OPTION}, {GETOPT_HELP_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL}, {NULL, 0, NULL, 0} @@ -96,6 +104,8 @@ cleanup (int sig) } if (monitored_pid) { + int where = foreground ? monitored_pid : 0; + if (sigs_to_ignore[sig]) { sigs_to_ignore[sig] = 0; @@ -108,9 +118,10 @@ cleanup (int sig) alarm (kill_after); kill_after = 0; /* Don't let later signals reset kill alarm. */ } - send_sig (0, sig); + + send_sig (where, sig); if (sig != SIGKILL && sig != SIGCONT) - send_sig (0, SIGCONT); + send_sig (where, SIGCONT); } else /* we're the child or the child is not exec'd yet. */ _exit (128 + sig); @@ -134,13 +145,17 @@ Start COMMAND, and kill it if still running after DURATION.\n\ Mandatory arguments to long options are mandatory for short options too.\n\ "), stdout); fputs (_("\ + --foreground\n\ + When not running timeout directly from a shell prompt,\n\ + allow COMMAND to read from the TTY and receive TTY signals.\n\ + In this mode, children of COMMAND will not be timed out.\n\ -k, --kill-after=DURATION\n\ - also send a KILL signal if COMMAND is still running\n\ - this long after the initial signal was sent.\n\ + also send a KILL signal if COMMAND is still running\n\ + this long after the initial signal was sent.\n\ -s, --signal=SIGNAL\n\ - specify the signal to be sent on timeout.\n\ - SIGNAL may be a name like `HUP' or a number.\n\ - See `kill -l` for a list of signals\n"), stdout); + specify the signal to be sent on timeout.\n\ + SIGNAL may be a name like `HUP' or a number.\n\ + See `kill -l` for a list of signals\n"), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); @@ -266,6 +281,10 @@ main (int argc, char **argv) usage (EXIT_CANCELED); break; + case FOREGROUND_OPTION: + foreground = true; + break; + case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); @@ -287,7 +306,8 @@ main (int argc, char **argv) Note we don't just put the child in a separate group as then we would need to worry about foreground and background groups and propagating signals between them. */ - setpgid (0, 0); + if (!foreground) + setpgid (0, 0); /* Setup handlers before fork() so that we handle any signals caused by child, without races. */ -- 1.7.5.2 --------------060908030305030005090107-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 07 06:15:37 2011 Received: (at 8938) by debbugs.gnu.org; 7 Jul 2011 10:15:38 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QelcP-0007Gi-53 for submit@debbugs.gnu.org; Thu, 07 Jul 2011 06:15:37 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QelcM-0007GW-U5 for 8938@debbugs.gnu.org; Thu, 07 Jul 2011 06:15:36 -0400 Received: (qmail 16447 invoked from network); 7 Jul 2011 10:15:28 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 7 Jul 2011 10:15:28 -0000 Message-ID: <4E1586F4.3070304@draigBrady.com> Date: Thu, 07 Jul 2011 11:14:12 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: 8938@debbugs.gnu.org Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> <4E0A214B.4060607@cs.ucla.edu> <4E14E39E.6070207@draigBrady.com> <4E1584E1.6010008@draigBrady.com> In-Reply-To: <4E1584E1.6010008@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 07/07/11 11:05, Pádraig Brady wrote: > On 06/07/11 23:37, Pádraig Brady wrote: >> OK I've added --foreground to support this. >> Note it still maintains a separate timeout >> monitor process to return 124 on timeout etc. > > Updated wording and NEWS entry now included. > I'll push this later today. I'm also thinking of pushing this as a separate patch, which will set WIFSIGNALED for the timeout process itself. This will make timeout more transparent and when doing Ctrl-C from make for example, printing "[target] Interrupt" rather than "[target] Error 130". diff --git a/src/timeout.c b/src/timeout.c index a686225..ea4af18 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -341,7 +361,19 @@ main (int argc, char **argv) if (WIFEXITED (status)) status = WEXITSTATUS (status); else if (WIFSIGNALED (status)) - status = WTERMSIG (status) + 128; /* what sh does at least. */ + { + int sig = WTERMSIG (status); + if (!timed_out) + { + /* exit with the signal flag set, but avoid core files. */ + if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0,0}) == 0) + { + signal (sig, SIG_DFL); + raise (sig); + } + } + status = sig + 128; /* what sh returns for signaled processes. */ + } From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 07 06:55:19 2011 Received: (at 8938) by debbugs.gnu.org; 7 Jul 2011 10:55:19 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QemEp-0008Ed-33 for submit@debbugs.gnu.org; Thu, 07 Jul 2011 06:55:19 -0400 Received: from mx.meyering.net ([82.230.74.64]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QemEm-0008ER-HM for 8938@debbugs.gnu.org; Thu, 07 Jul 2011 06:55:17 -0400 Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id E446460110; Thu, 7 Jul 2011 12:55:10 +0200 (CEST) From: Jim Meyering To: =?iso-8859-1?Q?P=E1draig?= Brady Subject: Re: bug#8938: make timeout and CTRL-C In-Reply-To: <4E1584E1.6010008@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?= =?iso-8859-1?Q?g?= Brady"'s message of "Thu, 07 Jul 2011 11:05:21 +0100") References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> <4E0A214B.4060607@cs.ucla.edu> <4E14E39E.6070207@draigBrady.com> <4E1584E1.6010008@draigBrady.com> Date: Thu, 07 Jul 2011 12:55:10 +0200 Message-ID: <87mxgqs6lt.fsf@rho.meyering.net> Lines: 64 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -6.1 (------) X-Debbugs-Envelope-To: 8938 Cc: Paul Eggert , 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.1 (------) P=E1draig Brady wrote: > On 06/07/11 23:37, P=E1draig Brady wrote: >> OK I've added --foreground to support this. >> Note it still maintains a separate timeout >> monitor process to return 124 on timeout etc. > > Updated wording and NEWS entry now included. > I'll push this later today. Thanks! This looks good. > Subject: [PATCH] timeout: add --foreground to support interactive commands ... > diff --git a/doc/coreutils.texi b/doc/coreutils.texi > index c59af2f..e04806d 100644 > --- a/doc/coreutils.texi > +++ b/doc/coreutils.texi > @@ -15651,6 +15651,23 @@ The program accepts the following options. Also= see @ref{Common options}. > Options must precede operands. > > @table @samp > +@itemx --foreground > +@opindex --foreground > +Don't create a separate background program group, so that > +the managed @var{COMMAND} can use the foreground TTY normally. "make check" dings that: ./coreutils.texi:15659:the managed @var{COMMAND} can use the foreground TTY= normally. doc/Makefile: do not use upper case in @var{...} make[2]: *** [sc-lower-case-var] Error 1 You probably have a test case, but just forgot to include it. This is subtle enough that it deserves one, if it's not too much work. > +This is needed to support timing out commands not started > +directly from an interactive shell, in two situations. > +@enumerate > +@item > +@var{command} is interactive and needs to read from the terminal for exa= mple > +@item > +the user wants to support sending signals directly to @var{command} > +from the terminal (like Ctrl-C for example) > +@end enumerate > + > +Note in this mode of operation, any children of @var{command} > +will not be timed out. > + > @item -k @var{duration} > @itemx --kill-after=3D@var{duration} > @opindex -k > diff --git a/src/timeout.c b/src/timeout.c > index a686225..8f0980b 100644 > --- a/src/timeout.c > +++ b/src/timeout.c > @@ -67,11 +67,19 @@ static int term_signal =3D SIGTERM; /* same default = as kill command. */ > static int monitored_pid; > static int sigs_to_ignore[NSIG]; /* so monitor can ignore sigs it rese= nds. */ > static unsigned long kill_after; > +static bool foreground; /* whether to use another program gro= up. */ The comment is worth more if it says e.g., /* If true, don't create a separate process group. */ From debbugs-submit-bounces@debbugs.gnu.org Thu Jul 07 07:14:00 2011 Received: (at 8938) by debbugs.gnu.org; 7 Jul 2011 11:14:00 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QemWu-0000D7-J6 for submit@debbugs.gnu.org; Thu, 07 Jul 2011 07:14:00 -0400 Received: from mx.meyering.net ([82.230.74.64]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QemWs-0000Cu-Vt for 8938@debbugs.gnu.org; Thu, 07 Jul 2011 07:14:00 -0400 Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id 6F3E3600BD; Thu, 7 Jul 2011 13:13:52 +0200 (CEST) From: Jim Meyering To: =?iso-8859-1?Q?P=E1draig?= Brady Subject: Re: bug#8938: make timeout and CTRL-C In-Reply-To: <4E1586F4.3070304@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?= =?iso-8859-1?Q?g?= Brady"'s message of "Thu, 07 Jul 2011 11:14:12 +0100") References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> <4E0A214B.4060607@cs.ucla.edu> <4E14E39E.6070207@draigBrady.com> <4E1584E1.6010008@draigBrady.com> <4E1586F4.3070304@draigBrady.com> Date: Thu, 07 Jul 2011 13:13:52 +0200 Message-ID: <87k4bus5qn.fsf@rho.meyering.net> Lines: 51 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -6.1 (------) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.1 (------) P=E1draig Brady wrote: > On 07/07/11 11:05, P=E1draig Brady wrote: >> On 06/07/11 23:37, P=E1draig Brady wrote: >>> OK I've added --foreground to support this. >>> Note it still maintains a separate timeout >>> monitor process to return 124 on timeout etc. >> >> Updated wording and NEWS entry now included. >> I'll push this later today. > > I'm also thinking of pushing this as a separate patch, > which will set WIFSIGNALED for the timeout process itself. > This will make timeout more transparent and when doing > Ctrl-C from make for example, printing "[target] Interrupt" > rather than "[target] Error 130". > > diff --git a/src/timeout.c b/src/timeout.c > index a686225..ea4af18 100644 > --- a/src/timeout.c > +++ b/src/timeout.c > @@ -341,7 +361,19 @@ main (int argc, char **argv) > if (WIFEXITED (status)) > status =3D WEXITSTATUS (status); > else if (WIFSIGNALED (status)) > - status =3D WTERMSIG (status) + 128; /* what sh does at least= . */ > + { > + int sig =3D WTERMSIG (status); > + if (!timed_out) > + { > + /* exit with the signal flag set, but avoid core files= . */ > + if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0,0}) = =3D=3D 0) > + { > + signal (sig, SIG_DFL); > + raise (sig); > + } > + } > + status =3D sig + 128; /* what sh returns for signaled proc= esses. */ I like the idea. Note that setrlimit is not available on mingw or Beos, according to gnulib's doc/posix-functions/setrlimit.texi, so you might want to test for its existence. Otherwise, this change would induce link failure on those systems. At first I was worried that this improvement would be dependent on setrlimit success, but it appears that it cannot fail for the arguments used here. I wonder if it's better to assert that non-failure -- or maybe just issue a warning, so that if it happens we'll be more likely to get a bug report about it, rather than have users endure a subtle difference in behavior. From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 08 06:51:03 2011 Received: (at 8938) by debbugs.gnu.org; 8 Jul 2011 10:51:03 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qf8eE-0002IM-P5 for submit@debbugs.gnu.org; Fri, 08 Jul 2011 06:51:02 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qf8eB-0002Hr-V6 for 8938@debbugs.gnu.org; Fri, 08 Jul 2011 06:51:00 -0400 Received: (qmail 58647 invoked from network); 8 Jul 2011 10:50:54 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 8 Jul 2011 10:50:54 -0000 Message-ID: <4E16E0BD.8060702@draigBrady.com> Date: Fri, 08 Jul 2011 11:49:33 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Jim Meyering Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> <4E0A214B.4060607@cs.ucla.edu> <4E14E39E.6070207@draigBrady.com> <4E1584E1.6010008@draigBrady.com> <87mxgqs6lt.fsf@rho.meyering.net> In-Reply-To: <87mxgqs6lt.fsf@rho.meyering.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 Cc: Paul Eggert , 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 07/07/11 11:55, Jim Meyering wrote: > You probably have a test case, but just forgot to include it. > This is subtle enough that it deserves one, if it's not too much work. The test is a bit awkward, but worth adding. Applying now... cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 08 06:56:04 2011 Received: (at 8938) by debbugs.gnu.org; 8 Jul 2011 10:56:04 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qf8j6-0002Q4-4P for submit@debbugs.gnu.org; Fri, 08 Jul 2011 06:56:04 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Qf8j4-0002Pb-Ah for 8938@debbugs.gnu.org; Fri, 08 Jul 2011 06:56:02 -0400 Received: (qmail 59762 invoked from network); 8 Jul 2011 10:55:55 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 8 Jul 2011 10:55:55 -0000 Message-ID: <4E16E1EA.2070308@draigBrady.com> Date: Fri, 08 Jul 2011 11:54:34 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Jim Meyering Subject: Re: bug#8938: make timeout and CTRL-C References: <4E087174.9020402@draigBrady.com> <4E0A1B2C.7060004@cs.ucla.edu> <4E0A206E.70902@draigBrady.com> <4E0A214B.4060607@cs.ucla.edu> <4E14E39E.6070207@draigBrady.com> <4E1584E1.6010008@draigBrady.com> <4E1586F4.3070304@draigBrady.com> <87k4bus5qn.fsf@rho.meyering.net> In-Reply-To: <87k4bus5qn.fsf@rho.meyering.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: 8938 Cc: 8938@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) On 07/07/11 12:13, Jim Meyering wrote: > Pádraig Brady wrote: > >> On 07/07/11 11:05, Pádraig Brady wrote: >>> On 06/07/11 23:37, Pádraig Brady wrote: >>>> OK I've added --foreground to support this. >>>> Note it still maintains a separate timeout >>>> monitor process to return 124 on timeout etc. >>> >>> Updated wording and NEWS entry now included. >>> I'll push this later today. >> >> I'm also thinking of pushing this as a separate patch, >> which will set WIFSIGNALED for the timeout process itself. >> This will make timeout more transparent and when doing >> Ctrl-C from make for example, printing "[target] Interrupt" >> rather than "[target] Error 130". >> >> diff --git a/src/timeout.c b/src/timeout.c >> index a686225..ea4af18 100644 >> --- a/src/timeout.c >> +++ b/src/timeout.c >> @@ -341,7 +361,19 @@ main (int argc, char **argv) >> if (WIFEXITED (status)) >> status = WEXITSTATUS (status); >> else if (WIFSIGNALED (status)) >> - status = WTERMSIG (status) + 128; /* what sh does at least. */ >> + { >> + int sig = WTERMSIG (status); >> + if (!timed_out) >> + { >> + /* exit with the signal flag set, but avoid core files. */ >> + if (setrlimit (RLIMIT_CORE, &(struct rlimit) {0,0}) == 0) >> + { >> + signal (sig, SIG_DFL); >> + raise (sig); >> + } >> + } >> + status = sig + 128; /* what sh returns for signaled processes. */ > > I like the idea. > Note that setrlimit is not available on mingw or Beos, according to > gnulib's doc/posix-functions/setrlimit.texi, so you might want to test > for its existence. Otherwise, this change would induce link failure on > those systems. Good catch. I'll wrap in #if HAVE_SETRLIMIT && defined RLIMIT_CORE #endif > At first I was worried that this improvement would be dependent on > setrlimit success, but it appears that it cannot fail for the arguments > used here. I wonder if it's better to assert that non-failure -- or > maybe just issue a warning, so that if it happens we'll be more likely > to get a bug report about it, rather than have users endure a subtle > difference in behavior. I'll issue a warning. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Sun Jul 17 08:02:30 2011 Received: (at control) by debbugs.gnu.org; 17 Jul 2011 12:02:31 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QiQ3K-0008Nt-Ej for submit@debbugs.gnu.org; Sun, 17 Jul 2011 08:02:30 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1QiQ3I-0008Nf-Dj for control@debbugs.gnu.org; Sun, 17 Jul 2011 08:02:29 -0400 Received: (qmail 64529 invoked from network); 17 Jul 2011 12:02:21 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 17 Jul 2011 12:02:21 -0000 Message-ID: <4E22CED1.4010505@draigBrady.com> Date: Sun, 17 Jul 2011 13:00:17 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: control@debbugs.gnu.org Subject: closing 8938 X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -2.6 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.6 (--) package coreutils close 8938 8.13 From unknown Sat Sep 06 02:03:47 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 15 Aug 2011 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator