diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-04-01 20:30:13 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-15 22:23:48 -0400 |
commit | a3152e7655231b94fa7b9582906fb86ab00b9c99 (patch) | |
tree | 7d8187f44f537c547e2ee62a1bab3bf0b85cfc2f /src/journal-remote | |
parent | 722b6795655149a68277b3cffeba711e1d440e5a (diff) |
journal-upload: add watchdog support
Diffstat (limited to 'src/journal-remote')
-rw-r--r-- | src/journal-remote/journal-remote.c | 2 | ||||
-rw-r--r-- | src/journal-remote/journal-upload.c | 47 | ||||
-rw-r--r-- | src/journal-remote/journal-upload.h | 1 |
3 files changed, 50 insertions, 0 deletions
diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index 906759b434..063d6dfa2d 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -1252,6 +1252,8 @@ int main(int argc, char **argv) { if (remoteserver_init(&s) < 0) return EXIT_FAILURE; + sd_event_set_watchdog(s.events, true); + log_debug("%s running as pid "PID_FMT, program_invocation_short_name, getpid()); sd_notify(false, diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 76855373d3..264f915a78 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -340,6 +340,43 @@ static int open_file_for_upload(Uploader *u, const char *filename) { return r; } +static int dispatch_sigterm(sd_event_source *event, + const struct signalfd_siginfo *si, + void *userdata) { + Uploader *u = userdata; + + assert(u); + + log_received_signal(LOG_INFO, si); + + close_fd_input(u); + close_journal_input(u); + + sd_event_exit(u->events, 0); + return 0; +} + +static int setup_signals(Uploader *u) { + sigset_t mask; + int r; + + assert(u); + + assert_se(sigemptyset(&mask) == 0); + sigset_add_many(&mask, SIGINT, SIGTERM, -1); + assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0); + + r = sd_event_add_signal(u->events, &u->sigterm_event, SIGTERM, dispatch_sigterm, u); + if (r < 0) + return r; + + r = sd_event_add_signal(u->events, &u->sigint_event, SIGINT, dispatch_sigterm, u); + if (r < 0) + return r; + + return 0; +} + static int setup_uploader(Uploader *u, const char *url, const char *state_file) { int r; @@ -358,6 +395,12 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file) return r; } + r = setup_signals(u); + if (r < 0) { + log_error("Failed to set up signals: %s", strerror(-r)); + return r; + } + return load_cursor_state(u); } @@ -376,6 +419,8 @@ static void destroy_uploader(Uploader *u) { close_fd_input(u); close_journal_input(u); + sd_event_source_unref(u->sigterm_event); + sd_event_source_unref(u->sigint_event); sd_event_unref(u->events); } @@ -668,6 +713,8 @@ int main(int argc, char **argv) { if (r < 0) goto cleanup; + sd_event_set_watchdog(u.events, true); + log_debug("%s running as pid "PID_FMT, program_invocation_short_name, getpid()); diff --git a/src/journal-remote/journal-upload.h b/src/journal-remote/journal-upload.h index 0adb915c68..9ccad102ad 100644 --- a/src/journal-remote/journal-upload.h +++ b/src/journal-remote/journal-upload.h @@ -21,6 +21,7 @@ typedef enum { typedef struct Uploader { sd_event *events; + sd_event_source *sigint_event, *sigterm_event; const char *url; CURL *easy; |