8d419f
From cb49e80f8adf8fe81b6aa96b17a39a96850dcfa6 Mon Sep 17 00:00:00 2001
8d419f
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
8d419f
Date: Thu, 10 Mar 2022 09:19:37 +0100
8d419f
Subject: [PATCH] shared/install: simplify unit_file_dump_changes()
8d419f
8d419f
No functional change.
8d419f
8d419f
(cherry picked from commit 32450f5348c03262f3257af328b6547cbfba5859)
8d419f
8d419f
Related: #2082131
8d419f
---
8d419f
 src/shared/install.c | 63 +++++++++++++++++++-------------------------
8d419f
 1 file changed, 27 insertions(+), 36 deletions(-)
8d419f
8d419f
diff --git a/src/shared/install.c b/src/shared/install.c
8d419f
index 8d82cb6b16..80863b448b 100644
8d419f
--- a/src/shared/install.c
8d419f
+++ b/src/shared/install.c
8d419f
@@ -320,7 +320,7 @@ void unit_file_changes_free(UnitFileChange *changes, size_t n_changes) {
8d419f
 }
8d419f
 
8d419f
 void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet) {
8d419f
-        bool logged = false;
8d419f
+        int err = 0;
8d419f
 
8d419f
         assert(changes || n_changes == 0);
8d419f
         /* If verb is not specified, errors are not allowed! */
8d419f
@@ -361,64 +361,55 @@ void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *chang
8d419f
                         break;
8d419f
                 case -EEXIST:
8d419f
                         if (changes[i].source)
8d419f
-                                log_error_errno(changes[i].type_or_errno,
8d419f
-                                                "Failed to %s unit, file \"%s\" already exists and is a symlink to \"%s\".",
8d419f
-                                                verb, changes[i].path, changes[i].source);
8d419f
+                                err = log_error_errno(changes[i].type_or_errno,
8d419f
+                                                      "Failed to %s unit, file \"%s\" already exists and is a symlink to \"%s\".",
8d419f
+                                                      verb, changes[i].path, changes[i].source);
8d419f
                         else
8d419f
-                                log_error_errno(changes[i].type_or_errno,
8d419f
-                                                "Failed to %s unit, file \"%s\" already exists.",
8d419f
-                                                verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                                err = log_error_errno(changes[i].type_or_errno,
8d419f
+                                                      "Failed to %s unit, file \"%s\" already exists.",
8d419f
+                                                      verb, changes[i].path);
8d419f
                         break;
8d419f
                 case -ERFKILL:
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is masked.",
8d419f
-                                        verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is masked.",
8d419f
+                                              verb, changes[i].path);
8d419f
                         break;
8d419f
                 case -EADDRNOTAVAIL:
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is transient or generated.",
8d419f
-                                        verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s is transient or generated.",
8d419f
+                                              verb, changes[i].path);
8d419f
                         break;
8d419f
                 case -EBADSLT:
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s unit, invalid specifier in \"%s\".",
8d419f
-                                        verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, invalid specifier in \"%s\".",
8d419f
+                                              verb, changes[i].path);
8d419f
                         break;
8d419f
                 case -EIDRM:
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.",
8d419f
-                                        verb, changes[i].source, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s %s, destination unit %s is a non-template unit.",
8d419f
+                                              verb, changes[i].source, changes[i].path);
8d419f
                         break;
8d419f
                 case -EUCLEAN:
8d419f
-                        log_error_errno(changes[i].type_or_errno,
8d419f
-                                        "Failed to %s unit, \"%s\" is not a valid unit name.",
8d419f
-                                        verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno,
8d419f
+                                              "Failed to %s unit, \"%s\" is not a valid unit name.",
8d419f
+                                              verb, changes[i].path);
8d419f
                         break;
8d419f
                 case -ELOOP:
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s unit, refusing to operate on linked unit file %s.",
8d419f
-                                        verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, refusing to operate on linked unit file %s.",
8d419f
+                                              verb, changes[i].path);
8d419f
                         break;
8d419f
                 case -ENOENT:
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s does not exist.", verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, unit %s does not exist.",
8d419f
+                                              verb, changes[i].path);
8d419f
                         break;
8d419f
                 case -EUNATCH:
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
8d419f
-                                        verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, cannot resolve specifiers in \"%s\".",
8d419f
+                                              verb, changes[i].path);
8d419f
                         break;
8d419f
                 default:
8d419f
                         assert(changes[i].type_or_errno < 0);
8d419f
-                        log_error_errno(changes[i].type_or_errno, "Failed to %s unit, file \"%s\": %m",
8d419f
-                                        verb, changes[i].path);
8d419f
-                        logged = true;
8d419f
+                        err = log_error_errno(changes[i].type_or_errno, "Failed to %s unit, file \"%s\": %m",
8d419f
+                                              verb, changes[i].path);
8d419f
                 }
8d419f
         }
8d419f
 
8d419f
-        if (r < 0 && !logged)
8d419f
+        if (r < 0 && err >= 0)
8d419f
                 log_error_errno(r, "Failed to %s: %m.", verb);
8d419f
 }
8d419f