Skip to content

Commit a658caf

Browse files
committed
machined: simplifications
1 parent 6ee69ba commit a658caf

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

src/machine/machine-dbus.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ int machine_send_create_reply(Machine *m, sd_bus_error *error) {
210210
c = m->create_message;
211211
m->create_message = NULL;
212212

213+
if (error)
214+
return sd_bus_reply_method_error(m->manager->bus, c, error);
215+
213216
/* Update the machine state file before we notify the client
214217
* about the result. */
215218
machine_save(m);
216219

217-
if (error)
218-
return sd_bus_reply_method_error(m->manager->bus, c, error);
219-
220220
p = machine_bus_path(m);
221221
if (!p)
222222
return -ENOMEM;

src/machine/machine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ int machine_stop(Machine *m) {
338338
return r;
339339
}
340340

341-
int machine_check_gc(Machine *m, bool drop_not_started) {
341+
bool machine_check_gc(Machine *m, bool drop_not_started) {
342342
assert(m);
343343

344344
if (drop_not_started && !m->started)

src/machine/machine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct Machine {
8080

8181
Machine* machine_new(Manager *manager, const char *name);
8282
void machine_free(Machine *m);
83-
int machine_check_gc(Machine *m, bool drop_not_started);
83+
bool machine_check_gc(Machine *m, bool drop_not_started);
8484
void machine_add_to_gc_queue(Machine *m);
8585
int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error);
8686
int machine_stop(Machine *m);

src/machine/machined-dbus.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,9 @@ const sd_bus_vtable manager_vtable[] = {
335335
};
336336

337337
int machine_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
338+
_cleanup_strv_free_ char **l = NULL;
338339
Machine *machine = NULL;
339340
Manager *m = userdata;
340-
char **l = NULL;
341341
Iterator i;
342342
int r;
343343

@@ -360,6 +360,8 @@ int machine_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *
360360
}
361361

362362
*nodes = l;
363+
l = NULL;
364+
363365
return 1;
364366
}
365367

@@ -456,6 +458,8 @@ int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
456458

457459
int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata) {
458460
Manager *m = userdata;
461+
Machine *machine;
462+
Iterator i;
459463
int b, r;
460464

461465
assert(bus);
@@ -466,16 +470,14 @@ int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata) {
466470
return 0;
467471
}
468472

469-
/* systemd finished reloading, let's recheck all our machines */
470-
if (!b) {
471-
Machine *machine;
472-
Iterator i;
473+
if (b)
474+
return 0;
473475

474-
log_debug("System manager has been reloaded, rechecking machines...");
476+
/* systemd finished reloading, let's recheck all our machines */
477+
log_debug("System manager has been reloaded, rechecking machines...");
475478

476-
HASHMAP_FOREACH(machine, m->machines, i)
477-
machine_add_to_gc_queue(machine);
478-
}
479+
HASHMAP_FOREACH(machine, m->machines, i)
480+
machine_add_to_gc_queue(machine);
479481

480482
return 0;
481483
}
@@ -507,7 +509,7 @@ int manager_start_scope(
507509
if (r < 0)
508510
return r;
509511

510-
r = sd_bus_message_append(m, "ss", scope, "fail");
512+
r = sd_bus_message_append(m, "ss", strempty(scope), "fail");
511513
if (r < 0)
512514
return r;
513515

@@ -620,23 +622,18 @@ int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, c
620622
}
621623

622624
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error) {
623-
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
624-
int r;
625-
626625
assert(manager);
627626
assert(unit);
628627

629-
r = sd_bus_call_method(
628+
return sd_bus_call_method(
630629
manager->bus,
631630
"org.freedesktop.systemd1",
632631
"/org/freedesktop/systemd1",
633632
"org.freedesktop.systemd1.Manager",
634633
"KillUnit",
635634
error,
636-
&reply,
635+
NULL,
637636
"ssi", unit, who == KILL_LEADER ? "main" : "all", signo);
638-
639-
return r;
640637
}
641638

642639
int manager_unit_is_active(Manager *manager, const char *unit) {

src/machine/machined.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ Manager *manager_new(void) {
4747
m->machines = hashmap_new(string_hash_func, string_compare_func);
4848
m->machine_units = hashmap_new(string_hash_func, string_compare_func);
4949

50-
r = sd_event_new(&m->event);
51-
if (r < 0) {
50+
if (!m->machines || !m->machine_units) {
5251
manager_free(m);
5352
return NULL;
5453
}
5554

56-
if (!m->machines || !m->machine_units) {
55+
r = sd_event_new(&m->event);
56+
if (r < 0) {
5757
manager_free(m);
5858
return NULL;
5959
}
@@ -284,7 +284,7 @@ void manager_gc(Manager *m, bool drop_not_started) {
284284
LIST_REMOVE(gc_queue, m->machine_gc_queue, machine);
285285
machine->in_gc_queue = false;
286286

287-
if (machine_check_gc(machine, drop_not_started) == 0) {
287+
if (!machine_check_gc(machine, drop_not_started)) {
288288
machine_stop(machine);
289289
machine_free(machine);
290290
}

src/machine/machined.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ Manager *manager_new(void);
4848
void manager_free(Manager *m);
4949

5050
int manager_add_machine(Manager *m, const char *name, Machine **_machine);
51-
5251
int manager_enumerate_machines(Manager *m);
5352

5453
int manager_startup(Manager *m);

0 commit comments

Comments
 (0)