summaryrefslogtreecommitdiff
path: root/src/journal-remote/journal-upload.c
diff options
context:
space:
mode:
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());