]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: fixes in read_errno()
authorIvan Kruglov <mail@ikruglov.com>
Thu, 9 Jan 2025 14:02:08 +0000 (15:02 +0100)
committerIvan Kruglov <mail@ikruglov.com>
Fri, 10 Jan 2025 10:49:49 +0000 (11:49 +0100)
follow ups for https://github.com/systemd/systemd/pull/35880

src/basic/process-util.c

index 77045e6aa8e61390734c02fa91fb85b03dd9b690..6af1349dd5697e0b0f462eebed44f14e5089298b 100644 (file)
@@ -2221,20 +2221,25 @@ int read_errno(int errno_fd) {
 
         assert(errno_fd >= 0);
 
-        ssize_t n = loop_read(errno_fd, &r, sizeof(r), /* do_pool = */ 0);
+        /* The issue here is that it's impossible to distinguish between
+         * an error code returned by child and IO error arrised when reading it.
+         * So, the function logs errors and return EIO for the later case. */
+
+        ssize_t n = loop_read(errno_fd, &r, sizeof(r), /* do_poll = */ false);
         if (n < 0) {
                 log_debug_errno(n, "Failed to read errno: %m");
                 return -EIO;
         }
         if (n == sizeof(r)) {
-                /* child processes reported a error, return it */
-                if (r < 0)
+                if (r == 0)
+                        return 0;
+                if (r < 0) /* child process reported an error, return it */
                         return log_debug_errno(r, "Child process failed with errno: %m");
-                return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Received a errno, but it's a positive value");
+                return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Received an errno, but it's a positive value.");
         }
         if (n != 0)
-                return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Received unexpected amount of bytes while reading errno");
+                return log_debug_errno(SYNTHETIC_ERRNO(EIO), "Received unexpected amount of bytes while reading errno.");
 
-        /* the process exited without reporting a error, assuming success */
+        /* the process exited without reporting an error, assuming success */
         return 0;
 }