GNU bug report logs - #15781
timeout: Child gets SIGTTOU when run from a shell script

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Reported by: Pádraig Brady <pbrady@HIDDEN>; merged with #15779; dated Fri, 1 Nov 2013 13:43:03 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.
Forcibly Merged 15779 15781. Request was from Pádraig Brady <P@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 1 Nov 2013 13:42:43 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 01 09:42:43 2013
Received: from localhost ([127.0.0.1]:56948 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1VcEzq-0006aj-8w
	for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 09:42:42 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58578)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <pbrady@HIDDEN>) id 1VcDIt-0003ru-Io
 for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 07:54:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <pbrady@HIDDEN>) id 1VcDIf-0007uy-Pa
 for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 07:54:10 -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]:38849)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <pbrady@HIDDEN>) id 1VcDIf-0007uu-MS
 for submit <at> debbugs.gnu.org; Fri, 01 Nov 2013 07:54:01 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:60278)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <pbrady@HIDDEN>) id 1VcDIZ-0006A9-JU
 for bug-coreutils@HIDDEN; Fri, 01 Nov 2013 07:54:01 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <pbrady@HIDDEN>) id 1VcDIT-0007sX-II
 for bug-coreutils@HIDDEN; Fri, 01 Nov 2013 07:53:55 -0400
Received: from mx1.redhat.com ([209.132.183.28]:37402)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <pbrady@HIDDEN>) id 1VcDIT-0007sG-A8
 for bug-coreutils@HIDDEN; Fri, 01 Nov 2013 07:53:49 -0400
Received: from int-mx01.intmail.prod.int.phx2.redhat.com
 (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])
 by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA1BrlPb031041
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
 for <bug-coreutils@HIDDEN>; Fri, 1 Nov 2013 07:53:47 -0400
Received: from [10.36.116.27] (ovpn-116-27.ams2.redhat.com [10.36.116.27])
 by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id
 rA1BriND029378
 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
 Fri, 1 Nov 2013 07:53:46 -0400
Message-ID: <52739648.1070901@HIDDEN>
Date: Fri, 01 Nov 2013 11:53:44 +0000
From: =?ISO-8859-1?Q?P=E1draig_Brady?= <pbrady@HIDDEN>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
 rv:17.0) Gecko/20130110 Thunderbird/17.0.2
MIME-Version: 1.0
To: "Richard W.M. Jones" <rjones@HIDDEN>
Subject: Re: timeout: Child gets SIGTTOU when run from a shell script
References: <20131101081028.GA18071@HIDDEN>
In-Reply-To: <20131101081028.GA18071@HIDDEN>
X-Enigmail-Version: 1.6
Content-Type: text/plain; charset=ISO-8859-1
X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id
 rA1BrlPb031041
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
X-Mailman-Approved-At: Fri, 01 Nov 2013 09:42:40 -0400
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 (-----)

On 11/01/2013 08:10 AM, Richard W.M. Jones wrote:
> Grab the tiny 'run' and 'test.c' attachments from here:
>=20
> https://bugzilla.redhat.com/show_bug.cgi?id=3D1025269#c5
>=20
> $ cd /tmp
> $ gcc -Wall test.c -o test
> $ ./test                             # this is ok
> $ timeout 4h ./test                  # this is ok
>=20
> $ cat ./run
> #!/bin/bash -
> timeout 4h ./test
>=20
> $ ./run                              # this HANGS
>=20
> The run script simply runs the same timeout command as before, from a
> shell script, but this time the test child process gets SIGTTOU and
> suspends itself, resulting in a hang.
>=20
> I was able to fix this by *removing* the following lines in
> src/timeout.c:
>=20
>        /* exec doesn't reset SIG_IGN -> SIG_DFL.  */
>        signal (SIGTTIN, SIG_DFL);
>        signal (SIGTTOU, SIG_DFL);
>=20
> In other words, leave SIGTTOU as SIG_IGN in the child process (which
> seems to make sense -- since the child is a backgrounded process, but
> we want it to be able to print things, we don't want it to get SIGTTOU
> signals when it outputs to the terminal).
>=20
> Anyway, I don't understand why this only happens when run from a shell
> script, and not from a terminal.  Presumably bash does something
> strange with SIGTTOU.

Probably something to do with job control
If you `set -m` first in the script,
then the test binary doesn't hang.

> Also I don't understand from looking at the kernel code why it's
> sending SIGTTOU in one case but not the other.  The relevant code is
> in drivers/tty/tty_io.c:tty_check_change but AFAICT it should send the
> signal in both cases.
>=20
> Rich.
>=20

Ugh these signals are really hairy to think about,
there are all sorts of edge cases here.

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.

Maybe we should be resetting SIGTT{OU,IN} to what it was
previously set to, rather than SIG_DFL?

P=E1draig.




Acknowledgement sent to Pádraig Brady <pbrady@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#15781; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.