Ejemplo n.º 1
0
/*
 * Collect the exit status of the child process
 */
static int
ni_process_reap(ni_process_t *pi)
{
	int rv;

	if (pi->pid == 0) {
		ni_error("%s: child already reaped", __func__);
		return 0;
	}

	rv = waitpid(pi->pid, &pi->status, WNOHANG);
	if (rv == 0) {
		/* This is an ugly workaround. Sometimes, we seem to get a hangup on the socket even
		 * though the script (provably) still has its end of the socket pair open for writing. */
		ni_error("%s: process %u has not exited yet; now doing a blocking waitpid()", __func__, pi->pid);
		rv = waitpid(pi->pid, &pi->status, 0);
	}

	if (rv < 0) {
		ni_error("%s: waitpid returns error (%m)", __func__);
		return -1;
	}

	if (WIFEXITED(pi->status))
		ni_debug_extension("subprocess %d (%s) exited with status %d",
				pi->pid, pi->process->command,
				WEXITSTATUS(pi->status));
	else if (WIFSIGNALED(pi->status))
		ni_debug_extension("subprocess %d (%s) died with signal %d%s",
				pi->pid, pi->process->command,
				WTERMSIG(pi->status),
				WCOREDUMP(pi->status)? " (core dumped)" : "");
	else
		ni_debug_extension("subprocess %d (%s) transcended into nirvana",
				pi->pid, pi->process->command);
	pi->pid = 0;

	if (pi->notify_callback)
		pi->notify_callback(pi);

	return 0;
}
Ejemplo n.º 2
0
static int
__ni_process_run_info(ni_process_t *pi)
{
	int rv;

	if ((rv = ni_process_exit_status(pi)) != NI_PROCESS_FAILURE) {
		ni_debug_extension("subprocess %d (%s) exited with status %d",
				pi->pid, pi->process->command, rv);
		return rv;
	} else
	if ((rv = ni_process_signaled(pi)) != NI_PROCESS_FAILURE) {
		ni_debug_extension("subprocess %d (%s) died with signal %d%s",
				pi->pid, pi->process->command, rv,
				ni_process_core_dumped(pi) ? " (core dumped)" : "");
		return NI_PROCESS_TERMSIG;
	} else {
		ni_debug_extension("subprocess %d (%s) transcended into nirvana",
				pi->pid, pi->process->command);
		return NI_PROCESS_UNKNOWN;
	}
}