diff --git a/src/engine.c b/src/engine.c index 54a9a7602564a7a753e8427a306f54ba0334f44a..8d055cc9dc98aee58e27ebe387dcb842a4caf21f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5637,13 +5637,7 @@ void engine_clean(struct engine *e) { */ void engine_struct_dump(struct engine *e, FILE *stream) { - /* Dump our signature and version. */ - restart_write_blocks(SWIFT_RESTART_SIGNATURE, strlen(SWIFT_RESTART_SIGNATURE), - 1, stream, "SWIFT signature"); - restart_write_blocks((void *)package_version(), strlen(package_version()), 1, - stream, "SWIFT version"); - - /* Now the engine. */ + /* Dump the engine. */ restart_write_blocks(e, sizeof(struct engine), 1, stream, "engine struct"); /* And all the engine pointed data, these use their own dump functions. */ @@ -5669,25 +5663,7 @@ void engine_struct_dump(struct engine *e, FILE *stream) { */ void engine_struct_restore(struct engine *e, FILE *stream) { - /* Get our version and signature back. These should match. */ - char signature[strlen(SWIFT_RESTART_SIGNATURE) + 1]; - restart_read_blocks(signature, strlen(SWIFT_RESTART_SIGNATURE), 1, stream, - "SWIFT signature"); - if (strcmp(signature, SWIFT_RESTART_SIGNATURE) != 0) - error("Do not recognise this as a SWIFT restart file"); - - char version[200]; - restart_read_blocks(version, strlen(package_version()), 1, stream, - "SWIFT version"); - /* XXX error or warning, it might work! */ - if (strcmp(version, package_version()) != 0) - message( - "WARNING: restoring from a different version of SWIFT. You have:" - " %s, and the restarts file where created using: %s. This may fail" - " badly", - version, package_version()); - - /* Now the engine. */ + /* Read the engine. */ restart_read_blocks(e, sizeof(struct engine), 1, stream, "engine struct"); /* XXX Re-initializations as necessary. XXX */ @@ -5752,7 +5728,7 @@ void engine_struct_restore(struct engine *e, FILE *stream) { e->sourceterms = sourceterms; struct swift_params *parameter_file = malloc(sizeof(struct swift_params)); - parser_struct_restore(e->parameter_file, stream); + parser_struct_restore(parameter_file, stream); e->parameter_file = parameter_file; /* Want to force a rebuild before using this engine. Wait to repartition.*/ diff --git a/src/restart.c b/src/restart.c index 689c111635e18a10b78f69d1cd637e82b6acf2ea..bcf05eafc89de5108a247240c526f17e84bd5ab5 100644 --- a/src/restart.c +++ b/src/restart.c @@ -35,6 +35,7 @@ #include "engine.h" #include "error.h" #include "restart.h" +#include "version.h" /** * @brief generate a name for a restart file. @@ -69,7 +70,7 @@ char **restart_locate(const char *dir, const char *basename, int *nfiles) { /* Construct the glob pattern for locating files. */ char pattern[200]; - if (snprintf(pattern, 200, "%s/%s_[0-9]*.rst", dir, basename) > 200) { + if (snprintf(pattern, 200, "%s/%s_[0-9]*.rst", dir, basename) < 200) { glob_t globbuf; char **files = NULL; @@ -111,6 +112,12 @@ void restart_write(struct engine *e, const char *filename) { if (stream == NULL) error("Failed to open restart file: %s (%s)", filename, strerror(errno)); + /* Dump our signature and version. */ + restart_write_blocks(SWIFT_RESTART_SIGNATURE, strlen(SWIFT_RESTART_SIGNATURE), + 1, stream, "SWIFT signature"); + restart_write_blocks((void *)package_version(), strlen(package_version()), 1, + stream, "SWIFT version"); + engine_struct_dump(e, stream); fclose(stream); } @@ -124,6 +131,27 @@ void restart_read(struct engine *e, const char *filename) { if (stream == NULL) error("Failed to open restart file: %s (%s)", filename, strerror(errno)); + /* Get our version and signature back. These should match. */ + char signature[strlen(SWIFT_RESTART_SIGNATURE) + 1]; + int len = strlen(SWIFT_RESTART_SIGNATURE); + restart_read_blocks(signature, len, 1, stream, "SWIFT signature"); + signature[len] = '\0'; + if (strncmp(signature, SWIFT_RESTART_SIGNATURE, len) != 0) + error("Do not recognise this as a SWIFT restart file, found %s " + "expected %s", signature, SWIFT_RESTART_SIGNATURE); + + char version[200]; + len = strlen(package_version()); + restart_read_blocks(version, len, 1, stream, "SWIFT version"); + version[len] = '\0'; + + /* XXX error or warning, it might work! */ + if (strncmp(version, package_version(), len) != 0) + message( + "WARNING: restoring from a different version of SWIFT.\n You have:" + " %s and the restarts files are from: %s. This may fail" + " badly.", package_version(), version); + engine_struct_restore(e, stream); fclose(stream); }