1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

sd-event: make errors on EPOLL_CTL_DEL pseudo-fatal

If we call EPOLL_CTL_DEL, we *REALLY* expect the file-descriptor to be
present in that given epoll-set. We actually track such state via our
s->io.registered flag, so it better be true.

Make sure if that's not true, we treat it similar to assert_return() (ie.,
print a loud warning).
This commit is contained in:
David Herrmann 2015-06-17 01:15:09 +02:00
parent 3eb3228e58
commit 366e641139
2 changed files with 11 additions and 15 deletions

View File

@ -248,18 +248,19 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
REENABLE_WARNING REENABLE_WARNING
#endif #endif
#define assert_log(expr) ((_likely_(expr)) \
? (true) \
: (log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__), false))
#define assert_return(expr, r) \ #define assert_return(expr, r) \
do { \ do { \
if (_unlikely_(!(expr))) { \ if (!assert_log(expr)) \
log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
return (r); \ return (r); \
} \
} while (false) } while (false)
#define assert_return_errno(expr, r, err) \ #define assert_return_errno(expr, r, err) \
do { \ do { \
if (_unlikely_(!(expr))) { \ if (!assert_log(expr)) { \
log_assert_failed_return(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
errno = err; \ errno = err; \
return (r); \ return (r); \
} \ } \

View File

@ -468,24 +468,22 @@ static bool event_pid_changed(sd_event *e) {
return e->original_pid != getpid(); return e->original_pid != getpid();
} }
static int source_io_unregister(sd_event_source *s) { static void source_io_unregister(sd_event_source *s) {
int r; int r;
assert(s); assert(s);
assert(s->type == SOURCE_IO); assert(s->type == SOURCE_IO);
if (event_pid_changed(s->event)) if (event_pid_changed(s->event))
return 0; return;
if (!s->io.registered) if (!s->io.registered)
return 0; return;
r = epoll_ctl(s->event->epoll_fd, EPOLL_CTL_DEL, s->io.fd, NULL); r = epoll_ctl(s->event->epoll_fd, EPOLL_CTL_DEL, s->io.fd, NULL);
if (r < 0) assert_log(r >= 0);
return -errno;
s->io.registered = false; s->io.registered = false;
return 0;
} }
static int source_io_register( static int source_io_register(
@ -1457,10 +1455,7 @@ _public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
switch (s->type) { switch (s->type) {
case SOURCE_IO: case SOURCE_IO:
r = source_io_unregister(s); source_io_unregister(s);
if (r < 0)
return r;
s->enabled = m; s->enabled = m;
break; break;