From 4139c1b2729f88991159b9affa2ebf3e4eb904a0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 18 Apr 2010 03:08:16 +0200 Subject: [PATCH] dbus: greatly extend dbus coverage --- Makefile.am | 16 +++++ automount.c | 3 + dbus-automount.c | 44 ++++++++++++ dbus-automount.h | 31 +++++++++ dbus-device.c | 44 ++++++++++++ dbus-device.h | 31 +++++++++ dbus-execute.c | 28 ++++++++ dbus-execute.h | 79 ++++++++++++++++++++++ dbus-job.c | 5 +- dbus-job.h | 32 +++++++++ dbus-manager.c | 66 +++++++++++++----- dbus-manager.h | 29 ++++++++ dbus-mount.c | 55 +++++++++++++++ dbus-mount.h | 31 +++++++++ dbus-service.c | 78 +++++++++++++++++++++ dbus-service.h | 31 +++++++++ dbus-snapshot.c | 75 +++++++++++++++++++++ dbus-snapshot.h | 31 +++++++++ dbus-socket.c | 64 ++++++++++++++++++ dbus-socket.h | 31 +++++++++ dbus-target.c | 42 ++++++++++++ dbus-target.h | 31 +++++++++ dbus-unit.c | 146 +++++++++++++++++++++++----------------- dbus-unit.h | 101 +++++++++++++++++++++++++++ dbus.c | 30 ++++++++- dbus.h | 23 +++---- device.c | 3 + job.c | 1 + manager.c | 2 + mount.c | 4 ++ service.c | 3 + socket.c | 5 +- systemd-interfaces.vala | 8 ++- target.c | 5 +- unit.c | 1 + unit.h | 3 + 36 files changed, 1115 insertions(+), 97 deletions(-) create mode 100644 dbus-automount.c create mode 100644 dbus-automount.h create mode 100644 dbus-device.c create mode 100644 dbus-device.h create mode 100644 dbus-execute.c create mode 100644 dbus-execute.h create mode 100644 dbus-job.h create mode 100644 dbus-manager.h create mode 100644 dbus-mount.c create mode 100644 dbus-mount.h create mode 100644 dbus-service.c create mode 100644 dbus-service.h create mode 100644 dbus-snapshot.c create mode 100644 dbus-snapshot.h create mode 100644 dbus-socket.c create mode 100644 dbus-socket.h create mode 100644 dbus-target.c create mode 100644 dbus-target.h create mode 100644 dbus-unit.h diff --git a/Makefile.am b/Makefile.am index 8cad1420e0f..8720e7898fa 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 5d79131afcb..fa5fd52552a 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 00000000000..9003b74b8ac --- /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 . +***/ + +#include "dbus-unit.h" +#include "dbus-automount.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " " + " " + " " + BUS_INTROSPECTABLE_INTERFACE + ""; + +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 00000000000..947bf0f59fd --- /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 . +***/ + +#include + +#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 00000000000..83764783adc --- /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 . +***/ + +#include "dbus-unit.h" +#include "dbus-device.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " " + " " + " " + BUS_INTROSPECTABLE_INTERFACE + ""; + +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 00000000000..f2850a63f83 --- /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 . +***/ + +#include + +#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 00000000000..8840396bc14 --- /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 . +***/ + +#include +#include + +#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 00000000000..25ecd982a43 --- /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 . +***/ + +#include + +#include "manager.h" + +#define BUS_EXEC_CONTEXT_INTERFACE \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " + +#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 b0f575b11be..bec5bca93ca 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 ""; -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 00000000000..cf9176052db --- /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 . +***/ + +#include + +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 8deb451795c..734ed7b886a 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 \ "" \ - " " \ + " " \ " " \ " " \ " " \ @@ -50,6 +51,11 @@ " " \ " " \ " " \ + " " \ + " " \ + " " \ + " " \ + " " \ " " \ " " \ " " \ @@ -78,7 +84,7 @@ #define INTROSPECTION_END \ "" -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 00000000000..0acd2d086d0 --- /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 . +***/ + +#include + +extern const DBusObjectPathVTable bus_manager_vtable; + +#endif diff --git a/dbus-mount.c b/dbus-mount.c new file mode 100644 index 00000000000..cbdb300f2c4 --- /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 . +***/ + +#include "dbus-unit.h" +#include "dbus-mount.h" +#include "dbus-execute.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " " + " " + " " + BUS_EXEC_CONTEXT_INTERFACE + " " + " " + " " + BUS_INTROSPECTABLE_INTERFACE + ""; + +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 00000000000..b92867df288 --- /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 . +***/ + +#include + +#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 00000000000..24dd6c14f64 --- /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 . +***/ + +#include + +#include "dbus-unit.h" +#include "dbus-execute.h" +#include "dbus-service.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " " + " " + " " + " " + " " + " " + BUS_EXEC_CONTEXT_INTERFACE + " " + " " + " " + " " + " " + " " + " " + " " + " " + BUS_INTROSPECTABLE_INTERFACE + ""; + +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 00000000000..f0a468e90d9 --- /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 . +***/ + +#include + +#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 00000000000..8aeca15254e --- /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 . +***/ + +#include "dbus-unit.h" +#include "dbus-snapshot.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " " + " " + " " + " " + BUS_INTROSPECTABLE_INTERFACE + ""; + +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 00000000000..5f28550c95f --- /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 . +***/ + +#include + +#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 00000000000..2a2349c00d7 --- /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 . +***/ + +#include "dbus-unit.h" +#include "dbus-socket.h" +#include "dbus-execute.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " " + " " + " " + " " + BUS_EXEC_CONTEXT_INTERFACE + " " + " " + " " + " " + " " + " " + " " + BUS_INTROSPECTABLE_INTERFACE + ""; + +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 00000000000..6a8f534bf58 --- /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 . +***/ + +#include + +#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 00000000000..be984b9bb47 --- /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 . +***/ + +#include "dbus-unit.h" +#include "dbus-target.h" + +static const char introspection[] = + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE + "" + BUS_UNIT_INTERFACE + BUS_PROPERTIES_INTERFACE + " " + " " + BUS_INTROSPECTABLE_INTERFACE + ""; + +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 00000000000..f6a1ac5e65d --- /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 . +***/ + +#include + +#include "unit.h" + +DBusHandlerResult bus_target_message_handler(Unit *u, DBusMessage *message); + +#endif diff --git a/dbus-unit.c b/dbus-unit.c index 6bccec14a71..cbc2812e315 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 - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - BUS_PROPERTIES_INTERFACE - BUS_INTROSPECTABLE_INTERFACE - ""; - -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 00000000000..471f64cbe88 --- /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 . +***/ + +#include + +#include "manager.h" + +#define BUS_UNIT_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 diff --git a/dbus.c b/dbus.c index a1a3606361e..79b1a7ebc39 100644 --- a/dbus.c +++ b/dbus.c @@ -19,17 +19,19 @@ along with systemd; If not, see . ***/ -#include - #include #include #include #include +#include #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; +} diff --git a/dbus.h b/dbus.h index 412c6683197..47a6639b438 100644 --- a/dbus.h +++ b/dbus.h @@ -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; \ \ diff --git a/device.c b/device.c index a9b003c6648..ddd05b35a08 100644 --- a/device.c +++ b/device.c @@ -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 }; diff --git a/job.c b/job.c index 0e03fcdc77b..c1b00714ec9 100644 --- a/job.c +++ b/job.c @@ -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; diff --git a/manager.c b/manager.c index 6f3ff54d6ce..0187d3b3746 100644 --- a/manager.c +++ b/manager.c @@ -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; diff --git a/mount.c b/mount.c index cc94ca6f236..d3e222d4bc8 100644 --- a/mount.c +++ b/mount.c @@ -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 }; diff --git a/service.c b/service.c index c85c6f572a6..f334027a798 100644 --- a/service.c +++ b/service.c @@ -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 }; diff --git a/socket.c b/socket.c index 88fb2d3869e..22658dcb009 100644 --- a/socket.c +++ b/socket.c @@ -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 dae0648c642..3b65d3c90b3 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; diff --git a/target.c b/target.c index 176ab68c42f..61cbebf654b 100644 --- a/target.c +++ b/target.c @@ -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 }; diff --git a/unit.c b/unit.c index 900c76ad66a..f8589fe6056 100644 --- a/unit.c +++ b/unit.c @@ -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, diff --git a/unit.h b/unit.h index 4dc53a1a687..b3c75ce20a7 100644 --- a/unit.h +++ b/unit.h @@ -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 -- 2.39.2