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.1 by pajs, Mon Jan 23 11:16:32 2006 UTC vs.
Revision 1.3 by pajs, Tue Jan 24 20:15:25 2006 UTC

# Line 19 | Line 19
19   */
20  
21   #include <stdio.h>
22 < #include <glib.h>
22 > #include <stdlib.h>
23   #include <unistd.h>
24 + #include <string.h>
25 + #include <glib.h>
26 + #include <glib/gprintf.h>
27   #include <poll.h>
28  
29   #define DEFNUMTHREAD 10
# Line 51 | Line 54 | static gchar *command = NULL;
54   static gchar *outdir = NULL;
55   static gchar *infile = NULL;
56   static gchar *arglist = NULL;
54 static gchar *stdindata = NULL;
57  
58   /* Command line options */
59   static GOptionEntry options[] =
# Line 83 | Line 85 | void process_child(gpointer data, gpointer user_data){
85          struct pollfd fds[3];
86          gint fdssize=2;
87  
88 <        /*if((pipe(outpipes)) != 0){
89 <                g_printerr("Failed to create pipe\n");
88 <                return ;
89 <        }*/
88 >        proc->timer = g_timer_new();
89 >        g_timer_start(proc->timer);
90  
91          /* Setup files in output dir if requested to do so */
92          if(outdir != NULL){
# Line 165 | Line 165 | void process_child(gpointer data, gpointer user_data){
165                  poll(fds, fdssize, -1);
166                  /* For stdout and stderr see if there is any data, and read it */
167                  for(x=0; x<2; x++){
168 <                        if(fds[x].revents|POLLIN == fds[x].revents){
168 >                        if((fds[x].revents & POLLIN) == 0){
169                                  /* We have data to read */
170                                  g_io_channel_read_line(sout[x], &readbuf, &rdatasize, NULL, NULL);
171                                  if(rdatasize > 0){
# Line 183 | Line 183 | void process_child(gpointer data, gpointer user_data){
183                          }
184                  }
185                  /* See if we need to pump more data down stdin */
186 <                if(fds[2].revents|POLLOUT == fds[2].revents){
186 >                if((fds[2].revents & POLLOUT) != 0){
187                          /* We have data we can write */
188                          gchar *nextline;
189                          gint nextlinesize;
# Line 193 | Line 193 | void process_child(gpointer data, gpointer user_data){
193                          /* Get the next line, and write it down the stream */
194                          s = g_io_channel_read_line(sinfile, &nextline, &nextlinesize, NULL, NULL);
195                          if (nextlinesize > 0){
196                                printf("Going to write '%s'\n", nextline);
196                                  g_io_channel_write_chars(sin, nextline, nextlinesize, &nextlinewritesize, NULL);
197                          }
198                          if (s == G_IO_STATUS_EOF){
199                                  g_io_channel_shutdown(sin, TRUE, NULL);
200 <                                sin == NULL;
200 >                                sin = NULL;
201                                  fdssize=2;
202                          }
203  
# Line 206 | Line 205 | void process_child(gpointer data, gpointer user_data){
205                  /* Even if we did get a hangup - lets make sure there is no more data to read first by looping again */
206                  if (readdata) continue;
207  
208 <                if((fds[0].revents|POLLHUP == fds[0].revents) && (fds[1].revents|POLLHUP == fds[1].revents)) break;
208 >                if(((fds[0].revents & POLLHUP) != 0) && ((fds[1].revents & POLLHUP) != 0)) break;
209          }      
210  
211 <        /* For some batty reason, it starts with a ref count of 1. Lets decrement it so we can shut it */
213 <        /*g_io_channel_unref(sout[0]);
214 <        g_io_channel_unref(sout[1]);*/
211 >        g_timer_stop(proc->timer);
212  
216
213          g_io_channel_shutdown(sout[0], TRUE, NULL);
214          g_io_channel_shutdown(sout[1], TRUE, NULL);
219        /*close(outpipes[0]);
220        close(outpipes[1]);*/
215  
222        /* BUG - Causes glib error saying its already closed */
216          if((infile != NULL) && (sin != NULL)){
217                  g_io_channel_shutdown(sin, TRUE, NULL);
218          }
# Line 270 | Line 263 | gchar *strrep(gchar *str, gchar *find, gchar *replace)
263   * and a line for doign the substitution with. Fills in jobname
264   */
265   gchar *genexeccmd(gchar *cmd, gchar *fmt, gchar *line, gchar **jobname){
273        gchar **fmttok;
266          gchar *newexec, *ptr;
267          int x;
268          gchar *linesep = " ";
# Line 402 | Line 394 | int main(int argc, char **argv){
394          /* Wait for the jobs to finish */
395          /* TODO - Kill jobs that don't finish in time */
396          while(g_thread_pool_get_num_threads(procpool) > 0){
397 <                sleep(1);
397 >                g_usleep(1000);
398          }
399  
400          return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines