--- projects/pjob/pjob.c 2006/01/24 20:15:25 1.3 +++ projects/pjob/pjob.c 2006/01/25 19:57:12 1.4 @@ -25,6 +25,8 @@ #include #include #include +#include +#include #define DEFNUMTHREAD 10 #define DEFTIMEOUT 60 @@ -35,6 +37,7 @@ struct _process_t{ gchar *jobname; GTimer *timer; GPid pid; + gint stat_loc; gchar *file_stdout; gchar *file_stderr; @@ -124,12 +127,12 @@ void process_child(gpointer data, gpointer user_data){ /* Exec the job */ if (infile == NULL){ - if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, 0, NULL, NULL, &(proc->pid), NULL, &(outpipes[0]), &(outpipes[1]), &err)){ + if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &(proc->pid), NULL, &(outpipes[0]), &(outpipes[1]), &err)){ g_printerr("Failed to execute job %s: %s\n", proc->jobname, err->message); return; } }else{ - if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, 0, NULL, NULL, &(proc->pid), &(inpipes[1]), &(outpipes[0]), &(outpipes[1]), &err)){ + if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &(proc->pid), &(inpipes[1]), &(outpipes[0]), &(outpipes[1]), &err)){ g_printerr("Failed to execute job %s: %s\n", proc->jobname, err->message); return; } @@ -208,8 +211,24 @@ void process_child(gpointer data, gpointer user_data){ if(((fds[0].revents & POLLHUP) != 0) && ((fds[1].revents & POLLHUP) != 0)) break; } + while((waitpid(proc->pid, &(proc->stat_loc), 0)) != proc->pid); + g_timer_stop(proc->timer); + /* If process exited cleanly */ + if (WIFEXITED(proc->stat_loc)){ + /* Get the exit code */ + if (verbose) g_fprintf(stderr, "Job '%s' exited with code %d. Exec time: %.2f\n", proc->jobname, WEXITSTATUS(proc->stat_loc), g_timer_elapsed(proc->timer, 0)); + }else{ + /* Otherwise - find out what it died with */ + /* TODO - this doesn't work quite right.. Mainly because its looking at the shell process, so the + * child of the /bin/sh which does get a signal, this isn't passed up. Although, it handly tells + * us if the /bin/sh gets a SEGV etc ;) + */ + g_fprintf(stderr, "Job %s exited with signal %d. Exec time: %.2f\n", proc->jobname, (WTERMSIG(proc->stat_loc)), g_timer_elapsed(proc->timer, 0)); + } + + g_io_channel_shutdown(sout[0], TRUE, NULL); g_io_channel_shutdown(sout[1], TRUE, NULL); @@ -223,7 +242,6 @@ void process_child(gpointer data, gpointer user_data){ g_spawn_close_pid(proc->pid); - if (verbose) g_fprintf(stderr, "Ending job '%s'\n", proc->jobname); }