From: Martin Mares Date: Sat, 10 Apr 2004 14:45:47 +0000 (+0000) Subject: Use format_exit_status(). One more ASSERT. X-Git-Tag: holmes-import~1081 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=623ac4972bd717007ef7d672dbe9fb265e3f8a3a;p=libucw.git Use format_exit_status(). One more ASSERT. --- diff --git a/lib/mainloop.c b/lib/mainloop.c index 93cea343..c83c9262 100644 --- a/lib/mainloop.c +++ b/lib/mainloop.c @@ -254,9 +254,16 @@ process_del(struct main_process *mp) int process_fork(struct main_process *mp) { + ASSERT(!mp->pid); pid_t pid = fork(); if (pid < 0) - return -1; + { + DBG("MAIN: Fork failed"); + mp->status = -1; + format_exit_status(mp->status_msg, -1); + mp->handler(mp); + return 1; + } else if (!pid) return 0; else @@ -359,17 +366,7 @@ main_loop(void) { pr->status = stat; process_del(pr); - if (WIFEXITED(stat) && WEXITSTATUS(stat) < 256) - { - if (WEXITSTATUS(stat)) - sprintf(pr->status_msg, "died with exit code %d", WEXITSTATUS(stat)); - else - pr->status_msg[0] = 0; - } - else if (WIFSIGNALED(stat)) - sprintf(pr->status_msg, "died on signal %d", WTERMSIG(stat)); - else - sprintf(pr->status_msg, "died with status %x", stat); + format_exit_status(pr->status_msg, pr->status); DBG("MAIN: Calling process exit handler"); pr->handler(pr); break; diff --git a/lib/mainloop.h b/lib/mainloop.h index 67a7fcd8..ffbf4e4d 100644 --- a/lib/mainloop.h +++ b/lib/mainloop.h @@ -74,9 +74,9 @@ void hook_del(struct main_hook *ho); struct main_process { cnode n; - int pid; - int status; /* Exit status */ - byte status_msg[32]; + int pid; /* Process id (0=not running) */ + int status; /* Exit status (-1=fork failed) */ + byte status_msg[EXIT_STATUS_MSG_SIZE]; void (*handler)(struct main_process *mp); /* [*] Called when the process exits; process_del done automatically */ void *data; /* [*] For use by the handler */ };