diff options
author | Thomas White <taw@physics.org> | 2014-12-10 18:23:10 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2014-12-10 18:23:10 +0100 |
commit | 08258e0a8f2cdc1e1f005e11fa5295784cff22ec (patch) | |
tree | b52a053a78e59b30a936aa114cfda0849607b30a | |
parent | 6f28aa507cdf41715992acdef3d4854b9ab32704 (diff) |
Improve detection of error conditions when reading events in worker processes
-rw-r--r-- | src/im-sandbox.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/im-sandbox.c b/src/im-sandbox.c index 1e567fb6..7b810da5 100644 --- a/src/im-sandbox.c +++ b/src/im-sandbox.c @@ -268,6 +268,8 @@ struct buffer_data int fd; int rbufpos; int rbuflen; + int eof; + int err; }; @@ -276,8 +278,19 @@ static int read_fpe_data(struct buffer_data *bd) int rval; int no_line = 0; + bd->eof = 0; + bd->err = 0; + rval = read(bd->fd, bd->rbuffer+bd->rbufpos, bd->rbuflen-bd->rbufpos); - if ( (rval == -1) || (rval == 0) ) return 1; + if ( rval == 0 ) { + bd->eof = 1; + return 1; + } + if ( rval == -1 ) { + bd->err = 1; + return 1; + } + bd->rbufpos += rval; assert(bd->rbufpos <= bd->rbuflen); @@ -292,7 +305,7 @@ static int read_fpe_data(struct buffer_data *bd) /* Is there a line in the buffer? */ if ( bd->rbuffer[i] == '\n' ) { - bd->rbuffer[i] = '\0'; + bd->rbuffer[i] = '\n'; line_end = i; line_ready = 1; break; @@ -358,6 +371,8 @@ static void run_work(const struct index_args *iargs, bd.rbufpos = 0; bd.line = NULL; bd.fd = 0; + bd.eof = 0; + bd.err = 1; fh = fdopen(filename_pipe, "r"); if ( fh == NULL ) { @@ -380,11 +395,9 @@ static void run_work(const struct index_args *iargs, struct pattern_args pargs; int c; - int error; int rval; char buf[1024]; - error = 0; pargs.filename_p_e = initialize_filename_plus_event(); rval = 0; @@ -431,17 +444,20 @@ static void run_work(const struct index_args *iargs, } while ( !rval ); - if ( error == 1 ) { + if ( bd.err ) { + ERROR("Event pipe read error: %s\n", strerror(errno)); allDone = 1; continue; } - chomp(bd.line); - - if ( strlen(bd.line) == 0 ) { - + if ( bd.eof ) { + ERROR("Event pipe EOF (should not happen).\n"); allDone = 1; + continue; + } + if ( bd.line[0] == '\n' ) { + allDone = 1; } else { char filename[1024]; @@ -449,14 +465,21 @@ static void run_work(const struct index_args *iargs, struct event* ev; int ser; + chomp(bd.line); + sscanf(bd.line, "%s %s %i", filename, event_str, &ser); pargs.filename_p_e->filename = strdup(filename); + /* Make absolutely sure the same event won't be + * processed a second time */ + bd.line[0] = '\0'; + if ( strcmp(event_str, "/") != 0 ) { ev = get_event_from_event_string(event_str); if ( ev == NULL ) { ERROR("Error in event recovery\n"); + continue; } pargs.filename_p_e->ev = ev; |