From ac9f2640cb9c107b43f47bba7e068d3b92b5337b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 10 Nov 2020 12:57:34 +0100 Subject: [PATCH] sd-event: increase n_enabled_child_sources just once Neither source_child_pidfd_register() nor event_make_signal_data() look at n_enabled_child_sources. --- src/libsystemd/sd-event/sd-event.c | 40 +++++++++--------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 5f66c379b5a..0d3d81959ce 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -1340,31 +1340,25 @@ _public_ int sd_event_add_child( if (r < 0) return r; - e->n_enabled_child_sources++; - if (EVENT_SOURCE_WATCH_PIDFD(s)) { /* We have a pidfd and we only want to watch for exit */ - r = source_child_pidfd_register(s, s->enabled); - if (r < 0) { - e->n_enabled_child_sources--; + if (r < 0) return r; - } + } else { /* We have no pidfd or we shall wait for some other event than WEXITED */ - r = event_make_signal_data(e, SIGCHLD, NULL); - if (r < 0) { - e->n_enabled_child_sources--; + if (r < 0) return r; - } e->need_process_child = true; } + e->n_enabled_child_sources++; + if (ret) *ret = s; - TAKE_PTR(s); return 0; } @@ -1429,31 +1423,24 @@ _public_ int sd_event_add_child_pidfd( if (r < 0) return r; - e->n_enabled_child_sources++; - if (EVENT_SOURCE_WATCH_PIDFD(s)) { /* We only want to watch for WEXITED */ - r = source_child_pidfd_register(s, s->enabled); - if (r < 0) { - e->n_enabled_child_sources--; + if (r < 0) return r; - } } else { /* We shall wait for some other event than WEXITED */ - r = event_make_signal_data(e, SIGCHLD, NULL); - if (r < 0) { - e->n_enabled_child_sources--; + if (r < 0) return r; - } e->need_process_child = true; } + e->n_enabled_child_sources++; + if (ret) *ret = s; - TAKE_PTR(s); return 0; } @@ -2342,27 +2329,24 @@ static int event_source_enable(sd_event_source *s, int enable) { break; case SOURCE_CHILD: - s->event->n_enabled_child_sources++; - if (EVENT_SOURCE_WATCH_PIDFD(s)) { /* yes, we have pidfd */ r = source_child_pidfd_register(s, enable); - if (r < 0) { - s->event->n_enabled_child_sources--; + if (r < 0) return r; - } } else { /* no pidfd, or something other to watch for than WEXITED */ r = event_make_signal_data(s->event, SIGCHLD, NULL); if (r < 0) { - s->event->n_enabled_child_sources--; event_gc_signal_data(s->event, &s->priority, SIGCHLD); return r; } } + s->event->n_enabled_child_sources++; + break; case SOURCE_TIME_REALTIME: