diff options
Diffstat (limited to 'src/machine')
-rw-r--r-- | src/machine/machine.c | 18 | ||||
-rw-r--r-- | src/machine/machine.h | 2 | ||||
-rw-r--r-- | src/machine/machined-dbus.c | 7 | ||||
-rw-r--r-- | src/machine/machined.c | 6 |
4 files changed, 19 insertions, 14 deletions
diff --git a/src/machine/machine.c b/src/machine/machine.c index ca43c977b0..c08a645814 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -35,12 +35,14 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Machine*, machine_free); -Machine* machine_new(Manager *manager, MachineClass class, const char *name) { +int machine_new(Manager *manager, MachineClass class, const char *name, Machine **ret) { _cleanup_(machine_freep) Machine *m = NULL; + int r; assert(manager); assert(class < _MACHINE_CLASS_MAX); assert(name); + assert(ret); /* Passing class == _MACHINE_CLASS_INVALID here is fine. It * means as much as "we don't know yet", and that we'll figure @@ -48,26 +50,28 @@ Machine* machine_new(Manager *manager, MachineClass class, const char *name) { m = new0(Machine, 1); if (!m) - return NULL; + return -ENOMEM; m->name = strdup(name); if (!m->name) - return NULL; + return -ENOMEM; if (class != MACHINE_HOST) { m->state_file = path_join("/run/systemd/machines", m->name); if (!m->state_file) - return NULL; + return -ENOMEM; } m->class = class; - if (hashmap_put(manager->machines, m->name, m) < 0) - return NULL; + r = hashmap_put(manager->machines, m->name, m); + if (r < 0) + return r; m->manager = manager; - return TAKE_PTR(m); + *ret = TAKE_PTR(m); + return 0; } Machine* machine_free(Machine *m) { diff --git a/src/machine/machine.h b/src/machine/machine.h index 5e0e529567..54ebcb3b26 100644 --- a/src/machine/machine.h +++ b/src/machine/machine.h @@ -66,7 +66,7 @@ struct Machine { LIST_FIELDS(Machine, gc_queue); }; -Machine* machine_new(Manager *manager, MachineClass class, const char *name); +int machine_new(Manager *manager, MachineClass class, const char *name, Machine **ret); Machine* machine_free(Machine *m); bool machine_may_gc(Machine *m, bool drop_not_started); void machine_add_to_gc_queue(Machine *m); diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 56dd22d757..3da639279d 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -1492,15 +1492,16 @@ int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) { int manager_add_machine(Manager *m, const char *name, Machine **_machine) { Machine *machine; + int r; assert(m); assert(name); machine = hashmap_get(m->machines, name); if (!machine) { - machine = machine_new(m, _MACHINE_CLASS_INVALID, name); - if (!machine) - return -ENOMEM; + r = machine_new(m, _MACHINE_CLASS_INVALID, name, &machine); + if (r < 0) + return r; } if (_machine) diff --git a/src/machine/machined.c b/src/machine/machined.c index 9ecba8720f..b4ff97ab70 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -117,9 +117,9 @@ static int manager_add_host_machine(Manager *m) { if (!unit) return log_oom(); - t = machine_new(m, MACHINE_HOST, ".host"); - if (!t) - return log_oom(); + r = machine_new(m, MACHINE_HOST, ".host", &t); + if (r < 0) + return log_error_errno(r, "Failed to create machine: %m"); t->leader = 1; t->id = mid; |