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.2 by pajs, Mon Jan 23 22:12:39 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  
86        /*if((pipe(outpipes)) != 0){
87                g_printerr("Failed to create pipe\n");
88                return ;
89        }*/
90
88          /* Setup files in output dir if requested to do so */
89          if(outdir != NULL){
90                  proc->file_stdout = g_strdup_printf("%s/%s-STDOUT", outdir, proc->jobname);
# Line 165 | Line 162 | void process_child(gpointer data, gpointer user_data){
162                  poll(fds, fdssize, -1);
163                  /* For stdout and stderr see if there is any data, and read it */
164                  for(x=0; x<2; x++){
165 <                        if(fds[x].revents|POLLIN == fds[x].revents){
165 >                        if((fds[x].revents|POLLIN) == fds[x].revents){
166                                  /* We have data to read */
167                                  g_io_channel_read_line(sout[x], &readbuf, &rdatasize, NULL, NULL);
168                                  if(rdatasize > 0){
# Line 183 | Line 180 | void process_child(gpointer data, gpointer user_data){
180                          }
181                  }
182                  /* See if we need to pump more data down stdin */
183 <                if(fds[2].revents|POLLOUT == fds[2].revents){
183 >                if((fds[2].revents|POLLOUT) == fds[2].revents){
184                          /* We have data we can write */
185                          gchar *nextline;
186                          gint nextlinesize;
# Line 193 | Line 190 | void process_child(gpointer data, gpointer user_data){
190                          /* Get the next line, and write it down the stream */
191                          s = g_io_channel_read_line(sinfile, &nextline, &nextlinesize, NULL, NULL);
192                          if (nextlinesize > 0){
196                                printf("Going to write '%s'\n", nextline);
193                                  g_io_channel_write_chars(sin, nextline, nextlinesize, &nextlinewritesize, NULL);
194                          }
195                          if (s == G_IO_STATUS_EOF){
196                                  g_io_channel_shutdown(sin, TRUE, NULL);
197 <                                sin == NULL;
197 >                                sin = NULL;
198                                  fdssize=2;
199                          }
200  
# Line 206 | Line 202 | void process_child(gpointer data, gpointer user_data){
202                  /* Even if we did get a hangup - lets make sure there is no more data to read first by looping again */
203                  if (readdata) continue;
204  
205 <                if((fds[0].revents|POLLHUP == fds[0].revents) && (fds[1].revents|POLLHUP == fds[1].revents)) break;
205 >                if(((fds[0].revents|POLLHUP) == fds[0].revents) && ((fds[1].revents|POLLHUP) == fds[1].revents)) break;
206          }      
207  
212        /* 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]);*/
215
216
208          g_io_channel_shutdown(sout[0], TRUE, NULL);
209          g_io_channel_shutdown(sout[1], TRUE, NULL);
219        /*close(outpipes[0]);
220        close(outpipes[1]);*/
210  
222        /* BUG - Causes glib error saying its already closed */
211          if((infile != NULL) && (sin != NULL)){
212                  g_io_channel_shutdown(sin, TRUE, NULL);
213          }
# Line 270 | Line 258 | gchar *strrep(gchar *str, gchar *find, gchar *replace)
258   * and a line for doign the substitution with. Fills in jobname
259   */
260   gchar *genexeccmd(gchar *cmd, gchar *fmt, gchar *line, gchar **jobname){
273        gchar **fmttok;
261          gchar *newexec, *ptr;
262          int x;
263          gchar *linesep = " ";
# Line 402 | Line 389 | int main(int argc, char **argv){
389          /* Wait for the jobs to finish */
390          /* TODO - Kill jobs that don't finish in time */
391          while(g_thread_pool_get_num_threads(procpool) > 0){
392 <                sleep(1);
392 >                g_usleep(1000);
393          }
394  
395          return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines