diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-06-10 11:43:40 +0200 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2020-06-10 20:06:10 +0200 |
commit | 0f2d351f790516bc3f1158d964c5f83f339addb2 (patch) | |
tree | f9df08ab66c5c7be26c92e1767d39835cc9f472c /src/sleep | |
parent | 24bd74ae03efc98272236bd0a98a1d7d090d540c (diff) | |
download | systemd-0f2d351f790516bc3f1158d964c5f83f339addb2.tar.gz |
tree-wide: port to fd_wait_for_event()
Prompted by the discussion on #16110, let's migrate more code to
fd_wait_for_event().
This only leaves 7 places where we call into poll()/poll() directly in
our entire codebase. (one of which is fd_wait_for_event() itself)
Diffstat (limited to 'src/sleep')
-rw-r--r-- | src/sleep/sleep.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 4f9c23099a..11c51fb32b 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -23,6 +23,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "io-util.h" #include "log.h" #include "main-func.h" #include "parse-util.h" @@ -239,7 +240,6 @@ static int execute_s2h(const SleepConfig *sleep_config) { _cleanup_close_ int tfd = -1; char buf[FORMAT_TIMESPAN_MAX]; struct itimerspec ts = {}; - struct pollfd fds; int r; assert(sleep_config); @@ -261,34 +261,25 @@ static int execute_s2h(const SleepConfig *sleep_config) { if (r < 0) return r; - fds = (struct pollfd) { - .fd = tfd, - .events = POLLIN, - }; - r = poll(&fds, 1, 0); + r = fd_wait_for_event(tfd, POLLIN, 0); if (r < 0) - return log_error_errno(errno, "Error polling timerfd: %m"); + return log_error_errno(r, "Error polling timerfd: %m"); + if (!FLAGS_SET(r, POLLIN)) /* We woke up before the alarm time, we are done. */ + return 0; tfd = safe_close(tfd); - if (FLAGS_SET(fds.revents, POLLNVAL)) - return log_error_errno(SYNTHETIC_ERRNO(EBADF), "Invalid timer fd to sleep on?"); - - if (!FLAGS_SET(fds.revents, POLLIN)) /* We woke up before the alarm time, we are done. */ - return 0; - /* If woken up after alarm time, hibernate */ log_debug("Attempting to hibernate after waking from %s timer", format_timespan(buf, sizeof(buf), sleep_config->hibernate_delay_sec, USEC_PER_SEC)); r = execute(sleep_config->hibernate_modes, sleep_config->hibernate_states); if (r < 0) { - log_notice("Couldn't hibernate, will try to suspend again."); + log_notice_errno(r, "Couldn't hibernate, will try to suspend again."); + r = execute(sleep_config->suspend_modes, sleep_config->suspend_states); - if (r < 0) { - log_notice("Could neither hibernate nor suspend again, giving up."); - return r; - } + if (r < 0) + return log_notice_errno(r, "Could neither hibernate nor suspend again, giving up."); } return 0; |