Re: [PATCH] Add timeout utility

2008-04-03 Thread Pádraig Brady
take 2 attached.
Note I kept the time interval parsing function
separate between `kill` and `timeout`, as they
operate on different types.

Pádraig.
>From 95c61d20933a749482c3d1d54eb3b1032735ab75 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <[EMAIL PROTECTED]>
Date: Fri, 28 Mar 2008 11:05:55 +
Subject: [PATCH] Add new program: timeout

* AUTHORS: Register as the author
* NEWS: Mention this change
* README: Add timeout command to list
* src/truncate.c: New command
* src/operand2sig.c: Split out function called by kill and timeout
* src/operand2sig.h: New operand2sig() function prototype
* src/Makefile.am: Add timeout command to list to build
* doc/coreutils.texi (timeout invocation): Add timeout info
* man/Makefile.am: Add timeout man page to list to build
* man/truncate.x: Add timeout man page template
* po/POTFILES.in: Add timeout to list to translate
* tests/misc/Makefile.am: Add timeout tests
* tests/misc/help-version: Add support for new timeout command
* tests/misc/timeout: check basic timeout operation
* tests/misc/timeout-parameters: check invalid parameter combinations

Signed-off-by: Pádraig Brady <[EMAIL PROTECTED]>
---
 AUTHORS   |1 +
 NEWS  |4 +
 README|4 +-
 doc/coreutils.texi|  242 +++---
 man/Makefile.am   |1 +
 man/timeout.x |6 +
 po/POTFILES.in|1 +
 src/Makefile.am   |5 +-
 src/kill.c|   47 +--
 src/operand2sig.c |   84 ++
 src/operand2sig.h |   19 +++
 src/timeout.c |  335 +
 tests/misc/Makefile.am|2 +
 tests/misc/help-version   |2 +
 tests/misc/timeout|   44 ++
 tests/misc/timeout-parameters |   55 +++
 16 files changed, 718 insertions(+), 134 deletions(-)
 create mode 100644 man/timeout.x
 create mode 100644 src/operand2sig.c
 create mode 100644 src/operand2sig.h
 create mode 100644 src/timeout.c
 create mode 100755 tests/misc/timeout
 create mode 100755 tests/misc/timeout-parameters

diff --git a/AUTHORS b/AUTHORS
index 807857f..87553fd 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -84,6 +84,7 @@ tac: Jay Lepreau, David MacKenzie
 tail: Paul Rubin, David MacKenzie, Ian Lance Taylor, Jim Meyering
 tee: Mike Parker, Richard M. Stallman, David MacKenzie
 test: Kevin Braunsdorf, Matthew Bradburn
+timeout: Padraig Brady
 touch: Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, Randy Smith
 tr: Jim Meyering
 true: Jim Meyering
diff --git a/NEWS b/NEWS
index 5250ed8..a326991 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU coreutils NEWS-*- outline -*-
 
 * Noteworthy changes in release 6.?? (2008-??-??) [stable]
 
+** New programs
+
+  timeout: Run a command with bounded time.
+
 ** Bug fixes
 
   configure --enable-no-install-program=groups now works.
diff --git a/README b/README
index 7a608f4..6159dfd 100644
--- a/README
+++ b/README
@@ -13,8 +13,8 @@ The programs that can be built with this package are:
   link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup
   od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
   runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf
-  sleep sort split stat stty su sum sync tac tail tee test touch tr true
-  tsort tty uname unexpand uniq unlink uptime users vdir wc who whoami yes
+  sleep sort split stat stty su sum sync tac tail tee test timeout touch tr
+  true tsort tty uname unexpand uniq unlink uptime users vdir wc who whoami yes
 
 See the file NEWS for a list of major changes in the current release.
 
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index f161c4d..61d0af1 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -111,6 +111,7 @@
 * tail: (coreutils)tail invocation. Output the last part of files.
 * tee: (coreutils)tee invocation.   Redirect to multiple files.
 * test: (coreutils)test invocation. File/string tests.
+* timeout: (coreutils)touch invocation. Run with time limit.
 * touch: (coreutils)touch invocation.   Change file timestamps.
 * tr: (coreutils)tr invocation. Translate characters.
 * true: (coreutils)true invocation. Do nothing, successfully.
@@ -190,7 +191,7 @@ Free Documentation License''.
 * Working context::pwd stty printenv tty
 * User information::   id logname whoami groups users who
 * System context:: date uname hostname hostid
-* Modified command invocation::chroot env nice nohup su
+* Modified command invocation::chroot env nice nohup su timeout
 * Process control::kill
 * Delaying::   sleep
 * Numeric operations:: factor seq
@@ -208,6 +209,7 @@ Common 

Re: [PATCH] Add timeout utility

2008-04-02 Thread Pádraig Brady
Bo Borgerson wrote:
> On Wed, Apr 2, 2008 at 10:20 AM, Pádraig Brady <[EMAIL PROTECTED]> wrote:
>>  It will always go through though as the kernel will buffer it.
> 
> Yes, that introduces some fuzz, but I think the principle remains
> viable -- the kernel will only buffer so much.

That could be a long time though.

> 
> Consider the following using a timeout.c modified with the attached
> patch, and a small Perl program (below) than hangs after 10 seconds:
> 
> $ time yes | src/timeout -i 2s ./write_then_hang 10 >/dev/null

replacing `yes` with `while true; do yes; sleep 1; done`
causes this to hang for ages.

I'll have another look at this when I finalize `timeout`

thanks,
Pádraig.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Pádraig Brady
Mike Frysinger wrote:
> On Wednesday 02 April 2008, Pádraig Brady wrote:
>> To be sure, are you referring to races where a signal
>> can be received while in the signal handler on some systems?
>>
>> Also there is the issue of restarting system calls
>> after the signal handler has run.
>>
>> Also there is the issue of resetting the signal
>> handler after it has run.
>>
>> Are there systems that coreutils supports currently
>> that doesn't follow BSD/linux semantics wrt the above 3 points?
> 
> afaik, Linux behaves as POSIX dictates.  that means it does not behave as you 
> describe above.  newer versions of glibc may block the same signal from 
> re-occuring, but it doesnt block other signals.

True, but the current timeout implementation can handle that.
Anyway I'll get rid of the ambiguity using sigaction as you suggest.

cheers,
Pádraig.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Bo Borgerson
On Wed, Apr 2, 2008 at 10:20 AM, Pádraig Brady <[EMAIL PROTECTED]> wrote:
>  It will always go through though as the kernel will buffer it.

Yes, that introduces some fuzz, but I think the principle remains
viable -- the kernel will only buffer so much.

Consider the following using a timeout.c modified with the attached
patch, and a small Perl program (below) than hangs after 10 seconds:

$ time yes | src/timeout -i 2s ./write_then_hang 10 >/dev/null

real0m11.777s
user0m0.656s
sys 0m0.068s

Bo

-- Perl --

#!/usr/bin/perl -w

my $n = shift @ARGV || 10;

my $s = time;

print scalar() while (time - $s < $n);

while(1){ }
diff --git a/src/timeout.c b/src/timeout.c
index 7c15f1d..1f44c27 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -75,6 +75,9 @@
 # define WTERMSIG(s) ((s) & 0x7F)
 #endif
 
+/* Size of atomic reads. */
+#define BUFFER_SIZE (16 * 1024)
+
 static int timed_out;
 static int term_signal = SIGTERM;  /* same default as kill command.  */
 static int monitored_pid;
@@ -83,6 +86,7 @@ static char *program_name;
 
 static struct option const long_options[] = {
   {"signal", required_argument, NULL, 's'},
+  {"inactivity", no_argument, NULL, 'i'},
   {NULL, 0, NULL, 0}
 };
 
