diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-11-24 01:42:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-24 01:42:48 +0100 |
commit | 00a60eaf5fcb3a0e415349aa649f2699550d26b0 (patch) | |
tree | 211135dfa606bf397a61c1a20db4a9d4b033f6d8 /src/basic | |
parent | core: add possibility to not track certain unit types (diff) | |
parent | io-util: document EINTR situation a bit (diff) | |
download | systemd-00a60eaf5fcb3a0e415349aa649f2699550d26b0.tar.xz systemd-00a60eaf5fcb3a0e415349aa649f2699550d26b0.zip |
Merge pull request #25483 from poettering/ppoll-usec-eintr
ppoll() + EINTR fixes
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/io-util.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/basic/io-util.c b/src/basic/io-util.c index cdad939aa6..f642beca3a 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -161,6 +161,21 @@ int ppoll_usec(struct pollfd *fds, size_t nfds, usec_t timeout) { assert(fds || nfds == 0); + /* This is a wrapper around ppoll() that does primarily two things: + * + * ✅ Takes a usec_t instead of a struct timespec + * + * ✅ Guarantees that if an invalid fd is specified we return EBADF (i.e. converts POLLNVAL to + * EBADF). This is done because EBADF is a programming error usually, and hence should bubble up + * as error, and not be eaten up as non-error POLLNVAL event. + * + * ⚠️ ⚠️ ⚠️ Note that this function does not add any special handling for EINTR. Don't forget + * poll()/ppoll() will return with EINTR on any received signal always, there is no automatic + * restarting via SA_RESTART available. Thus, typically you want to handle EINTR not as an error, + * but just as reason to restart things, under the assumption you use a more appropriate mechanism + * to handle signals, such as signalfd() or signal handlers. ⚠️ ⚠️ ⚠️ + */ + if (nfds == 0) return 0; @@ -188,6 +203,9 @@ int fd_wait_for_event(int fd, int event, usec_t timeout) { }; int r; + /* ⚠️ ⚠️ ⚠️ Keep in mind you almost certainly want to handle -EINTR gracefully in the caller, see + * ppoll_usec() above! ⚠️ ⚠️ ⚠️ */ + r = ppoll_usec(&pollfd, 1, timeout); if (r <= 0) return r; |