GNU bug report logs -
#54681
timeout: Program called by timeout cannot interact with tty stdin when timeout is called by exec()
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 54681 in the body.
You can then email your comments to 54681 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#54681
; Package
coreutils
.
(Sat, 02 Apr 2022 11:24:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Zhaofeng Yang <yangzhaofeng <at> arcas-da.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Sat, 02 Apr 2022 11:24:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi GNU Team,
I found that program called by timeout cannot interact with tty stdin
when timeout is called by exec().
A simplest example is `timeout 10 timeout 5 cat`. cat cannot read input
from tty stdin.
I also tried to run `timeout 5 cat` in other programs by exec(), and
all of them cannot read tty stdin. For example,
import subprocess
subprocess.run(f"timeout 5 cat", shell=True)
with Python 3.
I guessed it is a problem with exec(), but trying with the simple C
program
/* system.c */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(const int argc, const char* argv[]){
size_t cmd_length = argc;
for(int i=1; i<argc; i++){
cmd_length += strlen(argv[i]);
}
char* cmd_alloc = calloc(cmd_length, sizeof(char));
char* cmd = cmd_alloc;
for(int i=1; i<argc; i++){
strncpy(cmd_alloc, argv[i], strlen(argv[i]));
cmd_alloc += strlen(argv[i]);
cmd_alloc[0] = ' ';
cmd_alloc++;
}
cmd_alloc[ cmd_alloc != cmd ? -1 : 0 ] = '\0';
//printf("%s\n", cmd);
system(cmd);
free(cmd);
return 0;
}
with `./system ./system cat` it works as expected, while running
`./system timeout 5 cat` the bug occurs.
This bug (or is it a feature?) appears in coreutils 8.32 and 9.0, as I
have tested.
--
Zhaofeng Yang <yangzhaofeng <at> arcas-da.com>
[signature.asc (application/pgp-signature, inline)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#54681
; Package
coreutils
.
(Sat, 02 Apr 2022 12:22:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 54681 <at> debbugs.gnu.org (full text, mbox):
On Apr 02 2022, Zhaofeng Yang wrote:
> A simplest example is `timeout 10 timeout 5 cat`. cat cannot read input
> from tty stdin.
That's because timeout creates a new process group by default. The
outer timeout instance already runs in its own process group curtesy of
the parent shell (and thus remains in that group), but for the inner
instance the process group no longer matches the terminal process group,
and thus the children cannot read from the TTY. You can use timeout
--foreground to avoid that.
$ timeout 10 timeout --foreground 5 cat
--
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#54681
; Package
coreutils
.
(Sat, 02 Apr 2022 12:26:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 54681 <at> debbugs.gnu.org (full text, mbox):
tag 54681 notabug
close 54681
stop
On 02/04/2022 11:22, Zhaofeng Yang wrote:
> Hi GNU Team,
>
> I found that program called by timeout cannot interact with tty stdin
> when timeout is called by exec().
>
> A simplest example is `timeout 10 timeout 5 cat`. cat cannot read input
> from tty stdin.
>
> I also tried to run `timeout 5 cat` in other programs by exec(), and
> all of them cannot read tty stdin. For example,
>
> import subprocess
> subprocess.run(f"timeout 5 cat", shell=True)
timeout has a --foreground option to support this case,
with the caveat that if the program forks children,
they'll not be timed out.
See https://www.gnu.org/software/coreutils/timeout for details.
cheers,
Pádraig
Added tag(s) notabug.
Request was from
Pádraig Brady <P <at> draigBrady.com>
to
control <at> debbugs.gnu.org
.
(Sat, 02 Apr 2022 12:26:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
54681 <at> debbugs.gnu.org and Zhaofeng Yang <yangzhaofeng <at> arcas-da.com>
Request was from
Pádraig Brady <P <at> draigBrady.com>
to
control <at> debbugs.gnu.org
.
(Sat, 02 Apr 2022 12:26:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 01 May 2022 11:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 108 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.