diff options
author | Thomas White <taw@physics.org> | 2022-03-03 12:33:05 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-03-03 12:33:05 +0100 |
commit | 634ac34f8ffde1d3991751230c57eba70529f005 (patch) | |
tree | 58dbf7dd27c23a2d9d1653358f78980eecb24ebb | |
parent | 049d7fb351bfaf4ae2e627fe21f8748504a42778 (diff) |
GUI: Better handling of error-filled indexamajig logs
If there are lots of error messages (e.g. a missing mask file), looking
at the last 4k of the log file is not always enough. Now it will go
back to 16k, in steps of 4k. It will stop early if it finds the start
of the file, and it will complain if it still doesn't find what it's
looking for.
-rw-r--r-- | src/gui_index.c | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/src/gui_index.c b/src/gui_index.c index b5b24248..99d8feb3 100644 --- a/src/gui_index.c +++ b/src/gui_index.c @@ -1015,30 +1015,53 @@ int read_number_processed(const char *filename) { FILE *fh = fopen(filename, "r"); int n_proc = 0; + long len = 0; + int found; /* Normal situation if SLURM job hasn't started yet */ if ( fh == NULL ) return 0; - /* Only look at the last part of the file */ - fseek(fh, -4096, SEEK_END); - do { - char line[1024]; - if ( fgets(line, 1024, fh) == NULL ) break; - if ( strncmp(line, "Final: ", 7) == 0 ) { - int i; - if ( sscanf(line, "Final: %i images processed", &i) == 1 ) { - n_proc = i; - } - } else if ( strstr(line, " images processed, ") != NULL ) { - int i; - if ( sscanf(line, "%i ", &i) == 1 ) { - n_proc = i; - } + len += 4096; + + /* Only look at the last part of the file */ + if ( fseek(fh, -len, SEEK_END) ) { + /* Whoops, tried to go too far. + * Start from beginning, and don't loop again */ + fseek(fh, 0, SEEK_SET); + found = 1; + } else { + found = 0; } - } while ( 1 ); + do { + char line[1024]; + if ( fgets(line, 1024, fh) == NULL ) break; + + if ( strncmp(line, "Final: ", 7) == 0 ) { + int i; + if ( sscanf(line, "Final: %i images processed", &i) == 1 ) { + n_proc = i; + found = 1; + } + } else if ( strstr(line, " images processed, ") != NULL ) { + int i; + if ( sscanf(line, "%i ", &i) == 1 ) { + n_proc = i; + found = 1; + } + } + + } while ( 1 ); + + } while ( !found && (len < 16384) ); + + if ( !found ) { + ERROR("Couldn't find status message in last 16k of %s - " + "indexamajig output probably contains copious errors.\n", + filename); + } fclose(fh); |