/** Store the status of the process pid that was returned by waitpid. Return 0 if all went well, nonzero otherwise. This is called from a signal handler. */ static void mark_process_status(const job_t *j, process_t *p, int status) { // debug( 0, L"Process %ls %ls", p->argv[0], WIFSTOPPED (status)?L"stopped":(WIFEXITED( status )?L"exited":(WIFSIGNALED( status )?L"signaled to exit":L"BLARGH")) ); p->status = status; if (WIFSTOPPED(status)) { p->stopped = 1; } else if (WIFSIGNALED(status) || WIFEXITED(status)) { p->completed = 1; } else { /* This should never be reached */ p->completed = 1; char mess[MESS_SIZE]; snprintf(mess, MESS_SIZE, "Process %ld exited abnormally\n", (long) p->pid); /* If write fails, do nothing. We're in a signal handlers error handler. If things aren't working properly, it's safer to give up. */ write_ignore(2, mess, strlen(mess)); } }
void safe_perror(const char *message) { // Note we cannot use strerror, because on Linux it uses gettext, which is not safe. int err = errno; char buff[384]; buff[0] = '\0'; if (message) { safe_append(buff, message, sizeof buff); safe_append(buff, ": ", sizeof buff); } safe_append(buff, safe_strerror(err), sizeof buff); safe_append(buff, "\n", sizeof buff); write_ignore(STDERR_FILENO, buff, strlen(buff)); errno = err; }