summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2012-09-18 20:22:57 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2012-09-19 08:25:36 +0200
commitd3b52baff90876a648e321f3658a74bc58a8647c (patch)
tree2e199b9d68a731d1649dfa28a4c63a8766991dcb
parent67445f4e22ad924394acdd4fd49e6f238244a5ca (diff)
systemctl: use automatic cleanup
Introduce a helper method to unref dbus messages and use it.
-rw-r--r--src/shared/dbus-common.c6
-rw-r--r--src/shared/dbus-common.h3
-rw-r--r--src/systemctl/systemctl.c22
3 files changed, 17 insertions, 14 deletions
diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c
index 0c73d6c6a8..c53bf59eb3 100644
--- a/src/shared/dbus-common.c
+++ b/src/shared/dbus-common.c
@@ -1318,3 +1318,9 @@ finish:
return r;
}
+
+
+void dbus_message_unref_p(DBusMessage **reply) {
+ if (*reply)
+ dbus_message_unref(*reply);
+}
diff --git a/src/shared/dbus-common.h b/src/shared/dbus-common.h
index e49c3b5258..7294206bc4 100644
--- a/src/shared/dbus-common.h
+++ b/src/shared/dbus-common.h
@@ -213,3 +213,6 @@ int bus_method_call_with_reply(DBusConnection *bus,
DBusMessage **return_reply,
DBusError *return_error,
int first_arg_type, ...);
+
+void dbus_message_unref_p(DBusMessage **reply);
+#define _cleanup_dbus_msg_unref_ __attribute__((cleanup(dbus_message_unref_p)))
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0e564a5428..367dd8060a 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1441,22 +1441,22 @@ static void check_triggering_units(
DBusConnection *bus,
const char *unit_name) {
- DBusMessage *reply = NULL;
+ DBusMessage _cleanup_dbus_msg_unref_ *reply = NULL;
DBusMessageIter iter, sub;
char *service_trigger = NULL;
const char *interface = "org.freedesktop.systemd1.Unit",
*triggered_by_property = "TriggeredBy";
- char *unit_path = NULL, *n = NULL;
+ char _cleanup_free_ *unit_path = NULL, *n = NULL;
bool print_warning_label = true;
int r;
n = unit_name_mangle(unit_name);
unit_path = unit_dbus_path_from_name(n ? n : unit_name);
- free(n);
+
if (!unit_path) {
log_error("Could not allocate dbus path.");
- goto finish;
+ return;
}
r = bus_method_call_with_reply (
@@ -1471,13 +1471,12 @@ static void check_triggering_units(
DBUS_TYPE_STRING, &triggered_by_property,
DBUS_TYPE_INVALID);
if (r)
- goto finish;
+ return;
if (!dbus_message_iter_init(reply, &iter) ||
dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) {
log_error("Failed to parse reply.");
- goto finish;
-
+ return;
}
dbus_message_iter_recurse(&iter, &sub);
@@ -1488,14 +1487,14 @@ static void check_triggering_units(
if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING) {
log_error("Failed to parse reply.");
- goto finish;
+ return;
}
dbus_message_iter_get_basic(&sub, &service_trigger);
r = check_one_unit(bus, service_trigger, true);
if (r < 0)
- goto finish;
+ return;
if (r == 0) {
if (print_warning_label) {
log_warning("Warning: Stopping %s, but it can still be activated by:", unit_name);
@@ -1506,11 +1505,6 @@ static void check_triggering_units(
dbus_message_iter_next(&sub);
}
-finish:
- if (reply)
- dbus_message_unref(reply);
-
- free(unit_path);
}
static int start_unit_one(