From a2d4d607cc5cd94013c37ed6b64618dd647d5cbd Mon Sep 17 00:00:00 2001 From: Shane Snyder Date: Thu, 6 Oct 2016 12:55:52 -0500 Subject: [PATCH] update darshan-util to error with invalid versions darshan-logutils now returns an error when encountering a log file with a module version number greater than what the library was built with. all utilities were also updated to account for this modification --- darshan-util/darshan-convert.c | 27 ++++++++++++++------------- darshan-util/darshan-diff.c | 2 -- darshan-util/darshan-logutils.c | 11 +++++++++++ darshan-util/darshan-parser.c | 33 ++++++++++++++++----------------- 4 files changed, 41 insertions(+), 32 deletions(-) diff --git a/darshan-util/darshan-convert.c b/darshan-util/darshan-convert.c index 29e3a1f..2443862 100644 --- a/darshan-util/darshan-convert.c +++ b/darshan-util/darshan-convert.c @@ -360,6 +360,7 @@ int main(int argc, char **argv) { darshan_log_close(infile); darshan_log_close(outfile); + unlink(outfile_name); return(-1); } @@ -368,6 +369,7 @@ int main(int argc, char **argv) { darshan_log_close(infile); darshan_log_close(outfile); + unlink(outfile_name); return(-1); } @@ -389,19 +391,8 @@ int main(int argc, char **argv) /* we have module data to convert */ memset(mod_buf, 0, DEF_MOD_BUF_SIZE); - ret = mod_logutils[i]->log_get_record(infile, (void **)&mod_buf); - if(ret != 1) - { - fprintf(stderr, "Error: failed to parse the first %s module record.\n", - darshan_module_names[i]); - darshan_log_close(infile); - darshan_log_close(outfile); - unlink(outfile_name); - return(-1); - } - /* loop over each of the module's records and convert */ - do + while((ret = mod_logutils[i]->log_get_record(infile, (void **)&mod_buf)) == 1) { base_rec = (struct darshan_base_record *)mod_buf; @@ -412,12 +403,22 @@ int main(int argc, char **argv) { darshan_log_close(infile); darshan_log_close(outfile); + unlink(outfile_name); return(-1); } memset(mod_buf, 0, DEF_MOD_BUF_SIZE); } - } while((ret = mod_logutils[i]->log_get_record(infile, (void **)&mod_buf)) == 1); + } + if(ret < 0) + { + fprintf(stderr, "Error: failed to parse %s module record.\n", + darshan_module_names[i]); + darshan_log_close(infile); + darshan_log_close(outfile); + unlink(outfile_name); + return(-1); + } } darshan_log_close(infile); diff --git a/darshan-util/darshan-diff.c b/darshan-util/darshan-diff.c index 43f92fa..97bf093 100644 --- a/darshan-util/darshan-diff.c +++ b/darshan-util/darshan-diff.c @@ -384,13 +384,11 @@ static int darshan_build_global_record_hash( { fprintf(stderr, "Error: unable to read module %s data from log file.\n", darshan_module_names[i]); - free(mod_rec->mod_dat); free(mod_rec); return(-1); } else if(ret == 0) { - free(mod_rec->mod_dat); free(mod_rec); break; } diff --git a/darshan-util/darshan-logutils.c b/darshan-util/darshan-logutils.c index f2e3734..6851115 100644 --- a/darshan-util/darshan-logutils.c +++ b/darshan-util/darshan-logutils.c @@ -643,6 +643,17 @@ int darshan_log_get_mod(darshan_fd fd, darshan_module_id mod_id, if(fd->mod_map[mod_id].len == 0) return(0); /* no data corresponding to this mod_id */ + /* assume module will support backwards compatibility, but we obviously + * can't provide any sort of "forwards" compatibility + */ + if(fd->mod_ver[mod_id] > darshan_module_versions[mod_id]) + { + fprintf(stderr, "Error: invalid %s module log format version " + "(expected %d, got %d)\n", darshan_module_names[mod_id], + darshan_module_versions[mod_id], fd->mod_ver[mod_id]); + return(-1); + } + /* read this module's data from the log file */ ret = darshan_log_dzread(fd, mod_id, mod_buf, mod_buf_sz); if(ret < 0) diff --git a/darshan-util/darshan-parser.c b/darshan-util/darshan-parser.c index dc63c4b..d677d38 100644 --- a/darshan-util/darshan-parser.c +++ b/darshan-util/darshan-parser.c @@ -398,7 +398,8 @@ int main(int argc, char **argv) /* currently only POSIX, MPIIO, and STDIO modules support non-base * parsing */ - else if((i != DARSHAN_POSIX_MOD) && (i != DARSHAN_MPIIO_MOD) && (i != DARSHAN_STDIO_MOD) && !(mask & OPTION_BASE)) + else if((i != DARSHAN_POSIX_MOD) && (i != DARSHAN_MPIIO_MOD) && + (i != DARSHAN_STDIO_MOD) && !(mask & OPTION_BASE)) continue; /* this module has data to be parsed and printed */ @@ -425,22 +426,24 @@ int main(int argc, char **argv) } } - ret = mod_logutils[i]->log_get_record(fd, (void **)&mod_buf); - if(ret != 1) - { - fprintf(stderr, "Error: failed to parse the first %s module record.\n", - darshan_module_names[i]); - ret = -1; - goto cleanup; - } - /* loop over each of this module's records and print them */ - do + while(1) { char *mnt_pt = NULL; char *fs_type = NULL; char *rec_name = NULL; hash_entry_t *hfile = NULL; + + ret = mod_logutils[i]->log_get_record(fd, (void **)&mod_buf); + if(ret < 1) + { + if(ret == -1) + { + fprintf(stderr, "Error: failed to parse %s module record.\n", + darshan_module_names[i]); + } + break; + } base_rec = (struct darshan_base_record *)mod_buf; /* get the pathname for this record */ @@ -528,13 +531,9 @@ int main(int argc, char **argv) } memset(mod_buf, 0, DEF_MOD_BUF_SIZE); - - } while((ret = mod_logutils[i]->log_get_record(fd, (void **)&mod_buf)) == 1); - if (ret < 0) - { - ret = -1; - goto cleanup; } + if(ret == -1) + continue; /* move on to the next module if there was an error with this one */ /* we calculate more detailed stats for POSIX and MPI-IO modules, * if the parser is executed with more than the base option -- 2.26.2