tree-wide: make sigprocmask() changes more automatic

This tries to get rid of most manual sigprocmask() changes, in favour
of:

1. The SD_EVENT_SIGNAL_PROCMASK flag to sd_event_add_signal()
2. The sd_event_set_signal_exit() call for handling SIGTERM/SIGINT
3. Move masking of SIGWINCH into ptyfwd, out of nspawn/vmspawn/run

And while we are at it get rid of a bunch of event source fields whose
lifetime is bound to the sd_event object they belong to anyway, and make
use of the "floating" event source feature of sd-event instead.
This commit is contained in:
Lennart Poettering
2024-09-13 17:12:28 +02:00
parent a7af35f1d4
commit d7a6bb9891
25 changed files with 77 additions and 104 deletions
+3 -5
View File
@@ -153,8 +153,6 @@ Manager* manager_free(Manager *manager) {
sd_event_source_unref(manager->inotify_event);
sd_event_source_unref(manager->kill_workers_event);
sd_event_source_unref(manager->memory_pressure_event_source);
sd_event_source_unref(manager->sigrtmin18_event_source);
sd_event_unref(manager->event);
free(manager->cgroup);
@@ -1352,13 +1350,13 @@ int manager_main(Manager *manager) {
return log_error_errno(r, "Failed to create post event source: %m");
/* Eventually, we probably want to do more here on memory pressure, for example, kill idle workers immediately */
r = sd_event_add_memory_pressure(manager->event, &manager->memory_pressure_event_source, NULL, NULL);
r = sd_event_add_memory_pressure(manager->event, /* ret_event_source= */ NULL, /* callback= */ NULL, /* userdata= */ NULL);
if (r < 0)
log_full_errno(ERRNO_IS_NOT_SUPPORTED(r) || ERRNO_IS_PRIVILEGE(r) || (r == -EHOSTDOWN) ? LOG_DEBUG : LOG_WARNING, r,
"Failed to allocate memory pressure watch, ignoring: %m");
r = sd_event_add_signal(manager->event, &manager->memory_pressure_event_source,
(SIGRTMIN+18) | SD_EVENT_SIGNAL_PROCMASK, sigrtmin18_handler, NULL);
r = sd_event_add_signal(manager->event, /* ret_event_source= */ NULL,
(SIGRTMIN+18) | SD_EVENT_SIGNAL_PROCMASK, sigrtmin18_handler, /* userdata= */ NULL);
if (r < 0)
return log_error_errno(r, "Failed to allocate SIGRTMIN+18 event source, ignoring: %m");
-3
View File
@@ -35,9 +35,6 @@ typedef struct Manager {
sd_event_source *kill_workers_event;
sd_event_source *memory_pressure_event_source;
sd_event_source *sigrtmin18_event_source;
usec_t last_usec;
ResolveNameTiming resolve_name_timing;
+5 -3
View File
@@ -208,9 +208,11 @@ int monitor_main(int argc, char *argv[], void *userdata) {
goto finalize;
}
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT) >= 0);
(void) sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
(void) sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
r = sd_event_set_signal_exit(event, true);
if (r < 0) {
log_error_errno(r, "Failed to install SIGINT/SIGTERM handling: %m");
goto finalize;
}
printf("monitor will print the received events for:\n");
if (arg_print_udev) {