GNU bug report logs - #54681
timeout: Program called by timeout cannot interact with tty stdin when timeout is called by exec()

Previous Next

Package: coreutils;

Reported by: Zhaofeng Yang <yangzhaofeng <at> arcas-da.com>

Date: Sat, 2 Apr 2022 11:24:01 UTC

Severity: normal

Tags: notabug

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zhaofeng Yang <yangzhaofeng <at> arcas-da.com>
To: bug-coreutils <at> gnu.org
Subject: timeout: Program called by timeout cannot interact with tty stdin
 when timeout is called by exec()
Date: Sat, 02 Apr 2022 18:22:06 +0800
[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)]

This bug report was last modified 3 years and 110 days ago.

Previous Next


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