Makefile, debian/{control,inst}: Sort the various lists of things.
[misc] / mtimeout.c
index 055ef7e..373f2b0 100644 (file)
@@ -287,7 +287,11 @@ static void strtotime(const char *p, struct timeval *tv)
 /*----- Help functions ----------------------------------------------------*/
 
 static void usage(FILE *fp)
-  { pquis(fp, "Usage: $ [-s SIG] SECONDS COMMAND [ARGUMENTS ...]\n"); }
+{
+  pquis(fp,
+       "Usage: $ [-K] [-b TIME] [-k TIME] [-s SIG] "
+       "TIME COMMAND [ARGUMENTS ...]\n");
+}
 
 static void version(FILE *fp)
   { pquis(fp, "$ (version " VERSION ")\n"); }
@@ -298,14 +302,21 @@ static void help(FILE *fp)
   usage(fp);
   pquis(fp, "\n\
 Run COMMAND, giving it the ARGUMENTS.  If it fails to complete within the\n\
-specified number of SECONDS, kill it.  Otherwise exit with the status it\n\
-returns.\n                                                             \
+specified number of TIME, kill it.  Otherwise exit with the status it\n\
+returns.\n\
+\n\
+A TIME is a possibly fractional number followed by an optional unit\n\
+designator, which may be `s', `m', `h', or `d', for seconds, minutes,\n\
+hours, or days, respectively.  The default units are seconds.\n\
 \n\
 Options:\n\
   -h, --help           Show this help text.\n\
   -v, --version                Show version string.\n\
   -u, --usage          Show a terse usage summary.\n\
 \n\
+  -b, --bored-after=TIME  Wait for TIME after sending SIGKILL.\n\
+  -k, --kill-after=TIME        Wait for TIME after signal before sending SIGKILL.\n\
+  -K, --no-kill                Don't send SIGKILL; just give up when bored.\n\
   -s, --signal=SIG     Send signal SIG to the command.\n\
 ");
 }
@@ -361,7 +372,7 @@ static void timeout(struct timeval *now, void *p)
     ta = &t->ta[t->ip++];
     switch (ta->act) {
       case TA_MOAN:
-       moan(ta->u.s);
+       moan("%s", ta->u.s);
        break;
       case TA_KILL:
        kill(-t->kid, ta->u.i);
@@ -480,16 +491,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);