diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-10 10:23:08 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-07-12 13:30:54 +0200 |
commit | 16914edff068a77fe2277a2c7e725d7888370104 (patch) | |
tree | 2afdd85bd7d98459e38c6fcc755070c46ba60344 | |
parent | 67782e10f0dd0f2feeb036aa4380fa5c6c55aaea (diff) | |
download | systemd-16914edff068a77fe2277a2c7e725d7888370104.tar.gz |
sd-event: add more asserts about event source integrity
Also "downgrade" assert_se() to assert(), this is not test code.
(cherry picked from commit 199475092d9a6f0482a7b934592784a54b82ffd0)
-rw-r--r-- | src/libsystemd/sd-event/sd-event.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index e9ee44f651..1e044ebba3 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -85,6 +85,11 @@ DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(event_source_type, int); SOURCE_DEFER, \ SOURCE_INOTIFY) +/* This is used to assert that we didn't pass an unexpected source type to event_source_time_prioq_put(). + * Time sources and ratelimited sources can be passed, so effectively this is the same as the + * EVENT_SOURCE_CAN_RATE_LIMIT() macro. */ +#define EVENT_SOURCE_USES_TIME_PRIOQ(t) EVENT_SOURCE_CAN_RATE_LIMIT(t) + struct sd_event { unsigned n_ref; @@ -1201,6 +1206,7 @@ static int event_source_time_prioq_put( assert(s); assert(d); + assert(EVENT_SOURCE_USES_TIME_PRIOQ(s->type)); r = prioq_put(d->earliest, s, &s->earliest_index); if (r < 0) @@ -2988,6 +2994,7 @@ static int event_arm_timer( d->needs_rearm = false; a = prioq_peek(d->earliest); + assert(!a || EVENT_SOURCE_USES_TIME_PRIOQ(a->type)); if (!a || a->enabled == SD_EVENT_OFF || time_event_source_next(a) == USEC_INFINITY) { if (d->fd < 0) @@ -3005,7 +3012,8 @@ static int event_arm_timer( } b = prioq_peek(d->latest); - assert_se(b && b->enabled != SD_EVENT_OFF); + assert(!b || EVENT_SOURCE_USES_TIME_PRIOQ(b->type)); + assert(b && b->enabled != SD_EVENT_OFF); t = sleep_between(e, time_event_source_next(a), time_event_source_latest(b)); if (d->next == t) @@ -3085,6 +3093,8 @@ static int process_timer( for (;;) { s = prioq_peek(d->earliest); + assert(!s || EVENT_SOURCE_USES_TIME_PRIOQ(s->type)); + if (!s || time_event_source_next(s) > n) break; @@ -3646,6 +3656,8 @@ static int dispatch_exit(sd_event *e) { assert(e); p = prioq_peek(e->exit); + assert(!p || p->type == SOURCE_EXIT); + if (!p || event_source_is_offline(p)) { e->state = SD_EVENT_FINISHED; return 0; |