summaryrefslogtreecommitdiff
path: root/src/core/dbus-unit.c
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2012-05-21 12:54:34 +0200
committerMichal Schmidt <mschmidt@redhat.com>2012-05-21 12:54:34 +0200
commit80fbf05e75b75b7dd342ec844275efae90c479ec (patch)
tree628670675a636a0532e5fa8da51bcdef47e73b8a /src/core/dbus-unit.c
parentc0ef53aa5b54e2b1d4abe316ebb12d3e1d0d9250 (diff)
dbus-unit: always load the unit before handling a message for it
We need to be able to show the properties even of inactive units. systemctl loads the unit before getting its properties, but this is racy as the garbage collector may kick in right after the loading. Fix it by always loading the unit before handling a message for it. https://bugzilla.redhat.com/show_bug.cgi?id=814966#c6
Diffstat (limited to 'src/core/dbus-unit.c')
-rw-r--r--src/core/dbus-unit.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index b8d661698b..834fbd7693 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -558,12 +558,15 @@ static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DB
Manager *m = data;
Unit *u;
int r;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
+ DBusError error;
assert(connection);
assert(message);
assert(m);
+ dbus_error_init(&error);
+
if (streq(dbus_message_get_path(message), "/org/freedesktop/systemd1/unit")) {
/* Be nice to gdbus and return introspection data for our mid-level paths */
@@ -638,20 +641,12 @@ static DBusHandlerResult bus_unit_message_handler(DBusConnection *connection, DB
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
- if ((r = manager_get_unit_from_dbus_path(m, dbus_message_get_path(message), &u)) < 0) {
-
+ r = manager_load_unit_from_dbus_path(m, dbus_message_get_path(message), &error, &u);
+ if (r < 0) {
if (r == -ENOMEM)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-
- if (r == -ENOENT) {
- DBusError e;
-
- dbus_error_init(&e);
- dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown unit");
- return bus_send_error_reply(connection, message, &e, r);
- }
+ goto oom;
- return bus_send_error_reply(connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, &error, r);
}
return bus_unit_message_dispatch(u, connection, message);
@@ -660,6 +655,8 @@ oom:
if (reply)
dbus_message_unref(reply);
+ dbus_error_free(&error);
+
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}