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 |
37 |
|
gchar *jobname; |
38 |
|
GTimer *timer; |
39 |
|
GPid pid; |
40 |
+ |
gint stat_loc; |
41 |
|
gchar *file_stdout; |
42 |
|
gchar *file_stderr; |
43 |
|
|
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 |
|
} |
168 |
|
poll(fds, fdssize, -1); |
169 |
|
/* For stdout and stderr see if there is any data, and read it */ |
170 |
|
for(x=0; x<2; x++){ |
171 |
< |
if((fds[x].revents & POLLIN) == 0){ |
171 |
> |
if((fds[x].revents & POLLIN) != 0){ |
172 |
|
/* We have data to read */ |
173 |
|
g_io_channel_read_line(sout[x], &readbuf, &rdatasize, NULL, NULL); |
174 |
|
if(rdatasize > 0){ |
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 |
|
|
242 |
|
|
243 |
|
g_spawn_close_pid(proc->pid); |
244 |
|
|
226 |
– |
if (verbose) g_fprintf(stderr, "Ending job '%s'\n", proc->jobname); |
245 |
|
|
246 |
|
} |
247 |
|
|