summaryrefslogtreecommitdiff
path: root/src/journal-remote/journal-upload.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-01 20:30:13 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-15 22:23:48 -0400
commita3152e7655231b94fa7b9582906fb86ab00b9c99 (patch)
tree7d8187f44f537c547e2ee62a1bab3bf0b85cfc2f /src/journal-remote/journal-upload.c
parent722b6795655149a68277b3cffeba711e1d440e5a (diff)
journal-upload: add watchdog support
Diffstat (limited to 'src/journal-remote/journal-upload.c')
-rw-r--r--src/journal-remote/journal-upload.c47
1 files changed, 47 insertions, 0 deletions
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());