--- projects/pjob/pjob.c 2006/01/23 11:16:32 1.1 +++ projects/pjob/pjob.c 2006/01/23 22:12:39 1.2 @@ -19,8 +19,11 @@ */ #include -#include +#include #include +#include +#include +#include #include #define DEFNUMTHREAD 10 @@ -51,7 +54,6 @@ static gchar *command = NULL; static gchar *outdir = NULL; static gchar *infile = NULL; static gchar *arglist = NULL; -static gchar *stdindata = NULL; /* Command line options */ static GOptionEntry options[] = @@ -83,11 +85,6 @@ void process_child(gpointer data, gpointer user_data){ struct pollfd fds[3]; gint fdssize=2; - /*if((pipe(outpipes)) != 0){ - g_printerr("Failed to create pipe\n"); - return ; - }*/ - /* Setup files in output dir if requested to do so */ if(outdir != NULL){ proc->file_stdout = g_strdup_printf("%s/%s-STDOUT", outdir, proc->jobname); @@ -165,7 +162,7 @@ void process_child(gpointer data, gpointer user_data){ poll(fds, fdssize, -1); /* For stdout and stderr see if there is any data, and read it */ for(x=0; x<2; x++){ - if(fds[x].revents|POLLIN == fds[x].revents){ + if((fds[x].revents|POLLIN) == fds[x].revents){ /* We have data to read */ g_io_channel_read_line(sout[x], &readbuf, &rdatasize, NULL, NULL); if(rdatasize > 0){ @@ -183,7 +180,7 @@ void process_child(gpointer data, gpointer user_data){ } } /* See if we need to pump more data down stdin */ - if(fds[2].revents|POLLOUT == fds[2].revents){ + if((fds[2].revents|POLLOUT) == fds[2].revents){ /* We have data we can write */ gchar *nextline; gint nextlinesize; @@ -193,12 +190,11 @@ void process_child(gpointer data, gpointer user_data){ /* Get the next line, and write it down the stream */ s = g_io_channel_read_line(sinfile, &nextline, &nextlinesize, NULL, NULL); if (nextlinesize > 0){ - printf("Going to write '%s'\n", nextline); g_io_channel_write_chars(sin, nextline, nextlinesize, &nextlinewritesize, NULL); } if (s == G_IO_STATUS_EOF){ g_io_channel_shutdown(sin, TRUE, NULL); - sin == NULL; + sin = NULL; fdssize=2; } @@ -206,20 +202,12 @@ void process_child(gpointer data, gpointer user_data){ /* Even if we did get a hangup - lets make sure there is no more data to read first by looping again */ if (readdata) continue; - if((fds[0].revents|POLLHUP == fds[0].revents) && (fds[1].revents|POLLHUP == fds[1].revents)) break; + if(((fds[0].revents|POLLHUP) == fds[0].revents) && ((fds[1].revents|POLLHUP) == fds[1].revents)) break; } - /* For some batty reason, it starts with a ref count of 1. Lets decrement it so we can shut it */ - /*g_io_channel_unref(sout[0]); - g_io_channel_unref(sout[1]);*/ - - g_io_channel_shutdown(sout[0], TRUE, NULL); g_io_channel_shutdown(sout[1], TRUE, NULL); - /*close(outpipes[0]); - close(outpipes[1]);*/ - /* BUG - Causes glib error saying its already closed */ if((infile != NULL) && (sin != NULL)){ g_io_channel_shutdown(sin, TRUE, NULL); } @@ -270,7 +258,6 @@ gchar *strrep(gchar *str, gchar *find, gchar *replace) * and a line for doign the substitution with. Fills in jobname */ gchar *genexeccmd(gchar *cmd, gchar *fmt, gchar *line, gchar **jobname){ - gchar **fmttok; gchar *newexec, *ptr; int x; gchar *linesep = " "; @@ -402,7 +389,7 @@ int main(int argc, char **argv){ /* Wait for the jobs to finish */ /* TODO - Kill jobs that don't finish in time */ while(g_thread_pool_get_num_threads(procpool) > 0){ - sleep(1); + g_usleep(1000); } return 0;