Example #1
0
static void
waitchildren(const char *name, int waitall)
{
	pid_t pid;
	int status;

	while ((pid = xwait(waitall || pids_full(), &status)) > 0) {
		/* If we couldn't invoke the utility, exit. */
		if (childerr != 0) {
			errno = childerr;
			err(errno == ENOENT ? 127 : 126, "%s", name);
		}
		/*
		 * If utility signaled or exited with a value of 255,
		 * exit 1-125.
		 */
		if (WIFSIGNALED(status))
			errx(1, "%s: terminated with signal %d, aborting",
			    name, WTERMSIG(status));
		if (WEXITSTATUS(status) == 255)
			errx(1, "%s: exited with status 255, aborting", name);
		if (WEXITSTATUS(status))
			rval = 1;
	}

	if (pid == -1 && errno != ECHILD)
		err(1, "waitpid");
}
Example #2
0
static void
waitchildren(const char *name, int waitall)
{
	pid_t pid;
	int status;
	int cause_exit = 0;

	while ((pid = xwait(waitall || pids_full(), &status)) > 0) {
		/*
		 * If we couldn't invoke the utility or if utility exited
		 * because of a signal or with a value of 255, warn (per
		 * POSIX), and then wait until all other children have
		 * exited before exiting 1-125. POSIX requires us to stop
		 * reading if child exits because of a signal or with 255,
		 * but it does not require us to exit immediately; waiting
		 * is preferable to orphaning.
		 */
		if (childerr != 0 && cause_exit == 0) {
			errno = childerr;
			waitall = 1;
			cause_exit = ENOENT ? 127 : 126;
			warn("%s", name);
		} else if (WIFSIGNALED(status)) {
			waitall = cause_exit = 1;
			warnx("%s: terminated with signal %d; aborting",
			    name, WTERMSIG(status));
		} else if (WEXITSTATUS(status) == 255) {
			waitall = cause_exit = 1;
			warnx("%s: exited with status 255; aborting", name);
		} else if (WEXITSTATUS(status))
 			rval = 1;
	}

 	if (cause_exit)
		exit(cause_exit);
	if (pid == -1 && errno != ECHILD)
		err(1, "waitpid");
}