]> mj.ucw.cz Git - libucw.git/commitdiff
More enhancement to the main loop library: Export all lists for easy inspection
authorMartin Mares <mj@ucw.cz>
Thu, 8 Apr 2004 22:18:19 +0000 (22:18 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 8 Apr 2004 22:18:19 +0000 (22:18 +0000)
(reading only) by the callers. When a process exits, construct a nice tombstone
string for it.

lib/mainloop.c
lib/mainloop.h

index 11ef1baacb95690a9c157cfcb74710bde3f6e757..95709a311a0c08743015950e6c84f6160098e26b 100644 (file)
@@ -12,6 +12,7 @@
 #include "lib/lib.h"
 #include "lib/mainloop.h"
 
+#include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -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;
index 3cddb4185a73921b29ed0d0bd57a4784c6329e94..67a7fcd88d78cfc930ea55b9a20cc2dd34f112c9 100644 (file)
@@ -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 */
 };