hust testsuite: fix a false positive
[oweals/busybox.git] / miscutils / timeout.c
index 273d26953d76bd5b8508d798a936ecf71a1a6198..8df9ff0fdc38fe61346f30e1937a896534a8e55b 100644 (file)
  * rewrite  14-11-2008 vda
  */
 
+//usage:#define timeout_trivial_usage
+//usage:       "[-t SECS] [-s SIG] PROG ARGS"
+//usage:#define timeout_full_usage "\n\n"
+//usage:       "Runs PROG. Sends SIG to it if it is not gone in SECS seconds.\n"
+//usage:       "Defaults: SECS: 10, SIG: TERM."
+
 #include "libbb.h"
 
 int timeout_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -46,9 +52,8 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
        /* -p option is not documented, it is needed to support NOMMU. */
 
        /* -t SECONDS; -p PARENT_PID */
-       opt_complementary = "t+" USE_FOR_NOMMU(":p+");
        /* '+': stop at first non-option */
-       getopt32(argv, "+s:t:" USE_FOR_NOMMU("p:"), &opt_s, &timeout, &parent);
+       getopt32(argv, "+s:t:+" USE_FOR_NOMMU("p:+"), &opt_s, &timeout, &parent);
        /*argv += optind; - no, wait for bb_daemonize_or_rexec! */
        signo = get_signum(opt_s);
        if (signo < 0)
@@ -71,9 +76,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
        sv1 = argv[optind];
        sv2 = argv[optind + 1];
 #endif
-       pid = vfork();
-       if (pid < 0)
-               bb_perror_msg_and_die("vfork");
+       pid = xvfork();
        if (pid == 0) {
                /* Child: spawn grandchild and exit */
                parent = getppid();
@@ -85,7 +88,7 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
                bb_daemonize_or_rexec(0, argv);
                /* Here we are grandchild. Sleep, then kill grandparent */
  grandchild:
-               /* Just sleep(NUGE_NUM); kill(parent) may kill wrong process! */
+               /* Just sleep(HUGE_NUM); kill(parent) may kill wrong process! */
                while (1) {
                        sleep(1);
                        if (--timeout <= 0)
@@ -110,6 +113,5 @@ int timeout_main(int argc UNUSED_PARAM, char **argv)
        argv[0] = sv1;
        argv[1] = sv2;
 #endif
-       BB_EXECVP(argv[0], argv);
-       bb_perror_msg_and_die("can't execute '%s'", argv[0]);
+       BB_EXECVP_or_die(argv);
 }