]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/scope.c
core: introduce a helper function to wrap unit_log_{success,failure}
[thirdparty/systemd.git] / src / core / scope.c
index 27ff545313449bd43e7fc76a33f0ca0151aeb17d..151b8989a6416bb38bd7aada60a2ffdb6874636c 100644 (file)
@@ -1,9 +1,4 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  This file is part of systemd.
-
-  Copyright 2013 Lennart Poettering
-***/
 
 #include <errno.h>
 #include <unistd.h>
@@ -13,6 +8,7 @@
 #include "load-dropin.h"
 #include "log.h"
 #include "scope.h"
+#include "serialize.h"
 #include "special.h"
 #include "string-table.h"
 #include "string-util.h"
@@ -115,7 +111,7 @@ static int scope_add_default_dependencies(Scope *s) {
         r = unit_add_two_dependencies_by_name(
                         UNIT(s),
                         UNIT_BEFORE, UNIT_CONFLICTS,
-                        SPECIAL_SHUTDOWN_TARGET, NULL, true,
+                        SPECIAL_SHUTDOWN_TARGET, true,
                         UNIT_DEPENDENCY_DEFAULT);
         if (r < 0)
                 return r;
@@ -133,7 +129,7 @@ static int scope_verify(Scope *s) {
             !MANAGER_IS_RELOADING(UNIT(s)->manager) &&
             !unit_has_name(UNIT(s), SPECIAL_INIT_SCOPE)) {
                 log_unit_error(UNIT(s), "Scope has no PIDs. Refusing.");
-                return -EINVAL;
+                return -ENOENT;
         }
 
         return 0;
@@ -244,9 +240,7 @@ static void scope_enter_dead(Scope *s, ScopeResult f) {
         if (s->result == SCOPE_SUCCESS)
                 s->result = f;
 
-        if (s->result != SCOPE_SUCCESS)
-                log_unit_warning(UNIT(s), "Failed with result '%s'.", scope_result_to_string(s->result));
-
+        unit_log_result(UNIT(s), s->result == SCOPE_SUCCESS, scope_result_to_string(s->result));
         scope_set_state(s, s->result != SCOPE_SUCCESS ? SCOPE_FAILED : SCOPE_DEAD);
 }
 
@@ -407,11 +401,11 @@ static int scope_serialize(Unit *u, FILE *f, FDSet *fds) {
         assert(f);
         assert(fds);
 
-        unit_serialize_item(u, f, "state", scope_state_to_string(s->state));
-        unit_serialize_item(u, f, "was-abandoned", yes_no(s->was_abandoned));
+        (void) serialize_item(f, "state", scope_state_to_string(s->state));
+        (void) serialize_bool(f, "was-abandoned", s->was_abandoned);
 
         if (s->controller)
-                unit_serialize_item(u, f, "controller", s->controller);
+                (void) serialize_item(f, "controller", s->controller);
 
         return 0;
 }
@@ -446,7 +440,7 @@ static int scope_deserialize_item(Unit *u, const char *key, const char *value, F
 
                 r = free_and_strdup(&s->controller, value);
                 if (r < 0)
-                        log_oom();
+                        return log_oom();
 
         } else
                 log_unit_debug(u, "Unknown serialization key: %s", key);