984f77
From e48586dcfa66731a353ecc832e43fab75559e2cf Mon Sep 17 00:00:00 2001
984f77
From: Lennart Poettering <lennart@poettering.net>
984f77
Date: Wed, 30 Oct 2019 16:37:42 +0100
984f77
Subject: [PATCH] sd-event: don't invalidate source type on disconnect
984f77
984f77
This fixes fd closing if fd ownership is requested.
984f77
984f77
(cherry picked from commit f59825595182d70b9ead238d1e885d0db99cc201)
984f77
984f77
Resolves: #2115396
984f77
---
984f77
 src/libsystemd/sd-event/sd-event.c | 4 +++-
984f77
 1 file changed, 3 insertions(+), 1 deletion(-)
984f77
984f77
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
984f77
index 0adfdd9e1a..09d4584bf9 100644
984f77
--- a/src/libsystemd/sd-event/sd-event.c
984f77
+++ b/src/libsystemd/sd-event/sd-event.c
984f77
@@ -1104,11 +1104,13 @@ static void source_disconnect(sd_event_source *s) {
984f77
 
984f77
         event = s->event;
984f77
 
984f77
-        s->type = _SOURCE_EVENT_SOURCE_TYPE_INVALID;
984f77
         s->event = NULL;
984f77
         LIST_REMOVE(sources, event->sources, s);
984f77
         event->n_sources--;
984f77
 
984f77
+        /* Note that we don't invalidate the type here, since we still need it in order to close the fd or
984f77
+         * pidfd associated with this event source, which we'll do only on source_free(). */
984f77
+
984f77
         if (!s->floating)
984f77
                 sd_event_unref(event);
984f77
 }