summaryrefslogtreecommitdiff
path: root/src/machine
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-11-28 22:55:13 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-12-02 12:18:54 +0100
commitbb1a05d6f34b6f17ac1b6b49c93ec0f8f97dfce7 (patch)
tree72e82d880df074f57fd6f71593806d16aac4b3b2 /src/machine
parentb07ec5a173f285c35661150764562fb78bb6fadd (diff)
downloadsystemd-bb1a05d6f34b6f17ac1b6b49c93ec0f8f97dfce7.tar.gz
systemd-bb1a05d6f34b6f17ac1b6b49c93ec0f8f97dfce7.tar.bz2
systemd-bb1a05d6f34b6f17ac1b6b49c93ec0f8f97dfce7.zip
machine: introduce machine_hash_ops and use it
Diffstat (limited to 'src/machine')
-rw-r--r--src/machine/machine.c7
-rw-r--r--src/machine/machine.h2
-rw-r--r--src/machine/machined.c10
3 files changed, 9 insertions, 10 deletions
diff --git a/src/machine/machine.c b/src/machine/machine.c
index e114541b3f..c76dfc1846 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -70,8 +70,9 @@ fail:
return mfree(m);
}
-void machine_free(Machine *m) {
- assert(m);
+Machine* machine_free(Machine *m) {
+ if (!m)
+ return NULL;
while (m->operations)
operation_free(m->operations);
@@ -98,7 +99,7 @@ void machine_free(Machine *m) {
free(m->service);
free(m->root_directory);
free(m->netif);
- free(m);
+ return mfree(m);
}
int machine_save(Machine *m) {
diff --git a/src/machine/machine.h b/src/machine/machine.h
index 967c11039b..31527d029b 100644
--- a/src/machine/machine.h
+++ b/src/machine/machine.h
@@ -65,7 +65,7 @@ struct Machine {
};
Machine* machine_new(Manager *manager, MachineClass class, const char *name);
-void machine_free(Machine *m);
+Machine* machine_free(Machine *m);
bool machine_may_gc(Machine *m, bool drop_not_started);
void machine_add_to_gc_queue(Machine *m);
int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error);
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 6742722d0d..dec2164bb0 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -25,6 +25,9 @@
static Manager* manager_unref(Manager *m);
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref);
+DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(machine_hash_ops, void, trivial_hash_func, trivial_compare_func,
+ Machine, machine_free);
+
static int manager_new(Manager **ret) {
_cleanup_(manager_unrefp) Manager *m = NULL;
int r;
@@ -37,7 +40,7 @@ static int manager_new(Manager **ret) {
m->machines = hashmap_new(&string_hash_ops);
m->machine_units = hashmap_new(&string_hash_ops);
- m->machine_leaders = hashmap_new(NULL);
+ m->machine_leaders = hashmap_new(&machine_hash_ops);
if (!m->machines || !m->machine_units || !m->machine_leaders)
return -ENOMEM;
@@ -61,8 +64,6 @@ static int manager_new(Manager **ret) {
}
static Manager* manager_unref(Manager *m) {
- Machine *machine;
-
if (!m)
return NULL;
@@ -71,9 +72,6 @@ static Manager* manager_unref(Manager *m) {
assert(m->n_operations == 0);
- while ((machine = hashmap_first(m->machines)))
- machine_free(machine);
-
hashmap_free(m->machines);
hashmap_free(m->machine_units);
hashmap_free(m->machine_leaders);