summaryrefslogtreecommitdiffstats
path: root/src/import
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-02-16 18:20:51 +0100
committerLennart Poettering <lennart@poettering.net>2024-03-01 22:25:42 +0100
commit423bba9926c2d6cb3f3afbc3b37f90d1ece09b87 (patch)
tree3123e8ee2b8590cf8bd163dd1799b8954ffc4ab8 /src/import
parentimportd: trivial modernizations (diff)
downloadsystemd-423bba9926c2d6cb3f3afbc3b37f90d1ece09b87.tar.xz
systemd-423bba9926c2d6cb3f3afbc3b37f90d1ece09b87.zip
importd: modernize signal handling a bit
Diffstat (limited to 'src/import')
-rw-r--r--src/import/export.c23
-rw-r--r--src/import/import-common.c5
-rw-r--r--src/import/importd.c16
3 files changed, 14 insertions, 30 deletions
diff --git a/src/import/export.c b/src/import/export.c
index 074209b6dc..ee65cc8d36 100644
--- a/src/import/export.c
+++ b/src/import/export.c
@@ -14,6 +14,7 @@
#include "fd-util.h"
#include "fs-util.h"
#include "hostname-util.h"
+#include "import-common.h"
#include "import-util.h"
#include "main-func.h"
#include "signal-util.h"
@@ -43,12 +44,6 @@ static void determine_compression_from_filename(const char *p) {
arg_compress = IMPORT_COMPRESS_UNCOMPRESSED;
}
-static int interrupt_signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
- log_notice("Transfer aborted.");
- sd_event_exit(sd_event_source_get_event(s), EINTR);
- return 0;
-}
-
static void on_tar_finished(TarExport *export, int error, void *userdata) {
sd_event *event = userdata;
assert(export);
@@ -101,13 +96,9 @@ static int export_tar(int argc, char *argv[], void *userdata) {
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, strna(pretty), import_compress_type_to_string(arg_compress));
}
- r = sd_event_default(&event);
+ r = import_allocate_event_with_signals(&event);
if (r < 0)
- return log_error_errno(r, "Failed to allocate event loop: %m");
-
- assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT) >= 0);
- (void) sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL);
- (void) sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL);
+ return r;
r = tar_export_new(&export, event, on_tar_finished, event);
if (r < 0)
@@ -177,13 +168,9 @@ static int export_raw(int argc, char *argv[], void *userdata) {
log_info("Exporting '%s', saving to '%s' with compression '%s'.", local, strna(pretty), import_compress_type_to_string(arg_compress));
}
- r = sd_event_default(&event);
+ r = import_allocate_event_with_signals(&event);
if (r < 0)
- return log_error_errno(r, "Failed to allocate event loop: %m");
-
- assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT) >= 0);
- (void) sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL);
- (void) sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL);
+ return r;
r = raw_export_new(&export, event, on_raw_finished, event);
if (r < 0)
diff --git a/src/import/import-common.c b/src/import/import-common.c
index 4a8a9a9c20..9d1448545e 100644
--- a/src/import/import-common.c
+++ b/src/import/import-common.c
@@ -295,9 +295,8 @@ int import_allocate_event_with_signals(sd_event **ret) {
if (r < 0)
return log_error_errno(r, "Failed to allocate event loop: %m");
- assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT) >= 0);
- (void) sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL);
- (void) sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL);
+ (void) sd_event_add_signal(event, NULL, SIGTERM|SD_EVENT_SIGNAL_PROCMASK, interrupt_signal_handler, NULL);
+ (void) sd_event_add_signal(event, NULL, SIGINT|SD_EVENT_SIGNAL_PROCMASK, interrupt_signal_handler, NULL);
*ret = TAKE_PTR(event);
return 0;
diff --git a/src/import/importd.c b/src/import/importd.c
index 624a5c24b2..dbf2fba4ab 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -642,17 +642,11 @@ static int manager_new(Manager **ret) {
if (r < 0)
return r;
- (void) sd_event_set_watchdog(m->event, true);
-
- r = sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
- if (r < 0)
- return r;
-
- r = sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
+ r = sd_event_set_signal_exit(m->event, true);
if (r < 0)
return r;
- r = sd_event_add_signal(m->event, NULL, SIGRTMIN+18, sigrtmin18_handler, NULL);
+ r = sd_event_add_signal(m->event, NULL, (SIGRTMIN+18)|SD_EVENT_SIGNAL_PROCMASK, sigrtmin18_handler, NULL);
if (r < 0)
return r;
@@ -660,6 +654,10 @@ static int manager_new(Manager **ret) {
if (r < 0)
log_debug_errno(r, "Failed allocate memory pressure event source, ignoring: %m");
+ r = sd_event_set_watchdog(m->event, true);
+ if (r < 0)
+ log_debug_errno(r, "Failed to enable watchdog logic, ignoring: %m");
+
r = sd_bus_default_system(&m->bus);
if (r < 0)
return r;
@@ -1381,7 +1379,7 @@ static int run(int argc, char *argv[]) {
umask(0022);
- assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, SIGTERM, SIGINT, SIGRTMIN+18) >= 0);
+ assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD) >= 0);
r = manager_new(&m);
if (r < 0)