sd-event: check return value of syscals directly, avoid redundant variable assignment
And while we are at it, fix one incorrect error propagation.
This commit is contained in:
parent
ba28df775d
commit
15c689d77f
|
@ -399,13 +399,11 @@ static int source_io_register(
|
||||||
.events = events | (enabled == SD_EVENT_ONESHOT ? EPOLLONESHOT : 0),
|
.events = events | (enabled == SD_EVENT_ONESHOT ? EPOLLONESHOT : 0),
|
||||||
.data.ptr = s,
|
.data.ptr = s,
|
||||||
};
|
};
|
||||||
int r;
|
|
||||||
|
|
||||||
r = epoll_ctl(s->event->epoll_fd,
|
if (epoll_ctl(s->event->epoll_fd,
|
||||||
s->io.registered ? EPOLL_CTL_MOD : EPOLL_CTL_ADD,
|
s->io.registered ? EPOLL_CTL_MOD : EPOLL_CTL_ADD,
|
||||||
s->io.fd,
|
s->io.fd,
|
||||||
&ev);
|
&ev) < 0)
|
||||||
if (r < 0)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
s->io.registered = true;
|
s->io.registered = true;
|
||||||
|
@ -616,8 +614,7 @@ static int event_make_signal_data(
|
||||||
.data.ptr = d,
|
.data.ptr = d,
|
||||||
};
|
};
|
||||||
|
|
||||||
r = epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, d->fd, &ev);
|
if (epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, d->fd, &ev) < 0) {
|
||||||
if (r < 0) {
|
|
||||||
r = -errno;
|
r = -errno;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -1052,7 +1049,6 @@ static int event_setup_timer_fd(
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
_cleanup_close_ int fd = -1;
|
_cleanup_close_ int fd = -1;
|
||||||
int r;
|
|
||||||
|
|
||||||
fd = timerfd_create(clock, TFD_NONBLOCK|TFD_CLOEXEC);
|
fd = timerfd_create(clock, TFD_NONBLOCK|TFD_CLOEXEC);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -1065,8 +1061,7 @@ static int event_setup_timer_fd(
|
||||||
.data.ptr = d,
|
.data.ptr = d,
|
||||||
};
|
};
|
||||||
|
|
||||||
r = epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, fd, &ev);
|
if (epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0)
|
||||||
if (r < 0)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
d->fd = TAKE_FD(fd);
|
d->fd = TAKE_FD(fd);
|
||||||
|
@ -2776,7 +2771,6 @@ static int event_arm_timer(
|
||||||
struct itimerspec its = {};
|
struct itimerspec its = {};
|
||||||
sd_event_source *a, *b;
|
sd_event_source *a, *b;
|
||||||
usec_t t;
|
usec_t t;
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(e);
|
assert(e);
|
||||||
assert(d);
|
assert(d);
|
||||||
|
@ -2796,9 +2790,8 @@ static int event_arm_timer(
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* disarm */
|
/* disarm */
|
||||||
r = timerfd_settime(d->fd, TFD_TIMER_ABSTIME, &its, NULL);
|
if (timerfd_settime(d->fd, TFD_TIMER_ABSTIME, &its, NULL) < 0)
|
||||||
if (r < 0)
|
return -errno;
|
||||||
return r;
|
|
||||||
|
|
||||||
d->next = USEC_INFINITY;
|
d->next = USEC_INFINITY;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2820,8 +2813,7 @@ static int event_arm_timer(
|
||||||
} else
|
} else
|
||||||
timespec_store(&its.it_value, t);
|
timespec_store(&its.it_value, t);
|
||||||
|
|
||||||
r = timerfd_settime(d->fd, TFD_TIMER_ABSTIME, &its, NULL);
|
if (timerfd_settime(d->fd, TFD_TIMER_ABSTIME, &its, NULL) < 0)
|
||||||
if (r < 0)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
d->next = t;
|
d->next = t;
|
||||||
|
@ -2946,9 +2938,8 @@ static int process_child(sd_event *e) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
zero(s->child.siginfo);
|
zero(s->child.siginfo);
|
||||||
r = waitid(P_PID, s->child.pid, &s->child.siginfo,
|
if (waitid(P_PID, s->child.pid, &s->child.siginfo,
|
||||||
WNOHANG | (s->child.options & WEXITED ? WNOWAIT : 0) | s->child.options);
|
WNOHANG | (s->child.options & WEXITED ? WNOWAIT : 0) | s->child.options) < 0)
|
||||||
if (r < 0)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
if (s->child.siginfo.si_pid != 0) {
|
if (s->child.siginfo.si_pid != 0) {
|
||||||
|
@ -3439,7 +3430,6 @@ static sd_event_source* event_next_pending(sd_event *e) {
|
||||||
static int arm_watchdog(sd_event *e) {
|
static int arm_watchdog(sd_event *e) {
|
||||||
struct itimerspec its = {};
|
struct itimerspec its = {};
|
||||||
usec_t t;
|
usec_t t;
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(e);
|
assert(e);
|
||||||
assert(e->watchdog_fd >= 0);
|
assert(e->watchdog_fd >= 0);
|
||||||
|
@ -3455,8 +3445,7 @@ static int arm_watchdog(sd_event *e) {
|
||||||
if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
|
if (its.it_value.tv_sec == 0 && its.it_value.tv_nsec == 0)
|
||||||
its.it_value.tv_nsec = 1;
|
its.it_value.tv_nsec = 1;
|
||||||
|
|
||||||
r = timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL);
|
if (timerfd_settime(e->watchdog_fd, TFD_TIMER_ABSTIME, &its, NULL) < 0)
|
||||||
if (r < 0)
|
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3866,8 +3855,7 @@ _public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) {
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (!triple_timestamp_is_set(&e->timestamp)) {
|
if (!triple_timestamp_is_set(&e->timestamp)) {
|
||||||
/* Implicitly fall back to now() if we never ran
|
/* Implicitly fall back to now() if we never ran before and thus have no cached time. */
|
||||||
* before and thus have no cached time. */
|
|
||||||
*usec = now(clock);
|
*usec = now(clock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -3946,8 +3934,7 @@ _public_ int sd_event_set_watchdog(sd_event *e, int b) {
|
||||||
.data.ptr = INT_TO_PTR(SOURCE_WATCHDOG),
|
.data.ptr = INT_TO_PTR(SOURCE_WATCHDOG),
|
||||||
};
|
};
|
||||||
|
|
||||||
r = epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, e->watchdog_fd, &ev);
|
if (epoll_ctl(e->epoll_fd, EPOLL_CTL_ADD, e->watchdog_fd, &ev) < 0) {
|
||||||
if (r < 0) {
|
|
||||||
r = -errno;
|
r = -errno;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue