From: Martin Mares Date: Thu, 8 Apr 2004 22:18:19 +0000 (+0000) Subject: More enhancement to the main loop library: Export all lists for easy inspection X-Git-Tag: holmes-import~1087 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=145922abfddde52698aa151c720d67c8adfb2c9d;p=libucw.git More enhancement to the main loop library: Export all lists for easy inspection (reading only) by the callers. When a process exits, construct a nice tombstone string for it. --- diff --git a/lib/mainloop.c b/lib/mainloop.c index 11ef1baa..95709a31 100644 --- a/lib/mainloop.c +++ b/lib/mainloop.c @@ -12,6 +12,7 @@ #include "lib/lib.h" #include "lib/mainloop.h" +#include #include #include #include @@ -25,7 +26,7 @@ sh_time_t now; uns main_shutdown; -static clist main_timer_list, main_file_list, main_hook_list, main_process_list; +clist main_timer_list, main_file_list, main_hook_list, main_process_list; static uns main_file_cnt; static uns main_poll_table_obsolete, main_poll_table_size; static struct pollfd *main_poll_table; @@ -357,6 +358,17 @@ 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); DBG("MAIN: Calling process exit handler"); pr->handler(pr); break; diff --git a/lib/mainloop.h b/lib/mainloop.h index 3cddb418..67a7fcd8 100644 --- a/lib/mainloop.h +++ b/lib/mainloop.h @@ -11,6 +11,7 @@ extern sh_time_t now; /* Current time */ extern uns main_shutdown; +extern clist main_timer_list, main_file_list, main_hook_list, main_process_list; /* User-defined fields are marked with [*], all other fields must be initialized to zero. */ @@ -75,6 +76,7 @@ struct main_process { cnode n; int pid; int status; /* Exit status */ + byte status_msg[32]; void (*handler)(struct main_process *mp); /* [*] Called when the process exits; process_del done automatically */ void *data; /* [*] For use by the handler */ };