]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
io-util: make flush_fd() return how many bytes where flushed
authorLennart Poettering <lennart@poettering.net>
Tue, 12 Dec 2017 22:21:09 +0000 (23:21 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2018 12:55:08 +0000 (13:55 +0100)
This is useful so that callers know whether anything at all and how much
was flushed.

This patches through users of this functions to ensure that the return
values > 0 which may be returned now are not propagated in public APIs.

Also, users that ignore the return value are changed to do so explicitly
now.

src/basic/io-util.c
src/core/manager.c
src/libsystemd/sd-login/sd-login.c
src/libudev/libudev-queue.c
src/shared/ask-password-api.c
src/tty-ask-password-agent/tty-ask-password-agent.c

index 77c9bdc739d424076493ecfdc850fa2dc1f2e6f2..08ad42ed952468df310df00972cdecb3a051bfb5 100644 (file)
@@ -33,6 +33,7 @@ int flush_fd(int fd) {
                 .fd = fd,
                 .events = POLLIN,
         };
+        int count = 0;
 
         /* Read from the specified file descriptor, until POLLIN is not set anymore, throwing away everything
          * read. Note that some file descriptors (notable IP sockets) will trigger POLLIN even when no data can be read
@@ -52,7 +53,7 @@ int flush_fd(int fd) {
                         return -errno;
 
                 } else if (r == 0)
-                        return 0;
+                        return count;
 
                 l = read(fd, buf, sizeof(buf));
                 if (l < 0) {
@@ -61,11 +62,13 @@ int flush_fd(int fd) {
                                 continue;
 
                         if (errno == EAGAIN)
-                                return 0;
+                                return count;
 
                         return -errno;
                 } else if (l == 0)
-                        return 0;
+                        return count;
+
+                count += (int) l;
         }
 }
 
index 15720ada24f223b3b7de3cbb8f86974ec11e2361..860d58617fad787d54629491511de57a4489edb2 100644 (file)
@@ -263,7 +263,7 @@ static int manager_dispatch_ask_password_fd(sd_event_source *source,
 
         assert(m);
 
-        flush_fd(fd);
+        (void) flush_fd(fd);
 
         m->have_ask_password = have_ask_password();
         if (m->have_ask_password < 0)
index e8adaa6823238f87baaf682010012ed05345ead9..69572d1a5156e8227700de18c5243195be5bae8b 100644 (file)
@@ -1061,10 +1061,15 @@ _public_ sd_login_monitor* sd_login_monitor_unref(sd_login_monitor *m) {
 }
 
 _public_ int sd_login_monitor_flush(sd_login_monitor *m) {
+        int r;
 
         assert_return(m, -EINVAL);
 
-        return flush_fd(MONITOR_TO_FD(m));
+        r = flush_fd(MONITOR_TO_FD(m));
+        if (r < 0)
+                return r;
+
+        return 0;
 }
 
 _public_ int sd_login_monitor_get_fd(sd_login_monitor *m) {
index b941afb77397449a612b1a1ee1abbdb0449a622d..85ceb263a3ad2fc8f5a3a621ec9a37fdb0ff766d 100644 (file)
@@ -268,8 +268,16 @@ _public_ int udev_queue_get_fd(struct udev_queue *udev_queue) {
  * Returns: the result of clearing the watch for queue changes.
  */
 _public_ int udev_queue_flush(struct udev_queue *udev_queue) {
+        int r;
+
+        assert(udev_queue);
+
         if (udev_queue->fd < 0)
                 return -EINVAL;
 
-        return flush_fd(udev_queue->fd);
+        r = flush_fd(udev_queue->fd);
+        if (r < 0)
+                return r;
+
+        return 0;
 }
index 346d8c9d24e82f1e4de0a1295dd7bf31fdb3cc40..99d6a9b143a2ea7a1d84aa8cca8e7d2bf5dcac5d 100644 (file)
@@ -316,7 +316,7 @@ int ask_password_tty(
                 }
 
                 if (notify >= 0 && pollfd[POLL_INOTIFY].revents != 0)
-                        flush_fd(notify);
+                        (void) flush_fd(notify);
 
                 if (pollfd[POLL_TTY].revents == 0)
                         continue;
index 6e9c10aeb037a6328711791dcf9ff89635dfc74a..d2648ead93147a9f48b056900f0f5bde5829a2de 100644 (file)
@@ -159,7 +159,7 @@ static int ask_password_plymouth(
                 }
 
                 if (notify >= 0 && pollfd[POLL_INOTIFY].revents != 0)
-                        flush_fd(notify);
+                        (void) flush_fd(notify);
 
                 if (pollfd[POLL_SOCKET].revents == 0)
                         continue;