From 1325aa4202cbd393c9577794e2b4995cc8743892 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 23 May 2011 23:54:00 +0200 Subject: [PATCH] util: add pipe_eof() --- src/util.c | 18 ++++++++++++++++++ src/util.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/util.c b/src/util.c index 7f5902182..4a735dba5 100644 --- a/src/util.c +++ b/src/util.c @@ -4437,6 +4437,24 @@ char* hostname_cleanup(char *s) { return s; } +int pipe_eof(int fd) { + struct pollfd pollfd; + int r; + + zero(pollfd); + pollfd.fd = fd; + pollfd.events = POLLIN|POLLHUP; + + r = poll(&pollfd, 1, 0); + if (r < 0) + return -errno; + + if (r == 0) + return 0; + + return pollfd.revents & POLLHUP; +} + int terminal_vhangup_fd(int fd) { if (ioctl(fd, TIOCVHANGUP) < 0) return -errno; diff --git a/src/util.h b/src/util.h index f2156afb6..6076e69db 100644 --- a/src/util.h +++ b/src/util.h @@ -357,6 +357,8 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid); int rm_rf(const char *path, bool only_dirs, bool delete_root); +int pipe_eof(int fd); + cpu_set_t* cpu_set_malloc(unsigned *ncpus); void status_vprintf(const char *format, va_list ap); -- 2.30.2