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.6 by pajs, Mon Jan 30 21:46:59 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 + #include <sys/resource.h>
31  
32   #define DEFNUMTHREAD 10
33   #define DEFTIMEOUT 60
# Line 35 | Line 38 | struct _process_t{
38          gchar *jobname;
39          GTimer *timer;
40          GPid pid;
41 +        gint stat_loc;
42          gchar *file_stdout;
43          gchar *file_stderr;
44  
# Line 124 | Line 128 | void process_child(gpointer data, gpointer user_data){
128  
129          /* Exec the job */
130          if (infile == NULL){
131 <                if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, 0, NULL, NULL, &(proc->pid), NULL, &(outpipes[0]), &(outpipes[1]), &err)){
131 >                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)){
132                          g_printerr("Failed to execute job %s: %s\n", proc->jobname, err->message);
133                          return;
134                  }
135          }else{
136 <                if( ! g_spawn_async_with_pipes(NULL, execargv, NULL, 0, NULL, NULL, &(proc->pid), &(inpipes[1]), &(outpipes[0]), &(outpipes[1]), &err)){
136 >                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)){
137                          g_printerr("Failed to execute job %s: %s\n", proc->jobname, err->message);
138                          return;
139                  }
# Line 165 | Line 169 | void process_child(gpointer data, gpointer user_data){
169                  poll(fds, fdssize, -1);
170                  /* For stdout and stderr see if there is any data, and read it */
171                  for(x=0; x<2; x++){
172 <                        if((fds[x].revents & POLLIN) == 0){
172 >                        if((fds[x].revents & POLLIN) != 0){
173                                  /* We have data to read */
174                                  g_io_channel_read_line(sout[x], &readbuf, &rdatasize, NULL, NULL);
175                                  if(rdatasize > 0){
# Line 208 | Line 212 | void process_child(gpointer data, gpointer user_data){
212                  if(((fds[0].revents & POLLHUP) != 0) && ((fds[1].revents & POLLHUP) != 0)) break;
213          }      
214  
215 +        while((waitpid(proc->pid, &(proc->stat_loc), 0)) != proc->pid);
216 +
217          g_timer_stop(proc->timer);
218  
219 +        /* If process exited cleanly */
220 +        if (WIFEXITED(proc->stat_loc)){
221 +                /* Get the exit code */
222 +                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));
223 +        }else{
224 +                /* Otherwise - find out what it died with */
225 +                /* TODO - this doesn't work quite right.. Mainly because its looking at the shell process, so the
226 +                 * child of the /bin/sh which does get a signal, this isn't passed up. Although, it handly tells
227 +                 * us if the /bin/sh gets a SEGV etc ;)
228 +                 */
229 +                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));
230 +        }
231 +
232 +
233          g_io_channel_shutdown(sout[0], TRUE, NULL);
234          g_io_channel_shutdown(sout[1], TRUE, NULL);
235  
# Line 223 | Line 243 | void process_child(gpointer data, gpointer user_data){
243  
244          g_spawn_close_pid(proc->pid);
245  
226        if (verbose) g_fprintf(stderr, "Ending job '%s'\n", proc->jobname);
246  
247   }
248  
# Line 313 | Line 332 | int main(int argc, char **argv){
332          GError *pp_err = NULL, *err = NULL;
333          gint x;
334  
335 +        struct rlimit rlp;
336 +
337          GOptionContext *optcontext;
338  
339          optcontext = g_option_context_new(" - parallel job executer");
# Line 342 | Line 363 | int main(int argc, char **argv){
363          }else{
364                  g_printerr("Threading not supported\n");
365          }
366 +
367 +        /* Up the number of FD's to the "hard" limit.
368 +         * This is mainly to get around the very small default
369 +         * solaris has, or 256
370 +         */
371 +        getrlimit(RLIMIT_NOFILE, &rlp);
372 +        rlp.rlim_cur = rlp.rlim_max;
373 +        setrlimit(RLIMIT_NOFILE, &rlp);
374          
375          if(verbose) g_printerr("Creating a threadpool %d in size\n", numthreads);
376          procpool = g_thread_pool_new(process_child, NULL, numthreads, FALSE, &pp_err);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines