dryang / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
ac3a84
From f0c8da5396c02e2a935e9e8de1e8c08956feb672 Mon Sep 17 00:00:00 2001
ac3a84
From: Lennart Poettering <lennart@poettering.net>
ac3a84
Date: Tue, 22 Nov 2022 12:14:33 +0100
ac3a84
Subject: [PATCH] tree-wide: modernizations with RET_NERRNO()
ac3a84
ac3a84
(cherry picked from commit 108dfff2c7aebadb78e485ed564caf559367bf7c)
ac3a84
ac3a84
Related: #2137584
ac3a84
---
ac3a84
 src/shared/ask-password-api.c | 30 +++++++++++++-----------------
ac3a84
 src/shared/barrier.c          |  4 +---
ac3a84
 2 files changed, 14 insertions(+), 20 deletions(-)
ac3a84
ac3a84
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
ac3a84
index 17474fe0be..871af2ec99 100644
ac3a84
--- a/src/shared/ask-password-api.c
ac3a84
+++ b/src/shared/ask-password-api.c
ac3a84
@@ -230,8 +230,7 @@ int ask_password_plymouth(
ac3a84
                 if (notify < 0)
ac3a84
                         return -errno;
ac3a84
 
ac3a84
-                r = inotify_add_watch(notify, flag_file, IN_ATTRIB); /* for the link count */
ac3a84
-                if (r < 0)
ac3a84
+                if (inotify_add_watch(notify, flag_file, IN_ATTRIB) < 0) /* for the link count */
ac3a84
                         return -errno;
ac3a84
         }
ac3a84
 
ac3a84
@@ -239,8 +238,7 @@ int ask_password_plymouth(
ac3a84
         if (fd < 0)
ac3a84
                 return -errno;
ac3a84
 
ac3a84
-        r = connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
ac3a84
-        if (r < 0)
ac3a84
+        if (connect(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)) < 0)
ac3a84
                 return -errno;
ac3a84
 
ac3a84
         if (FLAGS_SET(flags, ASK_PASSWORD_ACCEPT_CACHED)) {
ac3a84
@@ -464,10 +462,9 @@ int ask_password_tty(
ac3a84
                 new_termios.c_cc[VMIN] = 1;
ac3a84
                 new_termios.c_cc[VTIME] = 0;
ac3a84
 
ac3a84
-                if (tcsetattr(ttyfd, TCSADRAIN, &new_termios) < 0) {
ac3a84
-                        r = -errno;
ac3a84
+                r = RET_NERRNO(tcsetattr(ttyfd, TCSADRAIN, &new_termios));
ac3a84
+                if (r < 0)
ac3a84
                         goto finish;
ac3a84
-                }
ac3a84
 
ac3a84
                 reset_tty = true;
ac3a84
         }
ac3a84
@@ -491,11 +488,11 @@ int ask_password_tty(
ac3a84
                 else
ac3a84
                         timeout = USEC_INFINITY;
ac3a84
 
ac3a84
-                if (flag_file)
ac3a84
-                        if (access(flag_file, F_OK) < 0) {
ac3a84
-                                r = -errno;
ac3a84
+                if (flag_file) {
ac3a84
+                        r = RET_NERRNO(access(flag_file, F_OK));
ac3a84
+                        if (r < 0)
ac3a84
                                 goto finish;
ac3a84
-                        }
ac3a84
+                }
ac3a84
 
ac3a84
                 r = ppoll_usec(pollfd, notify >= 0 ? 2 : 1, timeout);
ac3a84
                 if (r == -EINTR)
ac3a84
@@ -747,10 +744,10 @@ int ask_password_agent(
ac3a84
                         r = -errno;
ac3a84
                         goto finish;
ac3a84
                 }
ac3a84
-                if (inotify_add_watch(notify, "/run/systemd/ask-password", IN_ATTRIB /* for mtime */) < 0) {
ac3a84
-                        r = -errno;
ac3a84
+
ac3a84
+                r = RET_NERRNO(inotify_add_watch(notify, "/run/systemd/ask-password", IN_ATTRIB /* for mtime */));
ac3a84
+                if (r < 0)
ac3a84
                         goto finish;
ac3a84
-                }
ac3a84
         }
ac3a84
 
ac3a84
         fd = mkostemp_safe(temp);
ac3a84
@@ -813,10 +810,9 @@ int ask_password_agent(
ac3a84
         final[sizeof(final)-10] = 's';
ac3a84
         final[sizeof(final)-9] = 'k';
ac3a84
 
ac3a84
-        if (rename(temp, final) < 0) {
ac3a84
-                r = -errno;
ac3a84
+        r = RET_NERRNO(rename(temp, final));
ac3a84
+        if (r < 0)
ac3a84
                 goto finish;
ac3a84
-        }
ac3a84
 
ac3a84
         zero(pollfd);
ac3a84
         pollfd[FD_SOCKET].fd = socket_fd;
ac3a84
diff --git a/src/shared/barrier.c b/src/shared/barrier.c
ac3a84
index cbe54a60cd..d76a61a5db 100644
ac3a84
--- a/src/shared/barrier.c
ac3a84
+++ b/src/shared/barrier.c
ac3a84
@@ -92,7 +92,6 @@
ac3a84
  */
ac3a84
 int barrier_create(Barrier *b) {
ac3a84
         _unused_ _cleanup_(barrier_destroyp) Barrier *staging = b;
ac3a84
-        int r;
ac3a84
 
ac3a84
         assert(b);
ac3a84
 
ac3a84
@@ -104,8 +103,7 @@ int barrier_create(Barrier *b) {
ac3a84
         if (b->them < 0)
ac3a84
                 return -errno;
ac3a84
 
ac3a84
-        r = pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK);
ac3a84
-        if (r < 0)
ac3a84
+        if (pipe2(b->pipe, O_CLOEXEC | O_NONBLOCK) < 0)
ac3a84
                 return -errno;
ac3a84
 
ac3a84
         staging = NULL;