]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine: use free_and_replace() and TAKE_PTR()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 7 Aug 2018 01:11:56 +0000 (10:11 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 7 Aug 2018 01:11:56 +0000 (10:11 +0900)
src/machine/machine.c

index b645f614c416bad7599c829a3d1d4d7ac43a68b1..6ab33d3bea9128a27f63b56713aed87cfca405ec 100644 (file)
@@ -328,14 +328,13 @@ int machine_load(Machine *m) {
 }
 
 static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
-        int r = 0;
-
         assert(m);
         assert(m->class != MACHINE_HOST);
 
         if (!m->unit) {
-                _cleanup_free_ char *escaped = NULL;
-                char *scope, *description, *job = NULL;
+                _cleanup_free_ char *escaped = NULL, *scope = NULL;
+                char *description, *job = NULL;
+                int r;
 
                 escaped = unit_name_escape(m->name);
                 if (!escaped)
@@ -348,22 +347,17 @@ static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_er
                 description = strjoina(m->class == MACHINE_VM ? "Virtual Machine " : "Container ", m->name);
 
                 r = manager_start_scope(m->manager, scope, m->leader, SPECIAL_MACHINE_SLICE, description, properties, error, &job);
-                if (r < 0) {
-                        log_error("Failed to start machine scope: %s", bus_error_message(error, r));
-                        free(scope);
-                        return r;
-                } else {
-                        m->unit = scope;
-
-                        free(m->scope_job);
-                        m->scope_job = job;
-                }
+                if (r < 0)
+                        return log_error_errno(r, "Failed to start machine scope: %s", bus_error_message(error, r));
+
+                m->unit = TAKE_PTR(scope);
+                free_and_replace(m->scope_job, job);
         }
 
         if (m->unit)
                 hashmap_put(m->manager->machine_units, m->unit, m);
 
-        return r;
+        return 0;
 }
 
 int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
@@ -417,15 +411,10 @@ static int machine_stop_scope(Machine *m) {
                 return 0;
 
         r = manager_stop_unit(m->manager, m->unit, &error, &job);
-        if (r < 0) {
-                log_error("Failed to stop machine scope: %s", bus_error_message(&error, r));
-                return r;
-        }
-
-        free(m->scope_job);
-        m->scope_job = job;
+        if (r < 0)
+                return log_error_errno(r, "Failed to stop machine scope: %s", bus_error_message(&error, r));
 
-        return 0;
+        return free_and_replace(m->scope_job, job);
 }
 
 int machine_stop(Machine *m) {