mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 09:21:26 +03:00
sd-event: update state at the end in event_source_enable
Coverity in CID#1435966 was complaining that s->enabled is not "restored" in all cases. But the code was actually correct, since it should only be "restored" in the error paths. But let's still make this prettier by not setting the state before all operations that may fail are done. We need to set .enabled for the prioq reshuffling operations, so move those down. No functional change intended.
This commit is contained in:
parent
b8aac5014c
commit
d2eafe61ca
@ -2311,11 +2311,11 @@ static int event_source_disable(sd_event_source *s) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int event_source_enable(sd_event_source *s, int m) {
|
static int event_source_enable(sd_event_source *s, int enable) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(s);
|
assert(s);
|
||||||
assert(IN_SET(m, SD_EVENT_ON, SD_EVENT_ONESHOT));
|
assert(IN_SET(enable, SD_EVENT_ON, SD_EVENT_ONESHOT));
|
||||||
assert(s->enabled == SD_EVENT_OFF);
|
assert(s->enabled == SD_EVENT_OFF);
|
||||||
|
|
||||||
/* Unset the pending flag when this event source is enabled */
|
/* Unset the pending flag when this event source is enabled */
|
||||||
@ -2325,31 +2325,16 @@ static int event_source_enable(sd_event_source *s, int m) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->enabled = m;
|
|
||||||
|
|
||||||
switch (s->type) {
|
switch (s->type) {
|
||||||
|
|
||||||
case SOURCE_IO:
|
case SOURCE_IO:
|
||||||
r = source_io_register(s, m, s->io.events);
|
r = source_io_register(s, enable, s->io.events);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
s->enabled = SD_EVENT_OFF;
|
|
||||||
return r;
|
return r;
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SOURCE_TIME_REALTIME:
|
|
||||||
case SOURCE_TIME_BOOTTIME:
|
|
||||||
case SOURCE_TIME_MONOTONIC:
|
|
||||||
case SOURCE_TIME_REALTIME_ALARM:
|
|
||||||
case SOURCE_TIME_BOOTTIME_ALARM:
|
|
||||||
event_source_time_prioq_reshuffle(s);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SOURCE_SIGNAL:
|
case SOURCE_SIGNAL:
|
||||||
r = event_make_signal_data(s->event, s->signal.sig, NULL);
|
r = event_make_signal_data(s->event, s->signal.sig, NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
s->enabled = SD_EVENT_OFF;
|
|
||||||
event_gc_signal_data(s->event, &s->priority, s->signal.sig);
|
event_gc_signal_data(s->event, &s->priority, s->signal.sig);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -2362,9 +2347,8 @@ static int event_source_enable(sd_event_source *s, int m) {
|
|||||||
if (EVENT_SOURCE_WATCH_PIDFD(s)) {
|
if (EVENT_SOURCE_WATCH_PIDFD(s)) {
|
||||||
/* yes, we have pidfd */
|
/* yes, we have pidfd */
|
||||||
|
|
||||||
r = source_child_pidfd_register(s, s->enabled);
|
r = source_child_pidfd_register(s, enable);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
s->enabled = SD_EVENT_OFF;
|
|
||||||
s->event->n_enabled_child_sources--;
|
s->event->n_enabled_child_sources--;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -2373,7 +2357,6 @@ static int event_source_enable(sd_event_source *s, int m) {
|
|||||||
|
|
||||||
r = event_make_signal_data(s->event, SIGCHLD, NULL);
|
r = event_make_signal_data(s->event, SIGCHLD, NULL);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
s->enabled = SD_EVENT_OFF;
|
|
||||||
s->event->n_enabled_child_sources--;
|
s->event->n_enabled_child_sources--;
|
||||||
event_gc_signal_data(s->event, &s->priority, SIGCHLD);
|
event_gc_signal_data(s->event, &s->priority, SIGCHLD);
|
||||||
return r;
|
return r;
|
||||||
@ -2382,10 +2365,12 @@ static int event_source_enable(sd_event_source *s, int m) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SOURCE_TIME_REALTIME:
|
||||||
|
case SOURCE_TIME_BOOTTIME:
|
||||||
|
case SOURCE_TIME_MONOTONIC:
|
||||||
|
case SOURCE_TIME_REALTIME_ALARM:
|
||||||
|
case SOURCE_TIME_BOOTTIME_ALARM:
|
||||||
case SOURCE_EXIT:
|
case SOURCE_EXIT:
|
||||||
prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SOURCE_DEFER:
|
case SOURCE_DEFER:
|
||||||
case SOURCE_POST:
|
case SOURCE_POST:
|
||||||
case SOURCE_INOTIFY:
|
case SOURCE_INOTIFY:
|
||||||
@ -2395,6 +2380,26 @@ static int event_source_enable(sd_event_source *s, int m) {
|
|||||||
assert_not_reached("Wut? I shouldn't exist.");
|
assert_not_reached("Wut? I shouldn't exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s->enabled = enable;
|
||||||
|
|
||||||
|
/* Non-failing operations below */
|
||||||
|
switch (s->type) {
|
||||||
|
case SOURCE_TIME_REALTIME:
|
||||||
|
case SOURCE_TIME_BOOTTIME:
|
||||||
|
case SOURCE_TIME_MONOTONIC:
|
||||||
|
case SOURCE_TIME_REALTIME_ALARM:
|
||||||
|
case SOURCE_TIME_BOOTTIME_ALARM:
|
||||||
|
event_source_time_prioq_reshuffle(s);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SOURCE_EXIT:
|
||||||
|
prioq_reshuffle(s->event->exit, s, &s->exit.prioq_index);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user