diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-01-10 22:45:45 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-01-10 23:03:48 +0100 |
commit | 5dd9014faf58bf974352043fbddd3a8e9c3cd9d9 (patch) | |
tree | 3f884ee7658732e66ee47ab1ed13a15f36218879 /src/core/dbus-manager.c | |
parent | d354315ff7a4e128aea58583a3cbedbf86e69196 (diff) |
dbus: duplicate Job.Cancel() as CancelJob() and Snapshot.Remove() as RemoveSnapshot() on the Manager interface
For all other object mehtods there are already counterparts on the
manager object, as they help us reduce round-trips. So let's complete
this, and reduce complexity on the client side a bit.
As a side effect this also makes "systemctl snapshot" without arguments
work again.
Diffstat (limited to 'src/core/dbus-manager.c')
-rw-r--r-- | src/core/dbus-manager.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 859fa1a906..2d9cea676f 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -106,6 +106,9 @@ " <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \ " <arg name=\"job\" type=\"o\" direction=\"out\"/>\n" \ " </method>\n" \ + " <method name=\"CancelJob\">\n" \ + " <arg name=\"id\" type=\"u\" direction=\"in\"/>\n" \ + " </method>\n" \ " <method name=\"ClearJobs\"/>\n" \ " <method name=\"ResetFailed\"/>\n" \ " <method name=\"ListUnits\">\n" \ @@ -124,6 +127,9 @@ " <arg name=\"cleanup\" type=\"b\" direction=\"in\"/>\n" \ " <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n" \ " </method>\n" \ + " <method name=\"RemoveSnapshot\">\n" \ + " <arg name=\"name\" type=\"s\" direction=\"in\"/>\n" \ + " </method>\n" \ " <method name=\"Reload\"/>\n" \ " <method name=\"Reexecute\"/>\n" \ " <method name=\"Exit\"/>\n" \ @@ -774,10 +780,33 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBUS_TYPE_INVALID)) goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CancelJob")) { + uint32_t id; + Job *j; + + if (!dbus_message_get_args( + message, + &error, + DBUS_TYPE_UINT32, &id, + DBUS_TYPE_INVALID)) + return bus_send_error_reply(connection, message, &error, -EINVAL); + + j = manager_get_job(m, id); + if (!j) { + dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id); + return bus_send_error_reply(connection, message, &error, -ENOENT); + } + + SELINUX_UNIT_ACCESS_CHECK(j->unit, connection, message, "stop"); + job_finish_and_invalidate(j, JOB_CANCELED, true); + + reply = dbus_message_new_method_return(message); + if (!reply) + goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ClearJobs")) { SELINUX_ACCESS_CHECK(connection, message, "reboot"); - manager_clear_jobs(m); reply = dbus_message_new_method_return(message); @@ -1080,6 +1109,35 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBUS_TYPE_INVALID)) goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "RemoveSnapshot")) { + const char *name; + Unit *u; + + if (!dbus_message_get_args( + message, + &error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INVALID)) + return bus_send_error_reply(connection, message, &error, -EINVAL); + + u = manager_get_unit(m, name); + if (!u) { + dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s does not exist.", name); + return bus_send_error_reply(connection, message, &error, -ENOENT); + } + + if (u->type != UNIT_SNAPSHOT) { + dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not a snapshot.", name); + return bus_send_error_reply(connection, message, &error, -ENOENT); + } + + SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "stop"); + snapshot_remove(SNAPSHOT(u)); + + reply = dbus_message_new_method_return(message); + if (!reply) + goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) { char *introspection = NULL; FILE *f; |