Received: (at 15779) by debbugs.gnu.org; 1 Nov 2013 14:39:08 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 01 10:39:07 2013 Received: from localhost ([127.0.0.1]:57556 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1VcFsR-0000ml-5z for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 10:39:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48762) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <rjones@HIDDEN>) id 1VcFsK-0000mF-6p for 15779 <at> debbugs.gnu.org; Fri, 01 Nov 2013 10:39:01 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA1EcwfU004910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 1 Nov 2013 10:38:58 -0400 Received: from localhost (vpn1-5-7.ams2.redhat.com [10.36.5.7]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA1EUbrh007628; Fri, 1 Nov 2013 10:30:37 -0400 Date: Fri, 1 Nov 2013 14:30:33 +0000 From: "Richard W.M. Jones" <rjones@HIDDEN> To: =?iso-8859-1?Q?P=E1draig?= Brady <P@HIDDEN> Subject: Re: bug#15779: timeout: Child gets SIGTTOU when run from a shell script Message-ID: <20131101143033.GD1887@HIDDEN> References: <20131101081028.GA18071@HIDDEN> <52739648.1070901@HIDDEN> <20131101121737.GC1887@HIDDEN> <5273B13D.9060205@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5273B13D.9060205@HIDDEN> User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-Spam-Score: -5.5 (-----) X-Debbugs-Envelope-To: 15779 Cc: 15779 <at> debbugs.gnu.org X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -5.5 (-----) On Fri, Nov 01, 2013 at 01:48:45PM +0000, Pádraig Brady wrote: > The initial messages to bug-coreutils have disappeared somewhere in > the ether. Anyway the context is that if a process being controlled > by timeout gets a SIGTTOU, then it will be stopped. I don't think this is strictly accurate. The issue I have is that timeout behaves differently when running directly from the command line versus run from the command line via an intermediate shell script. interactive -> timeout -> command # OK interactive -> bash script -> timeout -> command # SIGTTOU sent SIGTTOU is sent in the latter case, causing the process under test to hang (ie. T state) until the timeout happens. This makes timeout useless for our purposes which is to cause a test to time out if it runs for longer than 4 hours. > I think that since the child wants to "interact" with the tty, that > adding the --foreground option to the timeout command is appropriate > here? The caveat is that children of the monitored command will not > be timed out. Annoyingly, for reasons not well understood, this bug only manifests itself on RHEL 6. Although my minimal test case mentioned in https://bugzilla.redhat.com/show_bug.cgi?id=1025269 works even upstream, the original bug we are trying to avoid only happens on RHEL 6 (no idea why that is .. possibly qemu doesn't play funny games with the tty upstream?) 'timeout' in RHEL 6 doesn't have --foreground. Therefore I have disabled timeout completely on RHEL 6 builds of libguestfs. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
bug-coreutils@HIDDEN
:bug#15779
; Package coreutils
.
Full text available.Pádraig Brady <P@HIDDEN>
to control <at> debbugs.gnu.org
.
Full text available.Received: (at 15779) by debbugs.gnu.org; 1 Nov 2013 13:48:55 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 01 09:48:55 2013 Received: from localhost ([127.0.0.1]:56961 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1VcF5q-0006kz-Mo for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 09:48:54 -0400 Received: from mail6.vodafone.ie ([213.233.128.184]:59906) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <P@HIDDEN>) id 1VcF5o-0006ke-Lf for 15779 <at> debbugs.gnu.org; Fri, 01 Nov 2013 09:48:53 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBAMuvc1JtTemc/2dsb2JhbAANTIM/wDWBNIMZAQEBBDIBRhALDQsJFg8JAwIBAgFFEwEHAQGICAiqAJMtBI9YBxaEGAOebo5L Received: from unknown (HELO [192.168.1.79]) ([109.77.233.156]) by mail3.vodafone.ie with ESMTP; 01 Nov 2013 13:48:46 +0000 Message-ID: <5273B13D.9060205@HIDDEN> Date: Fri, 01 Nov 2013 13:48:45 +0000 From: =?ISO-8859-1?Q?P=E1draig_Brady?= <P@HIDDEN> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: 15779 <at> debbugs.gnu.org Subject: Re: bug#15779: timeout: Child gets SIGTTOU when run from a shell script References: <20131101081028.GA18071@HIDDEN> <52739648.1070901@HIDDEN> <20131101121737.GC1887@HIDDEN> In-Reply-To: <20131101121737.GC1887@HIDDEN> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 15779 Cc: "Richard W.M. Jones" <rjones@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: 0.0 (/) On 11/01/2013 12:17 PM, Richard W.M. Jones wrote: > On Fri, Nov 01, 2013 at 11:53:44AM +0000, Pádraig Brady wrote: >> Probably something to do with job control >> If you `set -m` first in the script, >> then the test binary doesn't hang. > > Unfortunately set -m isn't quite right for the script > we are interested in fixing: > > https://github.com/libguestfs/libguestfs/blob/master/run.in#L217 > >> I did a version of timeout once that put the child in it's own group, >> and noted in that version that I needed to leave SIGTTOU as IGN >> as tcsetpgrp(0, getpid()) caused SIGTTOU to be sent and I wasn't sure why. > > That sounds like a very similar situation to this one. The > tty_check_change function is called all over the place, so just about > any ioctl or flush or tc* function could cause SIGTTOU to be sent. > >> Maybe we should be resetting SIGTT{OU,IN} to what it was >> previously set to, rather than SIG_DFL? > > The attached patch does *not* work .. don't know if you can see > any obvious mistakes. > > Yesterday I looked through the strace -f output between the two cases > and came to the conclusion that it's not about signal handlers at all. > (What it's about is a mystery ...) > > Rich. The initial messages to bug-coreutils have disappeared somewhere in the ether. Anyway the context is that if a process being controlled by timeout gets a SIGTTOU, then it will be stopped. Note timeout handles this case by killing the process when the timeout occurs, but that doesn't help as the process will be stalled for the duration of the timeout. Details at: https://bugzilla.redhat.com/1025269 The workaround was to remove the calls to set SIGTTOU to SIG_DFL just before the child is exec'd, however I'm not sure about that since we want to treat monitored timeout jobs like background processes, and if you run the problematic test child as a standard shell background job, it's stopped also: $ /tmp/test& [2]+ Stopped /tmp/test The proposed workaround mentioned in the quoted text above is ineffective. I think that since the child wants to "interact" with the tty, that adding the --foreground option to the timeout command is appropriate here? The caveat is that children of the monitored command will not be timed out. thanks, Pádraig. p.s. I wonder would cgroups when available give a more powerful "process tree" timeout control functionality
bug-coreutils@HIDDEN
:bug#15779
; Package coreutils
.
Full text available.Received: (at submit) by debbugs.gnu.org; 1 Nov 2013 12:18:08 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 01 08:18:07 2013 Received: from localhost ([127.0.0.1]:56808 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1VcDfz-0004VC-88 for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 08:18:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36943) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from <rjones@HIDDEN>) id 1VcDfv-0004Ue-EE for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 08:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <rjones@HIDDEN>) id 1VcDfk-0007h9-SV for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 08:17:58 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:60340) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <rjones@HIDDEN>) id 1VcDfk-0007h5-P3 for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 08:17:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <rjones@HIDDEN>) id 1VcDfg-0004PR-0e for bug-coreutils@HIDDEN; Fri, 01 Nov 2013 08:17:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <rjones@HIDDEN>) id 1VcDfb-0007fo-7F for bug-coreutils@HIDDEN; Fri, 01 Nov 2013 08:17:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45820) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <rjones@HIDDEN>) id 1VcDfa-0007fj-Ut for bug-coreutils@HIDDEN; Fri, 01 Nov 2013 08:17:43 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA1CHgfr013513 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for <bug-coreutils@HIDDEN>; Fri, 1 Nov 2013 08:17:42 -0400 Received: from localhost (vpn1-5-7.ams2.redhat.com [10.36.5.7]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA1CHfLt017430; Fri, 1 Nov 2013 08:17:41 -0400 Date: Fri, 1 Nov 2013 12:17:37 +0000 From: "Richard W.M. Jones" <rjones@HIDDEN> To: =?iso-8859-1?Q?P=E1draig?= Brady <pbrady@HIDDEN> Subject: Re: timeout: Child gets SIGTTOU when run from a shell script Message-ID: <20131101121737.GC1887@HIDDEN> References: <20131101081028.GA18071@HIDDEN> <52739648.1070901@HIDDEN> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="L+ofChggJdETEG3Y" Content-Disposition: inline In-Reply-To: <52739648.1070901@HIDDEN> User-Agent: Mutt/1.5.20 (2009-12-10) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit Cc: Report bugs to <bug-coreutils@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -5.0 (-----) --L+ofChggJdETEG3Y Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id rA1CHgfr013513 On Fri, Nov 01, 2013 at 11:53:44AM +0000, P=E1draig Brady wrote: > Probably something to do with job control > If you `set -m` first in the script, > then the test binary doesn't hang. Unfortunately set -m isn't quite right for the script we are interested in fixing: https://github.com/libguestfs/libguestfs/blob/master/run.in#L217 > I did a version of timeout once that put the child in it's own group, > and noted in that version that I needed to leave SIGTTOU as IGN > as tcsetpgrp(0, getpid()) caused SIGTTOU to be sent and I wasn't sure w= hy. That sounds like a very similar situation to this one. The tty_check_change function is called all over the place, so just about any ioctl or flush or tc* function could cause SIGTTOU to be sent. > Maybe we should be resetting SIGTT{OU,IN} to what it was > previously set to, rather than SIG_DFL? The attached patch does *not* work .. don't know if you can see any obvious mistakes. Yesterday I looked through the strace -f output between the two cases and came to the conclusion that it's not about signal handlers at all. (What it's about is a mystery ...) Rich. --=20 Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rj= ones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/ --L+ofChggJdETEG3Y Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="timeout.patch2" --- src/timeout.c.old 2013-10-31 19:44:01.719755435 +0000 +++ src/timeout.c 2013-11-01 12:01:06.074839679 +0000 @@ -370,6 +370,7 @@ double timeout; char signame[SIG2STR_MAX]; int c; + struct sigaction sa, sa_ttin, sa_ttou; initialize_main (&argc, &argv); set_program_name (argv[0]); @@ -429,9 +430,16 @@ /* Setup handlers before fork() so that we handle any signals caused by child, without races. */ install_signal_handlers (term_signal); - signal (SIGTTIN, SIG_IGN); /* Don't stop if background child needs tty. */ - signal (SIGTTOU, SIG_IGN); /* Don't stop if background child needs tty. */ - signal (SIGCHLD, SIG_DFL); /* Don't inherit CHLD handling from parent. */ + + /* Don't stop if background child needs tty. */ + sigemptyset (&sa.sa_mask); + sa.sa_handler = SIG_IGN; + sa.sa_flags = SA_RESTART; + sigaction (SIGTTIN, &sa, &sa_ttin); + sigaction (SIGTTOU, &sa, &sa_ttou); + + /* Don't inherit CHLD handling from parent. */ + signal (SIGCHLD, SIG_DFL); monitored_pid = fork (); if (monitored_pid == -1) @@ -443,9 +451,9 @@ { /* child */ int exit_status; - /* exec doesn't reset SIG_IGN -> SIG_DFL. */ - signal (SIGTTIN, SIG_DFL); - signal (SIGTTOU, SIG_DFL); + /* Restore old SIGTTIN/SIGTTOU handlers (RHBZ#1025269). */ + sigaction (SIGTTIN, &sa_ttin, NULL); + sigaction (SIGTTOU, &sa_ttou, NULL); execvp (argv[0], argv); /* FIXME: should we use "sh -c" ... here? */ --L+ofChggJdETEG3Y--
"Richard W.M. Jones" <rjones@HIDDEN>
:bug-coreutils@HIDDEN
.
Full text available.bug-coreutils@HIDDEN
:bug#15779
; Package coreutils
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.