diff options
-rw-r--r-- | Makefile.am | 16 | ||||
-rw-r--r-- | automount.c | 3 | ||||
-rw-r--r-- | dbus-automount.c | 44 | ||||
-rw-r--r-- | dbus-automount.h | 31 | ||||
-rw-r--r-- | dbus-device.c | 44 | ||||
-rw-r--r-- | dbus-device.h | 31 | ||||
-rw-r--r-- | dbus-execute.c | 28 | ||||
-rw-r--r-- | dbus-execute.h | 79 | ||||
-rw-r--r-- | dbus-job.c | 5 | ||||
-rw-r--r-- | dbus-job.h | 32 | ||||
-rw-r--r-- | dbus-manager.c | 66 | ||||
-rw-r--r-- | dbus-manager.h | 29 | ||||
-rw-r--r-- | dbus-mount.c | 55 | ||||
-rw-r--r-- | dbus-mount.h | 31 | ||||
-rw-r--r-- | dbus-service.c | 78 | ||||
-rw-r--r-- | dbus-service.h | 31 | ||||
-rw-r--r-- | dbus-snapshot.c | 75 | ||||
-rw-r--r-- | dbus-snapshot.h | 31 | ||||
-rw-r--r-- | dbus-socket.c | 64 | ||||
-rw-r--r-- | dbus-socket.h | 31 | ||||
-rw-r--r-- | dbus-target.c | 42 | ||||
-rw-r--r-- | dbus-target.h | 31 | ||||
-rw-r--r-- | dbus-unit.c | 146 | ||||
-rw-r--r-- | dbus-unit.h | 101 | ||||
-rw-r--r-- | dbus.c | 30 | ||||
-rw-r--r-- | dbus.h | 23 | ||||
-rw-r--r-- | device.c | 3 | ||||
-rw-r--r-- | job.c | 1 | ||||
-rw-r--r-- | manager.c | 2 | ||||
-rw-r--r-- | mount.c | 4 | ||||
-rw-r--r-- | service.c | 3 | ||||
-rw-r--r-- | socket.c | 5 | ||||
-rw-r--r-- | systemd-interfaces.vala | 8 | ||||
-rw-r--r-- | target.c | 5 | ||||
-rw-r--r-- | unit.c | 1 | ||||
-rw-r--r-- | unit.h | 3 |
36 files changed, 1115 insertions, 97 deletions
diff --git a/Makefile.am b/Makefile.am index 8cad1420e0..8720e7898f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -128,6 +128,22 @@ COMMON_SOURCES= \ dbus-unit.h \ dbus-job.c \ dbus-job.h \ + dbus-service.c \ + dbus-service.h \ + dbus-socket.c \ + dbus-socket.h \ + dbus-target.c \ + dbus-target.h \ + dbus-mount.c \ + dbus-mount.h \ + dbus-automount.c \ + dbus-autpmount.h \ + dbus-snapshot.c \ + dbus-snapshot.h \ + dbus-device.c \ + dbus-device.h \ + dbus-execute.c \ + dbus-execute.h \ cgroup.c \ cgroup.h \ mount-setup.c \ diff --git a/automount.c b/automount.c index 5d79131afc..fa5fd52552 100644 --- a/automount.c +++ b/automount.c @@ -34,6 +34,7 @@ #include "load-fragment.h" #include "load-dropin.h" #include "unit-name.h" +#include "dbus-automount.h" static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = { [AUTOMOUNT_DEAD] = UNIT_INACTIVE, @@ -602,5 +603,7 @@ const UnitVTable automount_vtable = { .fd_event = automount_fd_event, + .bus_message_handler = bus_automount_message_handler, + .shutdown = automount_shutdown }; diff --git a/dbus-automount.c b/dbus-automount.c new file mode 100644 index 0000000000..9003b74b8a --- /dev/null +++ b/dbus-automount.c @@ -0,0 +1,44 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include "dbus-unit.h" +#include "dbus-automount.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "<node>" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " <interface name=\"org.freedesktop.systemd1.Automount\">" + " <property name=\"Where\" type=\"s\" access=\"read\"/>" + " </interface>" + BUS_INTROSPECTABLE_INTERFACE + "</node>"; + +DBusHandlerResult bus_automount_message_handler(Unit *u, DBusMessage *message) { + const BusProperty properties[] = { + BUS_UNIT_PROPERTIES, + { "org.freedesktop.systemd1.Automount", "Where", bus_property_append_string, "s", u->automount.where }, + { NULL, NULL, NULL, NULL, NULL } + }; + + return bus_default_message_handler(u->meta.manager, message, introspection, properties); +} diff --git a/dbus-automount.h b/dbus-automount.h new file mode 100644 index 0000000000..947bf0f59f --- /dev/null +++ b/dbus-automount.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusautomounthfoo +#define foodbusautomounthfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "unit.h" + +DBusHandlerResult bus_automount_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-device.c b/dbus-device.c new file mode 100644 index 0000000000..83764783ad --- /dev/null +++ b/dbus-device.c @@ -0,0 +1,44 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include "dbus-unit.h" +#include "dbus-device.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "<node>" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " <interface name=\"org.freedesktop.systemd1.Device\">" + " <property name=\"SysFSPath\" type=\"s\" access=\"read\"/>" + " </interface>" + BUS_INTROSPECTABLE_INTERFACE + "</node>"; + +DBusHandlerResult bus_device_message_handler(Unit *u, DBusMessage *message) { + const BusProperty properties[] = { + BUS_UNIT_PROPERTIES, + { "org.freedesktop.systemd1.Device", "SysFSPath", bus_property_append_string, "s", u->device.sysfs }, + { NULL, NULL, NULL, NULL, NULL } + }; + + return bus_default_message_handler(u->meta.manager, message, introspection, properties); +} diff --git a/dbus-device.h b/dbus-device.h new file mode 100644 index 0000000000..f2850a63f8 --- /dev/null +++ b/dbus-device.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusdevicehfoo +#define foodbusdevicehfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "unit.h" + +DBusHandlerResult bus_device_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-execute.c b/dbus-execute.c new file mode 100644 index 0000000000..8840396bc1 --- /dev/null +++ b/dbus-execute.c @@ -0,0 +1,28 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include <errno.h> +#include <dbus/dbus.h> + +#include "dbus-execute.h" + +DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput); +DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput); diff --git a/dbus-execute.h b/dbus-execute.h new file mode 100644 index 0000000000..25ecd982a4 --- /dev/null +++ b/dbus-execute.h @@ -0,0 +1,79 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusexecutehfoo +#define foodbusexecutehfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "manager.h" + +#define BUS_EXEC_CONTEXT_INTERFACE \ + " <property name=\"Environment\" type=\"as\" access=\"read\"/>" \ + " <property name=\"UMask\" type=\"u\" access=\"read\"/>" \ + " <property name=\"WorkingDirectory\" type=\"s\" access=\"read\"/>" \ + " <property name=\"RootDirectory\" type=\"s\" access=\"read\"/>" \ + " <property name=\"CPUSchedulingResetOnFork\" type=\"b\" access=\"read\"/>" \ + " <property name=\"NonBlocking\" type=\"b\" access=\"read\"/>" \ + " <property name=\"StandardInput\" type=\"s\" access=\"read\"/>" \ + " <property name=\"StandardOutput\" type=\"s\" access=\"read\"/>" \ + " <property name=\"StandardError\" type=\"s\" access=\"read\"/>" \ + " <property name=\"TTYPath\" type=\"s\" access=\"read\"/>" \ + " <property name=\"SyslogPriority\" type=\"i\" access=\"read\"/>" \ + " <property name=\"SyslogIdentifier\" type=\"s\" access=\"read\"/>" \ + " <property name=\"SecureBits\" type=\"i\" access=\"read\"/>" \ + " <property name=\"CapabilityBoundingSetDrop\" type=\"t\" access=\"read\"/>" \ + " <property name=\"User\" type=\"s\" access=\"read\"/>" \ + " <property name=\"Group\" type=\"s\" access=\"read\"/>" \ + " <property name=\"SupplementaryGroups\" type=\"as\" access=\"read\"/>" + +#define BUS_EXEC_CONTEXT_PROPERTIES(interface, context) \ + { interface, "Environment", bus_property_append_strv, "as", (context).environment }, \ + { interface, "UMask", bus_property_append_mode, "u", &(context).umask }, \ + /* RLimits */ \ + { interface, "WorkingDirectory", bus_property_append_string, "s", (context).working_directory }, \ + { interface, "RootDirectory", bus_property_append_string, "s", (context).root_directory }, \ + /* OOM Adjust */ \ + /* Nice */ \ + /* IOPrio */ \ + /* CPUSchedPolicy */ \ + /* CPUSchedPriority */ \ + /* CPUAffinity */ \ + /* TimerSlackNS */ \ + { interface, "CPUSchedulingResetOnFork", bus_property_append_bool, "b", &(context).cpu_sched_reset_on_fork }, \ + { interface, "NonBlocking", bus_property_append_bool, "b", &(context).non_blocking }, \ + { interface, "StandardInput", bus_execute_append_input, "s", &(context).std_input }, \ + { interface, "StandardOutput", bus_execute_append_output, "s", &(context).std_output }, \ + { interface, "StandardError", bus_execute_append_output, "s", &(context).std_error }, \ + { interface, "TTYPath", bus_property_append_string, "s", (context).tty_path }, \ + { interface, "SyslogPriority", bus_property_append_int, "i", &(context).syslog_priority }, \ + { interface, "SyslogIdentifier", bus_property_append_string, "s", (context).syslog_identifier }, \ + /* CAPABILITIES */ \ + { interface, "SecureBits", bus_property_append_int, "i", &(context).secure_bits }, \ + { interface, "CapabilityBoundingSetDrop", bus_property_append_uint64, "t", &(context).capability_bounding_set_drop }, \ + { interface, "User", bus_property_append_string, "s", (context).user }, \ + { interface, "Group", bus_property_append_string, "s", (context).group }, \ + { interface, "SupplementaryGroups", bus_property_append_strv, "as", (context).supplementary_groups } + +int bus_execute_append_output(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_execute_append_input(Manager *m, DBusMessageIter *i, const char *property, void *data); + +#endif diff --git a/dbus-job.c b/dbus-job.c index b0f575b11b..bec5bca93c 100644 --- a/dbus-job.c +++ b/dbus-job.c @@ -23,6 +23,7 @@ #include "dbus.h" #include "log.h" +#include "dbus-job.h" static const char introspection[] = DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE @@ -39,8 +40,8 @@ static const char introspection[] = BUS_INTROSPECTABLE_INTERFACE "</node>"; -DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_state, job_state, JobState); -DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_type, job_type, JobType); +static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_state, job_state, JobState); +static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_type, job_type, JobType); static int bus_job_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) { Job *j = data; diff --git a/dbus-job.h b/dbus-job.h new file mode 100644 index 0000000000..cf9176052d --- /dev/null +++ b/dbus-job.h @@ -0,0 +1,32 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusjobhfoo +#define foodbusjobhfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +void bus_job_send_change_signal(Job *j); +void bus_job_send_removed_signal(Job *j); + +extern const DBusObjectPathVTable bus_job_vtable; + +#endif diff --git a/dbus-manager.c b/dbus-manager.c index 8deb451795..734ed7b886 100644 --- a/dbus-manager.c +++ b/dbus-manager.c @@ -23,11 +23,12 @@ #include "dbus.h" #include "log.h" +#include "dbus-manager.h" #define INTROSPECTION_BEGIN \ DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \ "<node>" \ - " <interface name=\"org.freedesktop.systemd1\">" \ + " <interface name=\"org.freedesktop.systemd1.Manager\">" \ " <method name=\"GetUnit\">" \ " <arg name=\"name\" type=\"s\" direction=\"in\"/>" \ " <arg name=\"unit\" type=\"o\" direction=\"out\"/>" \ @@ -50,6 +51,11 @@ " <method name=\"Subscribe\"/>" \ " <method name=\"Unsubscribe\"/>" \ " <method name=\"Dump\"/>" \ + " <method name=\"CreateSnapshot\">" \ + " <arg name=\"name\" type=\"s\" direction=\"in\"/>" \ + " <arg nane=\"cleanup\" type=\"b\" direction=\"in\"/>" \ + " <arg name=\"unit\" type=\"o\" direction=\"out\"/>" \ + " </method>" \ " <signal name=\"UnitNew\">" \ " <arg name=\"id\" type=\"s\"/>" \ " <arg name=\"unit\" type=\"o\"/>" \ @@ -78,7 +84,7 @@ #define INTROSPECTION_END \ "</node>" -DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs); +static 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; @@ -114,11 +120,11 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection 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 }, + { "org.freedesktop.systemd1.Manager", "Version", bus_property_append_string, "s", PACKAGE_STRING }, + { "org.freedesktop.systemd1.Manager", "RunningAs", bus_manager_append_running_as, "s", &m->running_as }, + { "org.freedesktop.systemd1.Manager", "BootTimestamp", bus_property_append_uint64, "t", &m->boot_timestamp }, + { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", NULL }, + { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", NULL }, { NULL, NULL, NULL, NULL, NULL } }; @@ -138,7 +144,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection dbus_message_get_member(message), dbus_message_get_path(message)); - if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "GetUnit")) { + if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnit")) { const char *name; Unit *u; @@ -164,7 +170,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection DBUS_TYPE_INVALID)) goto oom; - } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "LoadUnit")) { + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LoadUnit")) { const char *name; Unit *u; @@ -216,14 +222,14 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection 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.Manager", "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.Manager", "ListUnits")) { DBusMessageIter iter, sub; Iterator i; Unit *u; @@ -298,7 +304,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection 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.Manager", "ListJobs")) { DBusMessageIter iter, sub; Iterator i; Job *j; @@ -353,7 +359,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection if (!dbus_message_iter_close_container(&iter, &sub)) goto oom; - } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Subscribe")) { + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Subscribe")) { char *client; if (!(client = strdup(dbus_message_get_sender(message)))) @@ -367,7 +373,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection if (!(reply = dbus_message_new_method_return(message))) goto oom; - } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Unsubscribe")) { + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) { char *client; if (!(client = set_remove(m->subscribed, (char*) dbus_message_get_sender(message)))) @@ -378,7 +384,7 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection if (!(reply = dbus_message_new_method_return(message))) goto oom; - } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1", "Dump")) { + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Dump")) { FILE *f; char *dump = NULL; size_t size; @@ -406,6 +412,36 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection } free(dump); + } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) { + const char *name; + dbus_bool_t cleanup; + Snapshot *s; + + if (!dbus_message_get_args( + message, + &error, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_BOOLEAN, &cleanup, + DBUS_TYPE_INVALID)) + return bus_send_error_reply(m, message, &error, -EINVAL); + + if (name && name[0] == 0) + name = NULL; + + if ((r = snapshot_create(m, name, cleanup, &s)) < 0) + return bus_send_error_reply(m, message, NULL, r); + + if (!(reply = dbus_message_new_method_return(message))) + goto oom; + + if (!(path = unit_dbus_path(UNIT(s)))) + goto oom; + + if (!dbus_message_append_args( + reply, + DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_INVALID)) + goto oom; } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) { char *introspection = NULL; diff --git a/dbus-manager.h b/dbus-manager.h new file mode 100644 index 0000000000..0acd2d086d --- /dev/null +++ b/dbus-manager.h @@ -0,0 +1,29 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusmanagerhfoo +#define foodbusmanagerhfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +extern const DBusObjectPathVTable bus_manager_vtable; + +#endif diff --git a/dbus-mount.c b/dbus-mount.c new file mode 100644 index 0000000000..cbdb300f2c --- /dev/null +++ b/dbus-mount.c @@ -0,0 +1,55 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include "dbus-unit.h" +#include "dbus-mount.h" +#include "dbus-execute.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "<node>" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " <interface name=\"org.freedesktop.systemd1.Mount\">" + " <property name=\"Where\" type=\"s\" access=\"read\"/>" + " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>" + BUS_EXEC_CONTEXT_INTERFACE + " <property name=\"KillMode\" type=\"s\" access=\"read\"/>" + " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>" + " </interface>" + BUS_INTROSPECTABLE_INTERFACE + "</node>"; + +DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message) { + const BusProperty properties[] = { + BUS_UNIT_PROPERTIES, + { "org.freedesktop.systemd1.Mount", "Where", bus_property_append_string, "s", u->mount.where }, + /* Where, Options, fstype */ + { "org.freedesktop.systemd1.Mount", "TimeoutUSec", bus_property_append_usec, "t", &u->mount.timeout_usec }, + /* ExecCommand */ + BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Mount", u->mount.exec_context), + { "org.freedesktop.systemd1.Mount", "KillMode", bus_unit_append_kill_mode, "s", &u->mount.kill_mode }, + { "org.freedesktop.systemd1.Mount", "ControlPID", bus_property_append_pid, "u", &u->mount.control_pid }, + { NULL, NULL, NULL, NULL, NULL } + }; + + return bus_default_message_handler(u->meta.manager, message, introspection, properties); +} diff --git a/dbus-mount.h b/dbus-mount.h new file mode 100644 index 0000000000..b92867df28 --- /dev/null +++ b/dbus-mount.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusmounthfoo +#define foodbusmounthfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "unit.h" + +DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-service.c b/dbus-service.c new file mode 100644 index 0000000000..24dd6c14f6 --- /dev/null +++ b/dbus-service.c @@ -0,0 +1,78 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include <errno.h> + +#include "dbus-unit.h" +#include "dbus-execute.h" +#include "dbus-service.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "<node>" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " <interface name=\"org.freedesktop.systemd1.Service\">" + " <property name=\"Type\" type=\"s\" access=\"read\"/>" + " <property name=\"Restart\" type=\"s\" access=\"read\"/>" + " <property name=\"PIDFile\" type=\"s\" access=\"read\"/>" + " <property name=\"RestartUSec\" type=\"t\" access=\"read\"/>" + " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>" + BUS_EXEC_CONTEXT_INTERFACE + " <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>" + " <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>" + " <property name=\"ValidNoProcess\" type=\"b\" access=\"read\"/>" + " <property name=\"KillMode\" type=\"s\" access=\"read\"/>" + " <property name=\"MainPID\" type=\"u\" access=\"read\"/>" + " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>" + " <property name=\"SysVPath\" type=\"s\" access=\"read\"/>" + " <property name=\"BusName\" type=\"s\" access=\"read\"/>" + " </interface>" + BUS_INTROSPECTABLE_INTERFACE + "</node>"; + +static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType); +static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart); + +DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message) { + const BusProperty properties[] = { + BUS_UNIT_PROPERTIES, + { "org.freedesktop.systemd1.Service", "Type", bus_service_append_type, "s", &u->service.type }, + { "org.freedesktop.systemd1.Service", "Restart", bus_service_append_restart, "s", &u->service.restart }, + { "org.freedesktop.systemd1.Service", "PIDFile", bus_property_append_string, "s", u->service.pid_file }, + { "org.freedesktop.systemd1.Service", "RestartUSec", bus_property_append_usec, "t", &u->service.restart_usec }, + { "org.freedesktop.systemd1.Service", "TimeoutUSec", bus_property_append_usec, "t", &u->service.timeout_usec }, + /* ExecCommand */ + BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Service", u->service.exec_context), + { "org.freedesktop.systemd1.Service", "PermissionsStartOnly", bus_property_append_bool, "b", &u->service.permissions_start_only }, + { "org.freedesktop.systemd1.Service", "RootDirectoryStartOnly", bus_property_append_bool, "b", &u->service.root_directory_start_only }, + { "org.freedesktop.systemd1.Service", "ValidNoProcess", bus_property_append_bool, "b", &u->service.valid_no_process }, + { "org.freedesktop.systemd1.Service", "KillMode", bus_unit_append_kill_mode, "s", &u->service.kill_mode }, + /* MainExecStatus */ + { "org.freedesktop.systemd1.Service", "MainPID", bus_property_append_pid, "u", &u->service.main_pid }, + { "org.freedesktop.systemd1.Service", "ControlPID", bus_property_append_pid, "u", &u->service.control_pid }, + { "org.freedesktop.systemd1.Service", "SysVPath", bus_property_append_string, "s", u->service.sysv_path }, + { "org.freedesktop.systemd1.Service", "BusName", bus_property_append_string, "s", u->service.bus_name }, + { NULL, NULL, NULL, NULL, NULL } + }; + + return bus_default_message_handler(u->meta.manager, message, introspection, properties); +} diff --git a/dbus-service.h b/dbus-service.h new file mode 100644 index 0000000000..f0a468e90d --- /dev/null +++ b/dbus-service.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusservicehfoo +#define foodbusservicehfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "unit.h" + +DBusHandlerResult bus_service_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-snapshot.c b/dbus-snapshot.c new file mode 100644 index 0000000000..8aeca15254 --- /dev/null +++ b/dbus-snapshot.c @@ -0,0 +1,75 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include "dbus-unit.h" +#include "dbus-snapshot.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "<node>" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " <interface name=\"org.freedesktop.systemd1.Snapshot\">" + " <method name=\"Remove\"/>" + " <property name=\"Cleanup\" type=\"b\" access=\"read\"/>" + " </interface>" + BUS_INTROSPECTABLE_INTERFACE + "</node>"; + +DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message) { + const BusProperty properties[] = { + BUS_UNIT_PROPERTIES, + { "org.freedesktop.systemd1.Snapshot", "Cleanup", bus_property_append_bool, "b", &u->snapshot.cleanup }, + { NULL, NULL, NULL, NULL, NULL } + }; + + DBusMessage *reply = NULL; + DBusError error; + + dbus_error_init(&error); + + if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Snapshot", "Remove")) { + + snapshot_remove(SNAPSHOT(u)); + + if (!(reply = dbus_message_new_method_return(message))) + goto oom; + + } else + return bus_default_message_handler(u->meta.manager, message, introspection, properties); + + if (reply) { + if (!dbus_connection_send(u->meta.manager->api_bus, reply, NULL)) + goto oom; + + dbus_message_unref(reply); + } + + return DBUS_HANDLER_RESULT_HANDLED; + +oom: + if (reply) + dbus_message_unref(reply); + + dbus_error_free(&error); + + return DBUS_HANDLER_RESULT_NEED_MEMORY; +} diff --git a/dbus-snapshot.h b/dbus-snapshot.h new file mode 100644 index 0000000000..5f28550c95 --- /dev/null +++ b/dbus-snapshot.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbussnapshothfoo +#define foodbussnapshothfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "unit.h" + +DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-socket.c b/dbus-socket.c new file mode 100644 index 0000000000..2a2349c00d --- /dev/null +++ b/dbus-socket.c @@ -0,0 +1,64 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include "dbus-unit.h" +#include "dbus-socket.h" +#include "dbus-execute.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "<node>" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " <interface name=\"org.freedesktop.systemd1.Socket\">" + " <property name=\"BindIPv6Only\" type=\"b\" access=\"read\"/>" + " <property name=\"Backlog\" type=\"u\" access=\"read\"/>" + " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>" + BUS_EXEC_CONTEXT_INTERFACE + " <property name=\"KillMode\" type=\"s\" access=\"read\"/>" + " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>" + " <property name=\"BindToDevice\" type=\"s\" access=\"read\"/>" + " <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>" + " <property name=\"SocketMode\" type=\"u\" access=\"read\"/>" + " <property name=\"Accept\" type=\"b\" access=\"read\"/>" + " </interface>" + BUS_INTROSPECTABLE_INTERFACE + "</node>"; + +DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message) { + const BusProperty properties[] = { + BUS_UNIT_PROPERTIES, + { "org.freedesktop.systemd1.Socket", "BindIPv6Only", bus_property_append_bool, "b", &u->socket.bind_ipv6_only }, + { "org.freedesktop.systemd1.Socket", "Backlog", bus_property_append_unsigned, "u", &u->socket.backlog }, + { "org.freedesktop.systemd1.Socket", "TimeoutUSec", bus_property_append_usec, "t", &u->socket.timeout_usec }, + /* ExecCommand */ + BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Socket", u->socket.exec_context), + { "org.freedesktop.systemd1.Socket", "KillMode", bus_unit_append_kill_mode, "s", &u->socket.kill_mode }, + { "org.freedesktop.systemd1.Socket", "ControlPID", bus_property_append_pid, "u", &u->socket.control_pid }, + { "org.freedesktop.systemd1.Socket", "BindToDevice", bus_property_append_string, "s", u->socket.bind_to_device }, + { "org.freedesktop.systemd1.Socket", "DirectoryMode", bus_property_append_mode, "u", &u->socket.directory_mode }, + { "org.freedesktop.systemd1.Socket", "SocketMode", bus_property_append_mode, "u", &u->socket.socket_mode }, + { "org.freedesktop.systemd1.Socket", "Accept", bus_property_append_bool, "b", &u->socket.accept }, + { NULL, NULL, NULL, NULL, NULL } + }; + + return bus_default_message_handler(u->meta.manager, message, introspection, properties); +} diff --git a/dbus-socket.h b/dbus-socket.h new file mode 100644 index 0000000000..6a8f534bf5 --- /dev/null +++ b/dbus-socket.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbussockethfoo +#define foodbussockethfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "unit.h" + +DBusHandlerResult bus_socket_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-target.c b/dbus-target.c new file mode 100644 index 0000000000..be984b9bb4 --- /dev/null +++ b/dbus-target.c @@ -0,0 +1,42 @@ +/*-*- 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 <http://www.gnu.org/licenses/>. +***/ + +#include "dbus-unit.h" +#include "dbus-target.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "<node>" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " <interface name=\"org.freedesktop.systemd1.Target\">" + " </interface>" + BUS_INTROSPECTABLE_INTERFACE + "</node>"; + +DBusHandlerResult bus_target_message_handler(Unit *u, DBusMessage *message) { + const BusProperty properties[] = { + BUS_UNIT_PROPERTIES, + { NULL, NULL, NULL, NULL, NULL } + }; + + return bus_default_message_handler(u->meta.manager, message, introspection, properties); +} diff --git a/dbus-target.h b/dbus-target.h new file mode 100644 index 0000000000..f6a1ac5e65 --- /dev/null +++ b/dbus-target.h @@ -0,0 +1,31 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbustargethfoo +#define foodbustargethfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "unit.h" + +DBusHandlerResult bus_target_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-unit.c b/dbus-unit.c index 6bccec14a7..cbc2812e31 100644 --- a/dbus-unit.c +++ b/dbus-unit.c @@ -23,45 +23,28 @@ #include "dbus.h" #include "log.h" +#include "dbus-unit.h" -static const char introspection[] = - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE - "<node>" - " <interface name=\"org.freedesktop.systemd1.Unit\">" - " <method name=\"Start\">" - " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" - " <arg name=\"job\" type=\"o\" direction=\"out\"/>" - " </method>" - " <method name=\"Stop\">" - " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" - " <arg name=\"job\" type=\"o\" direction=\"out\"/>" - " </method>" - " <method name=\"Restart\">" - " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" - " <arg name=\"job\" type=\"o\" direction=\"out\"/>" - " </method>" - " <method name=\"Reload\">" - " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" - " <arg name=\"job\" type=\"o\" direction=\"out\"/>" - " </method>" - " <signal name=\"Changed\"/>" - " <property name=\"Id\" type=\"s\" access=\"read\"/>" - " <property name=\"Description\" type=\"s\" access=\"read\"/>" - " <property name=\"LoadState\" type=\"s\" access=\"read\"/>" - " <property name=\"ActiveState\" type=\"s\" access=\"read\"/>" - " <property name=\"SubState\" type=\"s\" access=\"read\"/>" - " <property name=\"FragmentPath\" type=\"s\" access=\"read\"/>" - " <property name=\"ActiveEnterTimestamp\" type=\"t\" access=\"read\"/>" - " <property name=\"ActiveExitTimestamp\" type=\"t\" access=\"read\"/>" - " <property name=\"CanReload\" type=\"b\" access=\"read\"/>" - " <property name=\"CanStart\" type=\"b\" access=\"read\"/>" - " <property name=\"Job\" type=\"(uo)\" access=\"read\"/>" - " </interface>" - BUS_PROPERTIES_INTERFACE - BUS_INTROSPECTABLE_INTERFACE - "</node>"; - -static int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *property, void *data) { +int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data) { + char *t; + Iterator j; + DBusMessageIter sub; + Unit *u = data; + + if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub)) + return -ENOMEM; + + SET_FOREACH(t, u->meta.names, j) + if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &t)) + return -ENOMEM; + + if (!dbus_message_iter_close_container(i, &sub)) + return -ENOMEM; + + return 0; +} + +int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *property, void *data) { Unit *u = data; const char *d; @@ -80,7 +63,7 @@ static int bus_unit_append_description(Manager *m, DBusMessageIter *i, const cha DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_load_state, unit_load_state, UnitLoadState); -static int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data) { +int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data) { Unit *u = data; const char *state; @@ -97,7 +80,7 @@ static int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const ch return 0; } -static int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data) { +int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data) { Unit *u = data; const char *state; @@ -114,7 +97,7 @@ static int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char return 0; } -static int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) { +int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data) { Unit *u = data; dbus_bool_t b; @@ -123,7 +106,7 @@ static int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char assert(property); assert(u); - b = unit_can_reload(u); + b = unit_can_start(u); if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b)) return -ENOMEM; @@ -131,7 +114,7 @@ static int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char return 0; } -static int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data) { +int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) { Unit *u = data; dbus_bool_t b; @@ -140,7 +123,7 @@ static int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char assert(property); assert(u); - b = unit_can_start(u); + b = unit_can_reload(u); if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b)) return -ENOMEM; @@ -148,7 +131,7 @@ static int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char return 0; } -static int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data) { +int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data) { Unit *u = data; DBusMessageIter sub; char *p; @@ -196,23 +179,62 @@ static int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *prope return 0; } -static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message) { +int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data) { + Unit *u = data; + char *t; + CGroupBonding *cgb; + bool success; - const BusProperty properties[] = { - { "org.freedesktop.systemd1.Unit", "Id", bus_property_append_string, "s", u->meta.id }, - { "org.freedesktop.systemd1.Unit", "Description", bus_unit_append_description, "s", u }, - { "org.freedesktop.systemd1.Unit", "LoadState", bus_unit_append_load_state, "s", &u->meta.load_state }, - { "org.freedesktop.systemd1.Unit", "ActiveState", bus_unit_append_active_state, "s", u }, - { "org.freedesktop.systemd1.Unit", "SubState", bus_unit_append_sub_state, "s", u }, - { "org.freedesktop.systemd1.Unit", "FragmentPath", bus_property_append_string, "s", u->meta.fragment_path }, - { "org.freedesktop.systemd1.Unit", "ActiveEnterTimestamp", bus_property_append_uint64, "t", &u->meta.active_enter_timestamp }, - { "org.freedesktop.systemd1.Unit", "ActiveExitTimestamp", bus_property_append_uint64, "t", &u->meta.active_exit_timestamp }, - { "org.freedesktop.systemd1.Unit", "CanReload", bus_unit_append_can_reload, "b", u }, - { "org.freedesktop.systemd1.Unit", "CanStart", bus_unit_append_can_start, "b", u }, - { "org.freedesktop.systemd1.Unit", "Job", bus_unit_append_job, "(uo)", u }, - { NULL, NULL, NULL, NULL, NULL } - }; + assert(m); + assert(i); + assert(property); + assert(u); + + if ((cgb = unit_get_default_cgroup(u))) { + if (!(t = cgroup_bonding_to_string(cgb))) + return -ENOMEM; + } else + t = (char*) ""; + success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t); + + if (cgb) + free(t); + + return success ? 0 : -ENOMEM; +} + +int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property, void *data) { + Unit *u = data; + CGroupBonding *cgb; + DBusMessageIter sub; + + if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub)) + return -ENOMEM; + + LIST_FOREACH(by_unit, cgb, u->meta.cgroup_bondings) { + char *t; + bool success; + + if (!(t = cgroup_bonding_to_string(cgb))) + return -ENOMEM; + + success = dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &t); + free(t); + + if (!success) + return -ENOMEM; + } + + if (!dbus_message_iter_close_container(i, &sub)) + return -ENOMEM; + + return 0; +} + +DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_kill_mode, kill_mode, KillMode); + +static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message) { DBusMessage *reply = NULL; Manager *m = u->meta.manager; DBusError error; @@ -228,8 +250,10 @@ static DBusHandlerResult bus_unit_message_dispatch(Unit *u, DBusMessage *message job_type = JOB_RELOAD; else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Unit", "Restart")) job_type = JOB_RESTART; + else if (UNIT_VTABLE(u)->bus_message_handler) + return UNIT_VTABLE(u)->bus_message_handler(u, message); else - return bus_default_message_handler(u->meta.manager, message, introspection, properties); + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; if (job_type != _JOB_TYPE_INVALID) { const char *smode; diff --git a/dbus-unit.h b/dbus-unit.h new file mode 100644 index 0000000000..471f64cbe8 --- /dev/null +++ b/dbus-unit.h @@ -0,0 +1,101 @@ +/*-*- Mode: C; c-basic-offset: 8 -*-*/ + +#ifndef foodbusunithfoo +#define foodbusunithfoo + +/*** + 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 <http://www.gnu.org/licenses/>. +***/ + +#include <dbus/dbus.h> + +#include "manager.h" + +#define BUS_UNIT_INTERFACE \ + " <interface name=\"org.freedesktop.systemd1.Unit\">" \ + " <method name=\"Start\">" \ + " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" \ + " <arg name=\"job\" type=\"o\" direction=\"out\"/>" \ + " </method>" \ + " <method name=\"Stop\">" \ + " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" \ + " <arg name=\"job\" type=\"o\" direction=\"out\"/>" \ + " </method>" \ + " <method name=\"Restart\">" \ + " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" \ + " <arg name=\"job\" type=\"o\" direction=\"out\"/>" \ + " </method>" \ + " <method name=\"Reload\">" \ + " <arg name=\"mode\" type=\"s\" direction=\"in\"/>" \ + " <arg name=\"job\" type=\"o\" direction=\"out\"/>" \ + " </method>" \ + " <signal name=\"Changed\"/>" \ + " <property name=\"Id\" type=\"s\" access=\"read\"/>" \ + " <property name=\"Names\" type=\"as\" access=\"read\"/>" \ + " <property name=\"Description\" type=\"s\" access=\"read\"/>" \ + " <property name=\"LoadState\" type=\"s\" access=\"read\"/>" \ + " <property name=\"ActiveState\" type=\"s\" access=\"read\"/>" \ + " <property name=\"SubState\" type=\"s\" access=\"read\"/>" \ + " <property name=\"FragmentPath\" type=\"s\" access=\"read\"/>" \ + " <property name=\"ActiveEnterTimestamp\" type=\"t\" access=\"read\"/>" \ + " <property name=\"ActiveExitTimestamp\" type=\"t\" access=\"read\"/>" \ + " <property name=\"CanReload\" type=\"b\" access=\"read\"/>" \ + " <property name=\"CanStart\" type=\"b\" access=\"read\"/>" \ + " <property name=\"Job\" type=\"(uo)\" access=\"read\"/>" \ + " <property name=\"RecursiveStop\" type=\"b\" access=\"read\"/>" \ + " <property name=\"StopWhenUneeded\" type=\"b\" access=\"read\"/>" \ + " <property name=\"DefaultControlGroup\" type=\"s\" access=\"read\"/>" \ + " <property name=\"ControlGroups\" type=\"as\" access=\"read\"/>" \ + " </interface>" + +#define BUS_UNIT_PROPERTIES \ + { "org.freedesktop.systemd1.Unit", "Id", bus_property_append_string, "s", u->meta.id }, \ + { "org.freedesktop.systemd1.Unit", "Names", bus_unit_append_names, "as", u }, \ + { "org.freedesktop.systemd1.Unit", "Description", bus_unit_append_description, "s", u }, \ + { "org.freedesktop.systemd1.Unit", "LoadState", bus_unit_append_load_state, "s", &u->meta.load_state }, \ + { "org.freedesktop.systemd1.Unit", "ActiveState", bus_unit_append_active_state, "s", u }, \ + { "org.freedesktop.systemd1.Unit", "SubState", bus_unit_append_sub_state, "s", u }, \ + { "org.freedesktop.systemd1.Unit", "FragmentPath", bus_property_append_string, "s", u->meta.fragment_path }, \ + { "org.freedesktop.systemd1.Unit", "ActiveEnterTimestamp", bus_property_append_uint64, "t", &u->meta.active_enter_timestamp }, \ + { "org.freedesktop.systemd1.Unit", "ActiveExitTimestamp", bus_property_append_uint64, "t", &u->meta.active_exit_timestamp }, \ + { "org.freedesktop.systemd1.Unit", "CanStart", bus_unit_append_can_start, "b", u }, \ + { "org.freedesktop.systemd1.Unit", "CanReload", bus_unit_append_can_reload, "b", u }, \ + { "org.freedesktop.systemd1.Unit", "Job", bus_unit_append_job, "(uo)", u }, \ + { "org.freedesktop.systemd1.Unit", "RecursiveStop", bus_property_append_bool, "b", &u->meta.recursive_stop }, \ + { "org.freedesktop.systemd1.Unit", "StopWhenUneeded", bus_property_append_bool, "b", &u->meta.stop_when_unneeded }, \ + { "org.freedesktop.systemd1.Unit", "DefaultControlGroup", bus_unit_append_default_cgroup, "s", u }, \ + { "org.freedesktop.systemd1.Unit", "ControlGroups", bus_unit_append_cgroups, "as", u } + +int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_load_state(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_unit_append_kill_mode(Manager *m, DBusMessageIter *i, const char *property, void *data); + +void bus_unit_send_change_signal(Unit *u); +void bus_unit_send_removed_signal(Unit *u); + +extern const DBusObjectPathVTable bus_unit_vtable; + +#endif @@ -19,17 +19,19 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <dbus/dbus.h> - #include <sys/epoll.h> #include <sys/timerfd.h> #include <errno.h> #include <unistd.h> +#include <dbus/dbus.h> #include "dbus.h" #include "log.h" #include "strv.h" #include "cgroup.h" +#include "dbus-unit.h" +#include "dbus-job.h" +#include "dbus-manager.h" static void api_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) { Manager *m = data; @@ -1023,6 +1025,10 @@ int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *prope assert(property); assert(data); + /* Let's ensure that pid_t is actually 64bit, and hence this + * function can be used for usec_t */ + assert_cc(sizeof(uint64_t) == sizeof(usec_t)); + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, data)) return -ENOMEM; @@ -1035,8 +1041,28 @@ int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *prope assert(property); assert(data); + /* Let's ensure that pid_t and mode_t is actually 32bit, and + * hence this function can be used for pid_t/mode_t */ + assert_cc(sizeof(uint32_t) == sizeof(pid_t)); + assert_cc(sizeof(uint32_t) == sizeof(mode_t)); + assert_cc(sizeof(uint32_t) == sizeof(unsigned)); + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, data)) return -ENOMEM; return 0; } + +int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data) { + assert(m); + assert(i); + assert(property); + assert(data); + + assert_cc(sizeof(int32_t) == sizeof(int)); + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, data)) + return -ENOMEM; + + return 0; +} @@ -66,30 +66,27 @@ unsigned bus_dispatch(Manager *m); void bus_watch_event(Manager *m, Watch *w, int events); void bus_timeout_event(Manager *m, Watch *w, int events); +int bus_query_pid(Manager *m, const char *name); + DBusHandlerResult bus_default_message_handler(Manager *m, DBusMessage *message, const char* introspection, const BusProperty *properties); DBusHandlerResult bus_send_error_reply(Manager *m, DBusMessage *message, DBusError *bus_error, int error); -int bus_query_pid(Manager *m, const char *name); - int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data); +int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data); int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data); -extern const DBusObjectPathVTable bus_manager_vtable; -extern const DBusObjectPathVTable bus_job_vtable; -extern const DBusObjectPathVTable bus_unit_vtable; - -void bus_unit_send_change_signal(Unit *u); -void bus_unit_send_removed_signal(Unit *u); - -void bus_job_send_change_signal(Job *j); -void bus_job_send_removed_signal(Job *j); +#define bus_property_append_int bus_property_append_int32 +#define bus_property_append_pid bus_property_append_uint32 +#define bus_property_append_mode bus_property_append_uint32 +#define bus_property_append_unsigned bus_property_append_uint32 +#define bus_property_append_usec bus_property_append_uint64 -#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \ - static int function(Manager *m, DBusMessageIter *i, const char *property, void *data) { \ +#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \ + int function(Manager *m, DBusMessageIter *i, const char *property, void *data) { \ const char *value; \ type *field = data; \ \ @@ -28,6 +28,7 @@ #include "strv.h" #include "log.h" #include "unit-name.h" +#include "dbus-device.h" static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = { [DEVICE_DEAD] = UNIT_INACTIVE, @@ -463,6 +464,8 @@ const UnitVTable device_vtable = { .active_state = device_active_state, .sub_state_to_string = device_sub_state_to_string, + .bus_message_handler = bus_device_message_handler, + .enumerate = device_enumerate, .shutdown = device_shutdown }; @@ -29,6 +29,7 @@ #include "load-fragment.h" #include "load-dropin.h" #include "log.h" +#include "dbus-job.h" Job* job_new(Manager *m, JobType type, Unit *unit) { Job *j; @@ -47,6 +47,8 @@ #include "mount-setup.h" #include "utmp-wtmp.h" #include "unit-name.h" +#include "dbus-unit.h" +#include "dbus-job.h" static int enable_special_signals(Manager *m) { char fd; @@ -33,6 +33,8 @@ #include "strv.h" #include "mount-setup.h" #include "unit-name.h" +#include "mount.h" +#include "dbus-mount.h" static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = { [MOUNT_DEAD] = UNIT_INACTIVE, @@ -1357,6 +1359,8 @@ const UnitVTable mount_vtable = { .sigchld_event = mount_sigchld_event, .timer_event = mount_timer_event, + .bus_message_handler = bus_mount_message_handler, + .enumerate = mount_enumerate, .shutdown = mount_shutdown }; @@ -31,6 +31,7 @@ #include "log.h" #include "strv.h" #include "unit-name.h" +#include "dbus-service.h" #define COMMENTS "#;\n" #define NEWLINES "\n\r" @@ -2239,5 +2240,7 @@ const UnitVTable service_vtable = { .bus_name_owner_change = service_bus_name_owner_change, .bus_query_pid_done = service_bus_query_pid_done, + .bus_message_handler = bus_service_message_handler, + .enumerate = service_enumerate }; @@ -35,6 +35,7 @@ #include "load-fragment.h" #include "strv.h" #include "unit-name.h" +#include "dbus-socket.h" static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = { [SOCKET_DEAD] = UNIT_INACTIVE, @@ -1098,5 +1099,7 @@ const UnitVTable socket_vtable = { .fd_event = socket_fd_event, .sigchld_event = socket_sigchld_event, - .timer_event = socket_timer_event + .timer_event = socket_timer_event, + + .bus_message_handler = bus_socket_message_handler }; diff --git a/systemd-interfaces.vala b/systemd-interfaces.vala index dae0648c64..3b65d3c90b 100644 --- a/systemd-interfaces.vala +++ b/systemd-interfaces.vala @@ -19,7 +19,7 @@ using DBus; -[DBus (name = "org.freedesktop.systemd1")] +[DBus (name = "org.freedesktop.systemd1.Manager")] public interface Manager : DBus.Object { public struct UnitInfo { @@ -76,12 +76,16 @@ public interface Unit : DBus.Object { public abstract string description { owned get; } public abstract string load_state { owned get; } public abstract string active_state { owned get; } + public abstract string sub_state { owned get; } public abstract string fragment_path { owned get; } public abstract uint64 active_enter_timestamp { owned get; } public abstract uint64 active_exit_timestamp { owned get; } - public abstract bool can_reload { owned get; } public abstract bool can_start { owned get; } + public abstract bool can_reload { owned get; } public abstract JobLink job { owned get; /* FIXME: this setter is a temporary fix to make valac not segfault */ set; } + public abstract bool recursive_stop { owned get; } + public abstract bool stop_when_unneeded { owned get; } + public abstract string default_control_group { owned get; } public abstract ObjectPath start(string mode) throws DBus.Error; public abstract ObjectPath stop(string mode) throws DBus.Error; @@ -26,6 +26,7 @@ #include "target.h" #include "load-fragment.h" #include "log.h" +#include "dbus-target.h" static const UnitActiveState state_translation_table[_TARGET_STATE_MAX] = { [TARGET_DEAD] = UNIT_INACTIVE, @@ -133,5 +134,7 @@ const UnitVTable target_vtable = { .stop = target_stop, .active_state = target_active_state, - .sub_state_to_string = target_sub_state_to_string + .sub_state_to_string = target_sub_state_to_string, + + .bus_message_handler = bus_target_message_handler }; @@ -37,6 +37,7 @@ #include "log.h" #include "unit-name.h" #include "specifier.h" +#include "dbus-unit.h" const UnitVTable * const unit_vtable[_UNIT_TYPE_MAX] = { [UNIT_SERVICE] = &service_vtable, @@ -264,6 +264,9 @@ struct UnitVTable { /* Called whenever a bus PID lookup finishes */ void (*bus_query_pid_done)(Unit *u, const char *name, pid_t pid); + /* Called for each message received on the bus */ + DBusHandlerResult (*bus_message_handler)(Unit *u, DBusMessage *message); + /* This is called for each unit type and should be used to * enumerate existing devices and load them. However, * everything that is loaded here should still stay in |