ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/pjob/pjob.c
(Generate patch)

Comparing projects/pjob/pjob.c (file contents):
Revision 1.3 by pajs, Tue Jan 24 20:15:25 2006 UTC vs.
Revision 1.4 by pajs, Wed Jan 25 19:57:12 2006 UTC

# Line 25 | Line 25
25   #include <glib.h>
26   #include <glib/gprintf.h>
27   #include <poll.h>
28 + #include <sys/types.h>
29 + #include <sys/wait.h>
30  
31   #define DEFNUMTHREAD 10
32   #define DEFTIMEOUT 60
# Line 35 | Line 37 | struct _process_t{
37          gchar *jobname;
38          GTimer *timer;
39          GPid pid;
40 +        gint stat_loc;
41          gchar *file_stdout;
42          gchar *file_stderr;
43  
# Line 124 | Line 127 | void process_child(gpointer data, gpointer user_data){
127  
128          /* Exec the job */
129          if (infile == NULL){
130 <                if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, 0, NULL, NULL, &(proc->pid), NULL, &(outpipes[0]), &(outpipes[1]), &err)){
130 >                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)){
131                          g_printerr("Failed to execute job %s: %s\n", proc->jobname, err->message);
132                          return;
133                  }
134          }else{
135 <                if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, 0, NULL, NULL, &(proc->pid), &(inpipes[1]), &(outpipes[0]), &(outpipes[1]), &err)){
135 >                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)){
136                          g_printerr("Failed to execute job %s: %s\n", proc->jobname, err->message);
137                          return;
138                  }
# Line 208 | Line 211 | void process_child(gpointer data, gpointer user_data){
211                  if(((fds[0].revents & POLLHUP) != 0) && ((fds[1].revents & POLLHUP) != 0)) break;
212          }      
213  
214 +        while((waitpid(proc->pid, &(proc->stat_loc), 0)) != proc->pid);
215 +
216          g_timer_stop(proc->timer);
217  
218 +        /* If process exited cleanly */
219 +        if (WIFEXITED(proc->stat_loc)){
220 +                /* Get the exit code */
221 +                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));
222 +        }else{
223 +                /* Otherwise - find out what it died with */
224 +                /* TODO - this doesn't work quite right.. Mainly because its looking at the shell process, so the
225 +                 * child of the /bin/sh which does get a signal, this isn't passed up. Although, it handly tells
226 +                 * us if the /bin/sh gets a SEGV etc ;)
227 +                 */
228 +                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));
229 +        }
230 +
231 +
232          g_io_channel_shutdown(sout[0], TRUE, NULL);
233          g_io_channel_shutdown(sout[1], TRUE, NULL);
234  
# Line 223 | Line 242 | void process_child(gpointer data, gpointer user_data){
242  
243          g_spawn_close_pid(proc->pid);
244  
226        if (verbose) g_fprintf(stderr, "Ending job '%s'\n", proc->jobname);
245  
246   }
247  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines