summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-event
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-12-23 23:26:15 +0100
committerSven Eden <yamakuzure@gmx.net>2017-07-17 17:58:35 +0200
commit8d6bc051881bde26218ab00014ea6bd0532280b2 (patch)
tree266617980c63b68094339de40e82ca1b5dacf22e /src/libelogind/sd-event
parentce18349eedcec2ed6074c89e5ce9e7bee0770ec0 (diff)
sd-event: when an event source fails, don't assume the type of it is still set
If a callback of an event source returns an error, then the event source might already be half-destroyed, if the callback dropped all refs. Hence, don't assume that the type is still valid, and save it before we issue the callback.
Diffstat (limited to 'src/libelogind/sd-event')
-rw-r--r--src/libelogind/sd-event/sd-event.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libelogind/sd-event/sd-event.c b/src/libelogind/sd-event/sd-event.c
index 383de48d5..1cdb3d139 100644
--- a/src/libelogind/sd-event/sd-event.c
+++ b/src/libelogind/sd-event/sd-event.c
@@ -2246,11 +2246,16 @@ static int process_signal(sd_event *e, struct signal_data *d, uint32_t events) {
}
static int source_dispatch(sd_event_source *s) {
+ EventSourceType saved_type;
int r = 0;
assert(s);
assert(s->pending || s->type == SOURCE_EXIT);
+ /* Save the event source type, here, so that we still know it after the event callback which might invalidate
+ * the event. */
+ saved_type = s->type;
+
if (s->type != SOURCE_DEFER && s->type != SOURCE_EXIT) {
r = source_set_pending(s, false);
if (r < 0)
@@ -2338,7 +2343,7 @@ static int source_dispatch(sd_event_source *s) {
if (r < 0)
log_debug_errno(r, "Event source %s (type %s) returned error, disabling: %m",
- strna(s->description), event_source_type_to_string(s->type));
+ strna(s->description), event_source_type_to_string(saved_type));
if (s->n_ref == 0)
source_free(s);