mtimeout.c: Add `--kill-after' and `--no-kill' options.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 15 Dec 2011 00:55:01 +0000 (00:55 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 15 Dec 2011 01:12:46 +0000 (01:12 +0000)
The `--kill-after' option is from the GNU Coreutils `timeout' program,
which doesn't kill by default.  The `--no-kill' option emulates this
behaviour.

mtimeout.1
mtimeout.c

index 9332807..147b097 100644 (file)
@@ -4,8 +4,15 @@ mtimeout \- run a program for at most a given amount of time
 .
 .SH SYNOPSIS
 .B mtimeout
+.RB [ \-K ]
+.RB [ \-k
+.IR time ]
+.RB [ \-b
+.IR time ]
 .RB [ \-s
 .IR signal ]
+.br
+       \c
 .I time
 .I command
 .RI [ arguments ...]
@@ -41,11 +48,15 @@ sends its child process group the specified signal, by default
 .BR SIGTERM ,
 though you can choose a different one with the
 .B \-s
-option.  It then waits an additional five seconds.  If the child still
-hasn't exited, it sends
+option.  It then waits an additional five seconds (configurable with
+the
+.B \-k
+option).  If the child still hasn't exited, it sends
 .B SIGKILL
-to the process group and waits a further five seconds.  If the child
-still hasn't exited in this time, then
+to the process group and waits a further five seconds (configurable
+with the
+.B \-b
+option).  If the child still hasn't exited in this time, then
 .B mtimeout
 gives up and exits.
 .PP
@@ -62,6 +73,39 @@ successfully.
 .B \-u, \-\-usage
 Prints a brief usage summary to standard output, and exits successfully.
 .TP
+.BI "\-b, \-\-bored-after=" time
+After sending
+.B SIGKILL
+(or, with
+.BR \-K ,
+the original signal)
+wait for
+.I time
+before giving up and declaring the child process undead.  The default
+wait is five seconds.  The
+.I time
+may have a unit suffix.
+.TP
+.B "\-K, \-\-no-kill"
+Don't send a
+.B SIGKILL
+to the process: just wait for a while (see the
+.B \-b
+option) after sending the original signal to see whether it actually
+dies.
+.TP
+.B "\-k, \-\-kill-after=" time
+After sending a signal, wait for
+.I time
+before sending
+.BR SIGKILL .
+The default wait is five seconds.  The
+.I time
+may have a unit suffix.
+This option has no effect if
+.BR \-K
+is set.
+.TP
 .BI "\-s, \-\-signal=" signal
 Send
 .I signal
index 055ef7e..9b22fb7 100644 (file)
@@ -480,16 +480,31 @@ int main(int argc, char *const argv[])
       { "help",                        0,              0,      'h' },
       { "version",             0,              0,      'v' },
       { "usage",               0,              0,      'u' },
+      { "no-kill",             0,              0,      'K' },
+      { "kill-after",          OPTF_ARGREQ,    0,      'k' },
+      { "bored-after",         OPTF_ARGREQ,    0,      'b' },
       { "signal",              OPTF_ARGREQ,    0,      's' },
       { 0,                     0,              0,      0 }
     };
 
-    int i = mdwopt(argc, argv, "+hvus:", opts, 0, 0, 0);
+    int i = mdwopt(argc, argv, "+hvuKb:k:s:", opts, 0, 0, 0);
     if (i < 0) break;
     switch (i) {
       case 'h': help(stdout); exit(0);
       case 'v': version(stdout); exit(0);
       case 'u': usage(stdout); exit(0);
+      case 'b':
+       ta[taoff_boredwait].act = TA_WAIT;
+       strtotime(optarg, &ta[taoff_boredwait].u.tv);
+       break;
+      case 'k':
+       ta[taoff_killwait].act = TA_WAIT;
+       strtotime(optarg, &ta[taoff_killwait].u.tv);
+       break;
+      case 'K':
+       ta[taoff_killwait].act = TA_GOTO;
+       ta[taoff_killwait].u.i = taoff_boredwait;
+       break;
       case 's':
        if ((ta[taoff_sig].u.i = namesig(optarg)) < 0)
          die(253, "bad signal spec `%s'", optarg);