summaryrefslogtreecommitdiff
path: root/src/machine
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2022-11-30 16:46:05 +0100
committerDavid Tardon <dtardon@redhat.com>2022-12-14 09:57:35 +0100
commit359e8d76e8addf1d88aa8f8b07a9b09817efbdb6 (patch)
treee3799ef7dc6437e2b8370f7186581d2b613d2b56 /src/machine
parent38f514409ac2f98b04a15c6e47a659a43618bd3b (diff)
downloadsystemd-359e8d76e8addf1d88aa8f8b07a9b09817efbdb6.tar.gz
machine: propagate error from machine_new
Diffstat (limited to 'src/machine')
-rw-r--r--src/machine/machine.c18
-rw-r--r--src/machine/machine.h2
-rw-r--r--src/machine/machined-dbus.c7
-rw-r--r--src/machine/machined.c6
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;