]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: loop_write - accept 0-length message
authorTom Gundersen <teg@jklm.no>
Fri, 15 May 2015 23:07:45 +0000 (01:07 +0200)
committerTom Gundersen <teg@jklm.no>
Fri, 15 May 2015 23:14:48 +0000 (01:14 +0200)
write() can send empty messages, so make sure loop_write() can do the same.

src/shared/util.c

index dda88bd2ee830545c10633902f875092f87533a0..3060adc8a659214da2b7b5687ff4f05df541ed7a 100644 (file)
@@ -1664,7 +1664,7 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
 
         errno = 0;
 
-        while (nbytes > 0) {
+        do {
                 ssize_t k;
 
                 k = write(fd, p, nbytes);
@@ -1684,12 +1684,12 @@ int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
                         return -errno;
                 }
 
-                if (k == 0) /* Can't really happen */
+                if (nbytes > 0 && k == 0) /* Can't really happen */
                         return -EIO;
 
                 p += k;
                 nbytes -= k;
-        }
+        } while (nbytes > 0);
 
         return 0;
 }