continue;
}
cmd[0] = name;
- ret = wait4pid(spawn(cmd));
+ ret = spawn_and_wait(cmd);
if (ret == 0)
continue;
n = 1;
if (ret < 0)
bb_perror_msg("can't execute '%s'", name);
else /* ret > 0 */
- bb_error_msg("%s exited with code %d", name, ret);
+ bb_error_msg("%s exited with code %d", name, ret & 0xff);
}
return n;
bb_error_msg("%s: exited with status 255; aborting", args[0]);
return 124;
}
-/* Huh? I think we won't see this, ever. We don't wait with WUNTRACED!
- if (WIFSTOPPED(status)) {
- bb_error_msg("%s: stopped by signal %d",
- args[0], WSTOPSIG(status));
- return 125;
- }
-*/
- if (status >= 1000) {
+ if (status >= 0x180) {
bb_error_msg("%s: terminated by signal %d",
- args[0], status - 1000);
+ args[0], status - 0x180);
return 125;
}
if (status)
#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__)
#endif
-/* NOMMU friendy fork+exec */
+/* NOMMU friendy fork+exec: */
pid_t spawn(char **argv) FAST_FUNC;
pid_t xspawn(char **argv) FAST_FUNC;
pid_t safe_waitpid(pid_t pid, int *wstat, int options) FAST_FUNC;
-/* Unlike waitpid, waits ONLY for one process.
+pid_t wait_any_nohang(int *wstat) FAST_FUNC;
+/* wait4pid: unlike waitpid, waits ONLY for one process.
+ * Returns sig + 0x180 if child is killed by signal.
* It's safe to pass negative 'pids' from failed [v]fork -
* wait4pid will return -1 (and will not clobber [v]fork's errno).
* IOW: rc = wait4pid(spawn(argv));
* if (rc < 0) bb_perror_msg("%s", argv[0]);
- * if (rc > 0) bb_error_msg("exit code: %d", rc);
+ * if (rc > 0) bb_error_msg("exit code: %d", rc & 0xff);
*/
int wait4pid(pid_t pid) FAST_FUNC;
-pid_t wait_any_nohang(int *wstat) FAST_FUNC;
-/* wait4pid(spawn(argv)) + NOFORK/NOEXEC (if configured) */
+/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
int spawn_and_wait(char **argv) FAST_FUNC;
struct nofork_save_area {
jmp_buf die_jmp;
if (WIFEXITED(status))
return WEXITSTATUS(status);
if (WIFSIGNALED(status))
- return WTERMSIG(status) + 1000;
+ return WTERMSIG(status) + 0x180;
return 0;
}
if (opts & OPT_X) {
signal(SIGPIPE, SIG_DFL);
// exit if helper exited >0
- rc = wait4pid(pid);
+ rc = (wait4pid(pid) & 0xff);
if (rc)
return rc+20;
}
argv[4] = concat_path_file("/dev", info->devname); /* device */
argv[5] = NULL;
- wait4pid(xspawn(argv));
+ spawn_and_wait(argv);
free(argv[4]);
} /* End Function action_modload */
argv[count] = largv[count];
}
argv[count] = NULL;
- wait4pid(spawn(argv));
+ spawn_and_wait(argv);
} /* End Function action_execute */
args[1] = events;
args[2] = watches[ie->wd];
args[3] = ie->len ? ie->name : NULL;
- wait4pid(xspawn((char **)args));
+ spawn_and_wait((char **)args);
// we are done if all files got final x event
if (ie->mask & 0x8000) {
if (--argc <= 0)
argv[3] = (char*) G.extra_arg;
argv[4] = NULL;
- /* r < 0 - can't exec, 0 <= r < 1000 - exited, >1000 - killed by sig (r-1000) */
- r = wait4pid(spawn(argv));
+ /* r < 0 - can't exec, 0 <= r < 0x180 - exited, >=0x180 - killed by sig (r-0x180) */
+ r = spawn_and_wait(argv);
- bb_error_msg("exit code: %d", r);
+ bb_error_msg("exit code: %d", r & 0xff);
return (option_mask32 & FLAG_IGNORE_RETVAL) ? 0 : r;
#else /* insanity */
/* Don't want to wait: it may run hwclock --systohc, and that
* may take some time (seconds): */
- /*wait4pid(spawn(argv));*/
+ /*spawn_and_wait(argv);*/
spawn(argv);
unsetenv("stratum");
argv[0] = (char*) client_config.script;
argv[1] = (char*) name;
argv[2] = NULL;
- wait4pid(spawn(argv));
+ spawn_and_wait(argv);
for (curr = envp; *curr; curr++) {
log2(" %s", *curr);
}
bb_info_msg(fmt, argv[2], argv[0], addr);
- status = wait4pid(spawn(argv + 1));
+ status = spawn_and_wait(argv + 1);
if (status < 0) {
bb_perror_msg("%s %s %s" + 3, argv[2], argv[0]);
return -errno;
}
if (status != 0)
- bb_error_msg("script %s %s failed, exitcode=%d", argv[1], argv[2], status);
+ bb_error_msg("script %s %s failed, exitcode=%d", argv[1], argv[2], status & 0xff);
return status;
}
args[rc++] = filteropts;
}
args[rc] = NULL;
- rc = wait4pid(spawn(args));
+ rc = spawn_and_wait(args);
free(args[0]);
if (!rc)
break;
}
args[n++] = mp->mnt_dir;
args[n] = NULL;
- rc = wait4pid(xspawn(args));
+ rc = spawn_and_wait(args);
goto report_error;
}