chiark / gitweb /
util: add pipe_eof()
authorLennart Poettering <lennart@poettering.net>
Mon, 23 May 2011 21:54:00 +0000 (23:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 21 Jun 2011 17:29:44 +0000 (19:29 +0200)
src/util.c
src/util.h

index 7f59021826d123ce75dbab6f6739c798f806ca2c..4a735dba58025345e4ef5255449ddb424c035960 100644 (file)
@@ -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;
index f2156afb60cd31ac565bf049c211ec5bb9a2a7c3..6076e69dbbcbedc3d2781e2f8869c6d5704ac2cc 100644 (file)
@@ -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);