X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=dbus-manager.c;h=a8661bace3332def5359bc410182e93afe07aa74;hb=dec1c02a34b4c5b9da5d2da2dcc09646cf1cef29;hp=32d074502509a58f30cadcf4b077da75422067b3;hpb=2b53c70b6429868029048244b8d21769148375e1;p=elogind.git
diff --git a/dbus-manager.c b/dbus-manager.c
index 32d074502..a8661bace 100644
--- a/dbus-manager.c
+++ b/dbus-manager.c
@@ -1,5 +1,24 @@
/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/***
+ This file is part of systemd.
+
+ Copyright 2010 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with systemd; If not, see .
+***/
+
#include
#include "dbus.h"
@@ -19,7 +38,7 @@
" " \
" " \
" " \
- " " \
+ " " \
" " \
" " \
" " \
@@ -28,6 +47,30 @@
" " \
" " \
" " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
+ " " \
" " \
BUS_PROPERTIES_INTERFACE \
BUS_INTROSPECTABLE_INTERFACE
@@ -35,9 +78,51 @@
#define INTROSPECTION_END \
""
-DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
- int r;
+DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs);
+
+static int bus_manager_append_log_target(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+ const char *t;
+
+ assert(m);
+ assert(i);
+ assert(property);
+
+ t = log_target_to_string(log_get_target());
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
+ return -ENOMEM;
+
+ return 0;
+}
+
+static int bus_manager_append_log_level(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+ const char *t;
+
+ assert(m);
+ assert(i);
+ assert(property);
+
+ t = log_level_to_string(log_get_max_level());
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
+ return -ENOMEM;
+
+ return 0;
+}
+
+static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
+
+ const BusProperty properties[] = {
+ { "org.freedesktop.systemd1", "Version", bus_property_append_string, "s", PACKAGE_VERSION },
+ { "org.freedesktop.systemd1", "RunningAs", bus_manager_append_running_as, "s", &m->running_as },
+ { "org.freedesktop.systemd1", "BootTimestamp", bus_property_append_uint64, "t", &m->boot_timestamp },
+ { "org.freedesktop.systemd1", "LogLevel", bus_manager_append_log_level, "s", NULL },
+ { "org.freedesktop.systemd1", "LogTarget", bus_manager_append_log_target, "s", NULL },
+ { NULL, NULL, NULL, NULL, NULL }
+ };
+
+ int r;
DBusError error;
DBusMessage *reply = NULL;
char * path = NULL;
@@ -105,7 +190,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;
@@ -131,14 +216,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;
@@ -153,7 +238,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;
@@ -169,21 +254,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 = "";
}
@@ -191,19 +276,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;
@@ -212,7 +297,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;
@@ -226,7 +311,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;
@@ -239,11 +324,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;
}
@@ -251,15 +336,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;
@@ -268,6 +353,60 @@ 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.systemd1", "Dump")) {
+ FILE *f;
+ char *dump = NULL;
+ size_t size;
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ if (!(f = open_memstream(&dump, &size)))
+ goto oom;
+
+ manager_dump_units(m, f, NULL);
+ manager_dump_jobs(m, f, NULL);
+
+ if (ferror(f)) {
+ fclose(f);
+ free(dump);
+ goto oom;
+ }
+
+ fclose(f);
+
+ if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &dump, DBUS_TYPE_INVALID)) {
+ free(dump);
+ goto oom;
+ }
+
+ free(dump);
+
} else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
char *introspection = NULL;
FILE *f;
@@ -330,7 +469,7 @@ DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusM
free(introspection);
} else
- return bus_default_message_handler(m, message, NULL, NULL);
+ return bus_default_message_handler(m, message, NULL, properties);
free(path);