@@ -144,8 +148,10 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -s, --signal=SIGNAL\n\
specify the signal to be sent on timeout.\n\
SIGNAL may be a name like `HUP' or a number.\n\
-   See `kill -l` for a list of signals\n"), stdout);
-
+   See `kill -l` for a list of signals\n\
+  -i, --inactivity\n\
+   act as a filter and only timeout if NUMBER\n\
+   seconds have passed without data flowing.\n"), stdout);
   fputs (HELP_OPTION_DESCRIPTION, stdout);
   fputs (VERSION_OPTION_DESCRIPTION, stdout);
   fputs (_("\n\
@@ -250,6 +256,8 @@ main (int argc, char **argv)
 {
   unsigned long timeout;
   char signame[SIG2STR_MAX];
+  bool inactivity = false;
+  int pipefds[2];
   int c;
   char *ep;
 
@@ -265,7 +273,7 @@ main (int argc, char **argv)
   parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION,
   usage, AUTHORS, (char const *) NULL);
 
-  while ((c = getopt_long (argc, argv, "+s:", long_options, NULL)) != -1)
+  while ((c = getopt_long (argc, argv, "+s:i", long_options, NULL)) != -1)
 {
   switch (c)
 {
@@ -274,6 +282,9 @@ main (int argc, char **argv)
   if (term_signal == -1)
 usage (ECANCELED);
   break;
+case 'i':
+  inactivity = true;
+  break;
 default:
   usage (ECANCELED);
   break;
@@ -315,6 +326,12 @@ main (int argc, char **argv)
   signal (SIGTTIN, SIG_IGN);/* don't sTop if background child needs tty.  */
   signal (SIGTTOU, SIG_IGN);/* don't sTop if background child needs tty.  */
 
+  if (inactivity)
+{
+  if (pipe(pipefds) == -1)
+perror ("pipe");
+}
+
   monitored_pid = fork ();
   if (monitored_pid == -1)
 {
@@ -325,6 +342,13 @@ main (int argc, char **argv)
 {   /* child */
   int exit_status;
 
+  if (inactivity)
+{
+  close (pipefds[1]);
+  close (STDIN_FILENO);
+  dup2 (pipefds[0], STDIN_FILENO);
+}
+
   /* exec doesn't reset SIG_IGN -> SIG_DFL.  */
   signal (SIGTTIN, SIG_DFL);
   signal (SIGTTOU, SIG_DFL);
@@ -342,6 +366,21 @@ main (int argc, char **argv)
 
   alarm ((unsigned int) timeout);
 
+  if (inactivity)
+{
+  int bytes_read;
+  char buf[BUFFER_SIZE];
+  close (pipefds[0]);
+  close (STDOUT_FILENO);
+  dup2 (pipefds[1], STDOUT_FILENO);
+  while ((bytes_read = read(STDIN_FILENO, buf, BUFFER_SIZE)) > 0)
+{
+  if ((write(STDOUT_FILENO, buf, bytes_read)) == -1)
+perror ("write");
+  alarm ((unsigned int) timeout);
+}
+}
+
   /* We're just waiting for a single process here, so wait() suffices.
* Note the signal() calls above on linux and BSD at least, essentially
* call the lower level sigaction() with the SA_RESTART flag set, which
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Mike Frysinger
On Wednesday 02 April 2008, Pádraig Brady wrote:
> Mike Frysinger wrote:
> > On Tuesday 01 April 2008, Pádraig Brady wrote:
> >> +  /* Setup handlers before fork() so that we
> >> +   * handle any signals caused by child, without races.  */
> >> +  signal (SIGALRM, cleanup);/* our timeout.  */
> >> +  signal (SIGINT, cleanup); /* Ctrl-C at terminal for example.  */
> >> +  signal (SIGQUIT, cleanup);/* Ctrl-\ at terminal for example.  */
> >> +  signal (SIGTERM, cleanup);/* if we're killed, stop monitored
> >> process.  */ +  signal (SIGHUP, cleanup); /* terminal closed for
> >> example.  */ +  signal (SIGTTIN, SIG_IGN);/* don't sTop if
> >> background child needs tty.  */ +  signal (SIGTTOU, SIG_IGN);/*
> >> don't sTop if background child needs tty.  */
> >
> > if you're using signal(), you have race problems.  why not use
> > sigaction() and friends instead ?
>
> I originally wrote this for util-linux-ng.
> BSD and linux at least handle signal() sanely
> so I wrote it for those.
>
> Since coreutils needs to be more portable,
> I'll change to the more complicated sigaction instead.
>
> To be sure, are you referring to races where a signal
> can be received while in the signal handler on some systems?
>
> Also there is the issue of restarting system calls
> after the signal handler has run.
>
> Also there is the issue of resetting the signal
> handler after it has run.
>
> Are there systems that coreutils supports currently
> that doesn't follow BSD/linux semantics wrt the above 3 points?

afaik, Linux behaves as POSIX dictates.  that means it does not behave as you 
describe above.  newer versions of glibc may block the same signal from 
re-occuring, but it doesnt block other signals.
-mike


signature.asc
Description: This is a digitally signed message part.
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Pádraig Brady
Bo Borgerson wrote:
> Pádraig Brady <[EMAIL PROTECTED]> wrote:
>> Subject: [PATCH] Add new program: timeout
> 
> Great idea for a tool!

Not my idea TBH:
http://mail.linux.ie/pipermail/ilug/2006-November/thread.html#90654

> Have you considered an alternate run-mode where it could operate as a
> filter and timeout on 'inactivity' of the pipeline?
> 
> For example:
> 
> $ sort -m inputs/* | timeout --inactivity 1m program_prone_to_stalling
> 
> Where timeout would open a pipe and dup2 the read end to child's
> STDIN_FILENO before exec'ing.

How would `timeout` determine when
`program_prone_to_stalling` issues read()s ?

cheers,
Pádraig.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Bo Borgerson
Pádraig Brady <[EMAIL PROTECTED]> wrote:
> Subject: [PATCH] Add new program: timeout

Great idea for a tool!

Have you considered an alternate run-mode where it could operate as a
filter and timeout on 'inactivity' of the pipeline?

If, for instance, I have a pipeline that processes a lot of data and
could legitimately take anywhere from a minute to an hour, it's
difficult to set an absolute timeout that doesn't risk chopping off
the end of the stream.  Then, with such a large timeout, my pipeline
could stall in the first ten seconds and I wouldn't know for a long
time.

If, on the other hand, I could say that there shouldn't ever be thirty
seconds without a buffer's worth of data coming through, then I could
set the timeout very low and know soon after a blockage formed.

For example:

$ sort -m inputs/* | timeout --inactivity 1m program_prone_to_stalling

Where timeout would open a pipe and dup2 the read end to child's
STDIN_FILENO before exec'ing.

If this sounds like a worthwhile extension I'd be happy to get to work
on it and submit a patch once your initial version has settled in.

Thanks,

Bo


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Pádraig Brady
Jim Meyering wrote:
> Thanks!
> 
> Pádraig Brady <[EMAIL PROTECTED]> wrote:
>> Subject: [PATCH] Add new program: timeout
> ...
>> +/* Given an integer value *X, and a suffix character, SUFFIX_CHAR,
>> +   scale *X by the multiplier implied by SUFFIX_CHAR.  SUFFIX_CHAR may
>> +   be the NUL byte or `s' to denote seconds, `m' for minutes, `h' for
>> +   hours, or `d' for days.  If SUFFIX_CHAR is invalid, don't modify *X
>> +   and return false.  If *X would overflow, don't modify *X and return 
>> false.
>> +   Otherwise return true.  */
>> +
>> +static bool
>> +apply_suffix (unsigned int *x, char suffix_char)
> 
> You probably expect this, but I have to say it ;-)
> Don't duplicate code!

