diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-07-16 05:11:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-16 05:11:00 +0900 |
commit | c798e1dfee12f407ea08285aeae1438def2899e8 (patch) | |
tree | 687420c9604ccdd6cce86caf71c3e13885e4d630 /src | |
parent | 5edf875b92b9986470d1499b6dd35dbca75f2854 (diff) | |
parent | c8e9d15cbfe9aff0cb1fd20a79b9d06485f599c2 (diff) | |
download | systemd-c798e1dfee12f407ea08285aeae1438def2899e8.tar.gz |
Merge pull request #24035 from yuwata/sd-event-cleanup
sd-event: tiny cleanups
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd/sd-event/sd-event.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index df48b3ce04..027a8dffa1 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -420,6 +420,8 @@ fail: } DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_event, sd_event, event_free); +#define PROTECT_EVENT(e) \ + _unused_ _cleanup_(sd_event_unrefp) sd_event *_ref = sd_event_ref(e); _public_ sd_event_source* sd_event_source_disable_unref(sd_event_source *s) { if (s) @@ -2139,12 +2141,9 @@ static sd_event_source* event_source_free(sd_event_source *s) { * we still retain a valid event source object after * the callback. */ - if (s->dispatching) { - if (s->type == SOURCE_IO) - source_io_unregister(s); - + if (s->dispatching) source_disconnect(s); - } else + else source_free(s); return NULL; @@ -3542,8 +3541,8 @@ static int process_inotify(sd_event *e) { } static int source_dispatch(sd_event_source *s) { - _cleanup_(sd_event_unrefp) sd_event *saved_event = NULL; EventSourceType saved_type; + sd_event *saved_event; int r = 0; assert(s); @@ -3555,7 +3554,8 @@ static int source_dispatch(sd_event_source *s) { /* Similarly, store a reference to the event loop object, so that we can still access it after the * callback might have invalidated/disconnected the event source. */ - saved_event = sd_event_ref(s->event); + saved_event = s->event; + PROTECT_EVENT(saved_event); /* Check if we hit the ratelimit for this event source, and if so, let's disable it. */ assert(!s->ratelimited); @@ -3756,7 +3756,7 @@ static int dispatch_exit(sd_event *e) { return 0; } - _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e); + PROTECT_EVENT(e); e->iteration++; e->state = SD_EVENT_EXITING; r = source_dispatch(p); @@ -3850,7 +3850,7 @@ _public_ int sd_event_prepare(sd_event *e) { assert_return(!e->default_event_ptr || e->tid == gettid(), -EREMOTEIO); /* Make sure that none of the preparation callbacks ends up freeing the event source under our feet */ - _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e); + PROTECT_EVENT(e); if (e->exit_requested) goto pending; @@ -4180,7 +4180,7 @@ _public_ int sd_event_dispatch(sd_event *e) { p = event_next_pending(e); if (p) { - _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e); + PROTECT_EVENT(e); e->state = SD_EVENT_RUNNING; r = source_dispatch(p); @@ -4232,7 +4232,7 @@ _public_ int sd_event_run(sd_event *e, uint64_t timeout) { } /* Make sure that none of the preparation callbacks ends up freeing the event source under our feet */ - _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e); + PROTECT_EVENT(e); r = sd_event_prepare(e); if (r == 0) @@ -4262,7 +4262,7 @@ _public_ int sd_event_loop(sd_event *e) { assert_return(!event_pid_changed(e), -ECHILD); assert_return(e->state == SD_EVENT_INITIAL, -EBUSY); - _unused_ _cleanup_(sd_event_unrefp) sd_event *ref = sd_event_ref(e); + PROTECT_EVENT(e); while (e->state != SD_EVENT_FINISHED) { r = sd_event_run(e, UINT64_MAX); |