]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Implement simple utility functions for reading and writing to fds
authorChristian Seiler <christian@iwakd.de>
Mon, 20 May 2013 15:54:23 +0000 (17:54 +0200)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 20 May 2013 22:35:46 +0000 (17:35 -0500)
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/utils.c
src/lxc/utils.h

index 66bd19d093d389df5ae697a671f8f223f2f254b3..cd35e00069b14e91c5ba539b8dc3ec5cbf8ec1f2 100644 (file)
@@ -281,3 +281,38 @@ again:
                goto again;
        return status;
 }
+
+int lxc_write_nointr(int fd, const void* buf, size_t count)
+{
+       int ret;
+again:
+       ret = write(fd, buf, count);
+       if (ret < 0 && errno == EINTR)
+               goto again;
+       return ret;
+}
+
+int lxc_read_nointr(int fd, void* buf, size_t count)
+{
+       int ret;
+again:
+       ret = read(fd, buf, count);
+       if (ret < 0 && errno == EINTR)
+               goto again;
+       return ret;
+}
+
+int lxc_read_nointr_expect(int fd, void* buf, size_t count, const void* expected_buf)
+{
+       int ret;
+       ret = lxc_read_nointr(fd, buf, count);
+       if (ret <= 0)
+               return ret;
+       if (ret != count)
+               return -1;
+       if (expected_buf && memcmp(buf, expected_buf, count) != 0) {
+               errno = EINVAL;
+               return -1;
+       }
+       return ret;
+}
index be1a8a8c30929cccc9257726d545e674d0a8f13d..d1242b1f55e987678c4e09cabb8f200b109a3961 100644 (file)
@@ -68,4 +68,9 @@ extern int __build_bug_on_failed;
 extern int wait_for_pid(pid_t pid);
 extern int lxc_wait_for_pid_status(pid_t pid);
 
+/* send and receive buffers completely */
+extern int lxc_write_nointr(int fd, const void* buf, size_t count);
+extern int lxc_read_nointr(int fd, void* buf, size_t count);
+extern int lxc_read_nointr_expect(int fd, void* buf, size_t count, const void* expected_buf);
+
 #endif