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