diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-03 17:29:09 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-03 17:34:49 +0200 |
commit | 38a03f06a7393d2721c23f23f0589d2f6d0904af (patch) | |
tree | 18f293ee4b9269aa085120920e2f36ea4a4fe99b /src/resolve | |
parent | 4d2bee0620c04f935f7de0cc10d8d5e5d3e54b6a (diff) |
sd-event: make sure sd_event_now() cannot fail
Previously, if the event loop never ran before sd_event_now() would
fail. With this change it will instead fall back to invoking now(). This
way, the function cannot fail anymore, except for programming error when
invoking it with wrong parameters.
This takes into account the fact that many callers did not handle the
error condition correctly, and if the callers did, then they kept simply
invoking now() as fall back on their own. Hence let's shorten the code
using this call, and make things more robust, and let's just fall back
to now() internally.
Whether now() is used or the cache timestamp may still be detected via
the return value of sd_event_now(). If > 0 is returned, then the fall
back to now() was used, if == 0 is returned, then the cached value was
returned.
This patch also simplifies many of the invocations of sd_event_now():
the manual fall back to now() can be removed. Also, in cases where the
call is invoked withing void functions we can now protect the invocation
via assert_se(), acknowledging the fact that the call cannot fail
anymore except for programming errors with the parameters.
This change is inspired by #841.
Diffstat (limited to 'src/resolve')
-rw-r--r-- | src/resolve/resolved-dns-transaction.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 487b2c5162..53779f3372 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -372,9 +372,7 @@ void dns_transaction_process_reply(DnsTransaction *t, DnsPacket *p) { } } - r = sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts); - if (r < 0) - ts = now(clock_boottime_or_monotonic()); + assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0); switch (t->scope->protocol) { case DNS_PROTOCOL_DNS: @@ -602,9 +600,7 @@ int dns_transaction_go(DnsTransaction *t) { return 0; } - r = sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts); - if (r < 0) - ts = now(clock_boottime_or_monotonic()); + assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0); t->n_attempts++; t->start_usec = ts; |