X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=dbus-manager.c;h=754916482936fc48277fda7728cd1191f1f01211;hb=e293f0f07d0dcff74acf756a2b88d7bd949257a7;hp=03a39300df53a6ff9d2268e880f39231c4302376;hpb=a7334b0952ab66c17ee787e36e6d2c5ceb387de6;p=elogind.git
diff --git a/dbus-manager.c b/dbus-manager.c
index 03a39300d..754916482 100644
--- a/dbus-manager.c
+++ b/dbus-manager.c
@@ -38,7 +38,7 @@
" " \
" " \
" " \
- " " \
+ " " \
" " \
" " \
" " \
@@ -47,6 +47,24 @@
" " \
" " \
" " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
" " \
BUS_PROPERTIES_INTERFACE \
BUS_INTROSPECTABLE_INTERFACE
@@ -54,7 +72,7 @@
#define INTROSPECTION_END \
""
-DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
+static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
int r;
Manager *m = data;
DBusError error;
@@ -124,7 +142,7 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
DBUS_TYPE_INVALID))
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "GetJob")) {
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "GetJob")) {
uint32_t id;
Job *j;
@@ -150,14 +168,14 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
DBUS_TYPE_INVALID))
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ClearJobs")) {
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ClearJobs")) {
manager_clear_jobs(m);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ListUnits")) {
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ListUnits")) {
DBusMessageIter iter, sub;
Iterator i;
Unit *u;
@@ -172,7 +190,7 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
goto oom;
HASHMAP_FOREACH_KEY(u, k, m->units, i) {
- char *unit_path, *job_path;
+ char *u_path, *j_path;
const char *id, *description, *load_state, *active_state, *job_type;
DBusMessageIter sub2;
uint32_t job_id;
@@ -188,21 +206,21 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
load_state = unit_load_state_to_string(u->meta.load_state);
active_state = unit_active_state_to_string(unit_active_state(u));
- if (!(unit_path = unit_dbus_path(u)))
+ if (!(u_path = unit_dbus_path(u)))
goto oom;
if (u->meta.job) {
job_id = (uint32_t) u->meta.job->id;
- if (!(job_path = job_dbus_path(u->meta.job))) {
- free(unit_path);
+ if (!(j_path = job_dbus_path(u->meta.job))) {
+ free(u_path);
goto oom;
}
job_type = job_type_to_string(u->meta.job->type);
} else {
job_id = 0;
- job_path = unit_path;
+ j_path = u_path;
job_type = "";
}
@@ -210,19 +228,19 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &unit_path) ||
+ !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &job_type) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &job_path)) {
- free(unit_path);
+ !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path)) {
+ free(u_path);
if (u->meta.job)
- free(job_path);
+ free(j_path);
goto oom;
}
- free(unit_path);
+ free(u_path);
if (u->meta.job)
- free(job_path);
+ free(j_path);
if (!dbus_message_iter_close_container(&sub, &sub2))
goto oom;
@@ -231,7 +249,7 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
if (!dbus_message_iter_close_container(&iter, &sub))
goto oom;
- } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ListJobs")) {
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "ListJobs")) {
DBusMessageIter iter, sub;
Iterator i;
Job *j;
@@ -245,7 +263,7 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
goto oom;
HASHMAP_FOREACH(j, m->jobs, i) {
- char *unit_path, *job_path;
+ char *u_path, *j_path;
const char *unit, *state, *type;
uint32_t id;
DBusMessageIter sub2;
@@ -258,11 +276,11 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
state = job_state_to_string(j->state);
type = job_type_to_string(j->type);
- if (!(job_path = job_dbus_path(j)))
+ if (!(j_path = job_dbus_path(j)))
goto oom;
- if (!(unit_path = unit_dbus_path(j->unit))) {
- free(job_path);
+ if (!(u_path = unit_dbus_path(j->unit))) {
+ free(j_path);
goto oom;
}
@@ -270,15 +288,15 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &unit) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &job_path) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &unit_path)) {
- free(job_path);
- free(unit_path);
+ !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path) ||
+ !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path)) {
+ free(j_path);
+ free(u_path);
goto oom;
}
- free(job_path);
- free(unit_path);
+ free(j_path);
+ free(u_path);
if (!dbus_message_iter_close_container(&sub, &sub2))
goto oom;
@@ -287,6 +305,31 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
if (!dbus_message_iter_close_container(&iter, &sub))
goto oom;
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Subscribe")) {
+ char *client;
+
+ if (!(client = strdup(dbus_message_get_sender(message))))
+ goto oom;
+
+ r = set_put(m->subscribed, client);
+
+ if (r < 0)
+ return bus_send_error_reply(m, message, NULL, r);
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Unsubscribe")) {
+ char *client;
+
+ if (!(client = set_remove(m->subscribed, (char*) dbus_message_get_sender(message))))
+ return bus_send_error_reply(m, message, NULL, -ENOENT);
+
+ free(client);
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
} else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
char *introspection = NULL;
FILE *f;