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 |
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[] = |
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){ |
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){ |
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; |
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 |
|
|
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 |
|
} |
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 = " "; |
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; |