From 53bac4e0e32b017e7a5c1fd1181c740a1583e3fd Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 10 Apr 2015 18:45:39 +0200 Subject: [PATCH] sd-event: simplify sd_event_run() --- src/libsystemd/sd-event/sd-event.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 376477f275b..0dc46803768 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -2490,24 +2490,20 @@ _public_ int sd_event_run(sd_event *e, uint64_t timeout) { assert_return(e->state == SD_EVENT_INITIAL, -EBUSY); r = sd_event_prepare(e); - if (r > 0) { - r = sd_event_dispatch(e); - if (r < 0) - return r; - else - return 1; - } else if (r < 0) - return r; + if (r == 0) + /* There was nothing? Then wait... */ + r = sd_event_wait(e, timeout); - r = sd_event_wait(e, timeout); if (r > 0) { + /* There's something now, then let's dispatch it */ r = sd_event_dispatch(e); if (r < 0) return r; - else - return 1; - } else - return r; + + return 1; + } + + return r; } _public_ int sd_event_loop(sd_event *e) {