From 3627a2a69d8ca7f803286569d8fe770ab10bde77 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 29 May 2012 18:01:33 +0200 Subject: Fix select() call --- src/indexamajig.c | 94 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 45 deletions(-) (limited to 'src/indexamajig.c') diff --git a/src/indexamajig.c b/src/indexamajig.c index bb5be4b5..aab6a0eb 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -470,7 +470,6 @@ static void run_work(const struct index_args *iargs, char *rval; line = malloc(1024*sizeof(char)); - STATUS("Waiting for filename...\n"); rval = fgets(line, 1023, fh); if ( rval == NULL ) { free(line); @@ -482,8 +481,6 @@ static void run_work(const struct index_args *iargs, pargs.filename = line; pargs.indexable = 0; - STATUS("Got filename: '%s'\n", line); - process_image(iargs, &pargs, cookie); /* Request another image */ @@ -1070,8 +1067,6 @@ int main(int argc, char *argv[]) filename_pipes[i] = filename_pipe[1]; result_pipes[i] = result_pipe[0]; - FD_SET(result_pipes[i], &fds); - } /* Send first image to all children */ @@ -1093,63 +1088,72 @@ int main(int argc, char *argv[]) nFinished = 0; while ( !allDone ) { - int r; + int r, i; struct timeval tv; - fd_set fds_copy; + fd_set fds; double tNow; + int fdmax; tv.tv_sec = 5; tv.tv_usec = 0; - memcpy(&fds_copy, &fds, sizeof(fd_set)); - r = select(n_proc, &fds, NULL, NULL, &tv); + FD_ZERO(&fds); + fdmax = 0; + for ( i=0; i fdmax ) { + fdmax = result_pipes[i]; + } + } - if ( r < 0 ) { + r = select(fdmax+1, &fds, NULL, NULL, &tv); + if ( r == -1 ) { ERROR("select() failed!\n"); + continue; + } - } else { + if ( r == 0 ) { + STATUS("Timeout\n"); + continue; + } - for ( i=0; i