Subject: bug#8938: make timeout and CTRL-C

From: Jim Meyering <[email-masked]>
Date: Thu, 07 Jul 2011 12:55:10 +0200

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.

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 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.  */

The comment is worth more if it says e.g.,

            /* If true, don't create a separate process group.  */