diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-10-21 23:34:29 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-10-23 00:27:23 -0400 |
commit | d71839afd88589247d8dd42b2b09d024f521749d (patch) | |
tree | e210b8bd516ed2d1c04fcac11e588f587dea5144 | |
parent | cb6518345fcc057ca6ed3d037253bb4eeab4d94e (diff) |
journal-upload: verify state file can be saved before uploading
Do our best verify that we can actually write the state file
before upload commences to avoid duplicate messages on the server.
-rw-r--r-- | src/journal-remote/journal-upload.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 87d6ff7c06..37c12f0e07 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -31,6 +31,7 @@ #include "util.h" #include "build.h" #include "fileio.h" +#include "mkdir.h" #include "conf-parser.h" #include "journal-upload.h" @@ -93,6 +94,32 @@ static size_t output_callback(char *buf, return size * nmemb; } +static int check_cursor_updating(Uploader *u) { + _cleanup_free_ char *temp_path = NULL; + _cleanup_fclose_ FILE *f = NULL; + int r; + + if (!u->state_file) + return 0; + + r = mkdir_parents(u->state_file, 0755); + if (r < 0) { + log_error("Cannot create parent directory of state file %s: %s", + u->state_file, strerror(-r)); + return r; + } + + r = fopen_temporary(u->state_file, &f, &temp_path); + if (r < 0) { + log_error("Cannot save state to %s: %s", + u->state_file, strerror(-r)); + return r; + } + unlink(temp_path); + + return 0; +} + static int update_cursor_state(Uploader *u) { _cleanup_free_ char *temp_path = NULL; _cleanup_fclose_ FILE *f = NULL; @@ -779,6 +806,10 @@ int main(int argc, char **argv) { sd_event_set_watchdog(u.events, true); + r = check_cursor_updating(&u); + if (r < 0) + goto cleanup; + log_debug("%s running as pid "PID_FMT, program_invocation_short_name, getpid()); |