From 30ddb045dfaaf867bda7122d76ceb12d24d248e7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 22 May 2014 16:42:33 +0200 Subject: Rationalise and document stream "open for write" functions A nice side-effect is that streams now only have one set of headers --- src/im-sandbox.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/im-sandbox.c') diff --git a/src/im-sandbox.c b/src/im-sandbox.c index 3558c8ea..3e2ab2b3 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -74,8 +74,8 @@ struct sb_reader FILE **fhs; int *fds; - /* Final output fd */ - int ofd; + /* Final output */ + Stream *stream; }; @@ -376,6 +376,7 @@ static void remove_pipe(struct sb_reader *rd, int d) static void *run_reader(void *rdv) { struct sb_reader *rd = rdv; + const int ofd = get_stream_fd(rd->stream); while ( 1 ) { @@ -425,7 +426,7 @@ static void *run_reader(void *rdv) /* If the chunk cannot be read, assume the connection * is broken and that the process will die soon. */ - if ( pump_chunk(rd->fhs[i], rd->ofd) ) { + if ( pump_chunk(rd->fhs[i], ofd) ) { /* remove_pipe() assumes that the caller is * holding rd->lock ! */ remove_pipe(rd, i); @@ -440,8 +441,7 @@ static void *run_reader(void *rdv) } -static void start_worker_process(struct sandbox *sb, int slot, - int argc, char *argv[]) +static void start_worker_process(struct sandbox *sb, int slot) { pid_t p; int filename_pipe[2]; @@ -537,8 +537,6 @@ static void start_worker_process(struct sandbox *sb, int slot, close(result_pipe[0]); st = open_stream_fd_for_write(stream_pipe[1]); - write_command(st, argc, argv); - write_line(st, "FLUSH"); run_work(sb->iargs, filename_pipe[0], result_pipe[1], st, slot, tmp); close_stream(st); @@ -606,7 +604,7 @@ static void handle_zombie(struct sandbox *sb) STATUS("Last filename was: %s\n", sb->last_filename[i]); sb->n_processed++; - start_worker_process(sb, i, 0, NULL); + start_worker_process(sb, i); } } @@ -618,7 +616,7 @@ static void handle_zombie(struct sandbox *sb) void create_sandbox(struct index_args *iargs, int n_proc, char *prefix, int config_basename, FILE *fh, - int ofd, int argc, char *argv[], const char *tempdir) + Stream *stream, const char *tempdir) { int i; int allDone; @@ -657,7 +655,7 @@ void create_sandbox(struct index_args *iargs, int n_proc, char *prefix, sb->reader->fds = NULL; sb->reader->fhs = NULL; - sb->reader->ofd = ofd; + sb->reader->stream = stream; sb->stream_pipe_write = calloc(n_proc, sizeof(int)); if ( sb->stream_pipe_write == NULL ) { @@ -742,7 +740,7 @@ void create_sandbox(struct index_args *iargs, int n_proc, char *prefix, /* Fork the right number of times */ lock_sandbox(sb); for ( i=0; i