of course.

> apply_suffix is a tiny function, and used also by sleep.c, so let's not
> duplicate it.  How about putting it (static inline) in system.h instead?

sleep's apply_suffic() works on floats where as timeout's work on ints.
I'll see if I can merge them somewhat.
Hmm I could allow float input to timeout (1.5d for example),
and then round this to the nearest second later?

> operand2sig is similar but not as lightweight, since it uses str2sig,
> error, xstrdup and W* macros.  Maybe put it in its own file in src/?
> Or change xstrdup to strdup, eliminate the error call, and consider
> putting it in lib/gnulib.  It's probably better to go the easier
> route and use a separate file in src/[ch].

I intended but forgot to add the comment:
/* FIXME: where will we refactor this to? */
I'll add a new src/ file so.

> 
> Rather than '???' (or in addition to), please mark such
> comments with "FIXME".

righto

>> +  /* Setup handlers before fork() so that we
>> +   * handle any signals caused by child, without races.  */
>> +  signal (SIGALRM, cleanup);/* our timeout.  */
>> +  signal (SIGINT, cleanup); /* Ctrl-C at terminal for example.  */
>> +  signal (SIGQUIT, cleanup);/* Ctrl-\ at terminal for example.  */
>> +  signal (SIGTERM, cleanup);/* if we're killed, stop monitored process. 
>>  */
> 
> Mike Frysinger's point is a good one: use signal only if absolutely
> necessary.  Prefer sigaction.
> 
> Most signal-handling code in coreutils uses sigaction, and falls back on
> signal ifndef SA_NOCLDSTOP.  But the ifdefs and code duplication are
> pretty ugly.  If you're game, I'd like to try using *only* sigaction for
> an initial test release, in order to see if any "reasonable portability
> targets" remain that lack sigaction support.  Then, if there are no
> build failure reports for a long enough period, we can remove the crufty
> signal-using #else blocks in a bunch of programs.


Ok, I'll assume that sigaction is available.

thanks,
Pádraig.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Jim Meyering
Thanks!

Pádraig Brady <[EMAIL PROTECTED]> wrote:
> Subject: [PATCH] Add new program: timeout
...
> +/* Given an integer value *X, and a suffix character, SUFFIX_CHAR,
> +   scale *X by the multiplier implied by SUFFIX_CHAR.  SUFFIX_CHAR may
> +   be the NUL byte or `s' to denote seconds, `m' for minutes, `h' for
> +   hours, or `d' for days.  If SUFFIX_CHAR is invalid, don't modify *X
> +   and return false.  If *X would overflow, don't modify *X and return false.
> +   Otherwise return true.  */
> +
> +static bool
> +apply_suffix (unsigned int *x, char suffix_char)

You probably expect this, but I have to say it ;-)
Don't duplicate code!

apply_suffix is a tiny function, and used also by sleep.c, so let's not
duplicate it.  How about putting it (static inline) in system.h instead?

operand2sig is similar but not as lightweight, since it uses str2sig,
error, xstrdup and W* macros.  Maybe put it in its own file in src/?
Or change xstrdup to strdup, eliminate the error call, and consider
putting it in lib/gnulib.  It's probably better to go the easier
route and use a separate file in src/[ch].

Rather than '???' (or in addition to), please mark such
comments with "FIXME".

...
> +  /* Setup handlers before fork() so that we
> +   * handle any signals caused by child, without races.  */
> +  signal (SIGALRM, cleanup);/* our timeout.  */
> +  signal (SIGINT, cleanup); /* Ctrl-C at terminal for example.  */
> +  signal (SIGQUIT, cleanup);/* Ctrl-\ at terminal for example.  */
> +  signal (SIGTERM, cleanup);/* if we're killed, stop monitored process.  
> */

Mike Frysinger's point is a good one: use signal only if absolutely
necessary.  Prefer sigaction.

Most signal-handling code in coreutils uses sigaction, and falls back on
signal ifndef SA_NOCLDSTOP.  But the ifdefs and code duplication are
pretty ugly.  If you're game, I'd like to try using *only* sigaction for
an initial test release, in order to see if any "reasonable portability
targets" remain that lack sigaction support.  Then, if there are no
build failure reports for a long enough period, we can remove the crufty
signal-using #else blocks in a bunch of programs.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


Re: [PATCH] Add timeout utility

2008-04-02 Thread Pádraig Brady
Mike Frysinger wrote:
> On Tuesday 01 April 2008, Pádraig Brady wrote:
>> +  /* Setup handlers before fork() so that we
>> +   * handle any signals caused by child, without races.  */
>> +  signal (SIGALRM, cleanup);/* our timeout.  */
>> +  signal (SIGINT, cleanup); /* Ctrl-C at terminal for example.  */
>> +  signal (SIGQUIT, cleanup);/* Ctrl-\ at terminal for example.  */
>> +  signal (SIGTERM, cleanup);/* if we're killed, stop monitored
>> process.  */ +  signal (SIGHUP, cleanup); /* terminal closed for
>> example.  */ +  signal (SIGTTIN, SIG_IGN);/* don't sTop if background
>> child needs tty.  */ +  signal (SIGTTOU, SIG_IGN);/* don't sTop if
>> background child needs tty.  */
> 
> if you're using signal(), you have race problems.  why not use sigaction() 
> and 
> friends instead ?

I originally wrote this for util-linux-ng.
BSD and linux at least handle signal() sanely
so I wrote it for those.

Since coreutils needs to be more portable,
I'll change to the more complicated sigaction instead.

To be sure, are you referring to races where a signal
can be received while in the signal handler on some systems?

Also there is the issue of restarting system calls
after the signal handler has run.

Also there is the issue of resetting the signal
handler after it has run.

Are there systems that coreutils supports currently
that doesn't follow BSD/linux semantics wrt the above 3 points?

thanks,
Pádraig.


___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils


[PATCH] Add timeout utility

2008-04-01 Thread Pádraig Brady
attached
>From e2c2d212bfea29540bb433bb8d00e1e9e9fd3ff6 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?P=C3=A1draig=20Brady?= <[EMAIL PROTECTED]>
Date: Fri, 28 Mar 2008 11:05:55 +
Subject: [PATCH] Add new program: timeout

* AUTHORS: Register as the author
* NEWS: Mention this change
* README: Add timeout command to list
* src/truncate.c: New command
* src/Makefile.am: Add timeout command to list to build
* doc/coreutils.texi (timeout invocation): Add timeout info
* man/Makefile.am: Add timeout man page to list to build
* man/truncate.x: Add timeout man page template
* po/POTFILES.in: Add timeout to list to translate
* tests/misc/Makefile.am: Add timeout tests
* tests/misc/help-version: Add support for new timeout command
* tests/misc/timeout: check basic timeout operation
* tests/misc/timeout-parameters: check invalid parameter combinations

Signed-off-by: Pádraig Brady <[EMAIL PROTECTED]>
---
 AUTHORS   |1 +
 NEWS  |4 +
 README|4 +-
 doc/coreutils.texi|  242 +--
 man/Makefile.am   |1 +
 man/timeout.x |6 +
 po/POTFILES.in|1 +
 src/Makefile.am   |2 +-
 src/timeout.c |  370 +
 tests/misc/Makefile.am|2 +
 tests/misc/help-version   |2 +
 tests/misc/timeout|   41 +
 tests/misc/timeout-parameters |   58 +++
 13 files changed, 646 insertions(+), 88 deletions(-)
 create mode 100644 man/timeout.x
 create mode 100644 src/timeout.c
 create mode 100755 tests/misc/timeout
 create mode 100755 tests/misc/timeout-parameters

diff --git a/AUTHORS b/AUTHORS
index 807857f..87553fd 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -84,6 +84,7 @@ tac: Jay Lepreau, David MacKenzie
 tail: Paul Rubin, David MacKenzie, Ian Lance Taylor, Jim Meyering
 tee: Mike Parker, Richard M. Stallman, David MacKenzie
 test: Kevin Braunsdorf, Matthew Bradburn
+timeout: Padraig Brady
 touch: Paul Rubin, Arnold Robbins, Jim Kingdon, David MacKenzie, Randy Smith
 tr: Jim Meyering
 true: Jim Meyering
diff --git a/NEWS b/NEWS
index 5250ed8..a326991 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU coreutils NEWS-*- outline -*-
 
 * Noteworthy changes in release 6.?? (2008-??-??) [stable]
 
+** New programs
+
+  timeout: Run a command with bounded time.
+
 ** Bug fixes
 
   configure --enable-no-install-program=groups now works.
diff --git a/README b/README
index 7a608f4..6159dfd 100644
--- a/README
+++ b/README
@@ -13,8 +13,8 @@ The programs that can be built with this package are:
   link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup
   od paste pathchk pinky pr printenv printf ptx pwd readlink rm rmdir
   runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum shred shuf
-  sleep sort split stat stty su sum sync tac tail tee test touch tr true
-  tsort tty uname unexpand uniq unlink uptime users vdir wc who whoami yes
+  sleep sort split stat stty su sum sync tac tail tee test timeout touch tr
+  true tsort tty uname unexpand uniq unlink uptime users vdir wc who whoami yes
 
 See the file NEWS for a list of major changes in the current release.
 
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index f161c4d..61d0af1 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -111,6 +111,7 @@
 * tail: (coreutils)tail invocation. Output the last part of files.
 * tee: (coreutils)tee invocation.   Redirect to multiple files.
 * test: (coreutils)test invocation. File/string tests.
+* timeout: (coreutils)touch invocation. Run with time limit.
 * touch: (coreutils)touch invocation.   Change file timestamps.
 * tr: (coreutils)tr invocation. Translate characters.
 * true: (coreutils)true invocation. Do nothing, successfully.
@@ -190,7 +191,7 @@ Free Documentation License''.
 * Working context::pwd stty printenv tty
 * User information::   id logname whoami groups users who
 * System context:: date uname hostname hostid
-* Modified command invocation::chroot env nice nohup su
+* Modified command invocation::chroot env nice nohup su timeout
 * Process control::kill
 * Delaying::   sleep
 * Numeric operations:: factor seq
@@ -208,6 +209,7 @@ Common Options
 * Exit status:: Indicating program success or failure.
 * Backup options::  Backup options
 * Block size::  Block size
+* Signal specifications::   Specifying signals
 * Disambiguating names and IDs:: chgrp and chown owner and group syntax
 * Random sources::  Sources of random data
 * Target directory::Target directory
@@ -421,6 +423,7 @@ Modified command invocation
 * nice invocation::

Re: [PATCH] Add timeout utility

2008-04-01 Thread Mike Frysinger
On Tuesday 01 April 2008, Pádraig Brady wrote:
> +  /* Setup handlers before fork() so that we
> +   * handle any signals caused by child, without races.  */
> +  signal (SIGALRM, cleanup);    /* our timeout.  */
> +  signal (SIGINT, cleanup);     /* Ctrl-C at terminal for example.  */
> +  signal (SIGQUIT, cleanup);    /* Ctrl-\ at terminal for example.  */
> +  signal (SIGTERM, cleanup);    /* if we're killed, stop monitored
> process.  */ +  signal (SIGHUP, cleanup);     /* terminal closed for
> example.  */ +  signal (SIGTTIN, SIG_IGN);    /* don't sTop if background
> child needs tty.  */ +  signal (SIGTTOU, SIG_IGN);    /* don't sTop if
> background child needs tty.  */

if you're using signal(), you have race problems.  why not use sigaction() and 
friends instead ?
-mike


signature.asc
Description: This is a digitally signed message part.
___
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils