chiark / gitweb /
unit: get rid of various unnecessary casts
[elogind.git] / src / dbus-service.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23
24 #include "dbus-unit.h"
25 #include "dbus-execute.h"
26 #include "dbus-service.h"
27
28 #define BUS_SERVICE_INTERFACE                                           \
29         " <interface name=\"org.freedesktop.systemd1.Service\">\n"      \
30         "  <property name=\"Type\" type=\"s\" access=\"read\"/>\n"      \
31         "  <property name=\"Restart\" type=\"s\" access=\"read\"/>\n"   \
32         "  <property name=\"PIDFile\" type=\"s\" access=\"read\"/>\n"   \
33         "  <property name=\"RestartUSec\" type=\"t\" access=\"read\"/>\n" \
34         "  <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
35         BUS_EXEC_CONTEXT_INTERFACE                                      \
36         "  <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>\n" \
37         "  <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
38         "  <property name=\"ValidNoProcess\" type=\"b\" access=\"read\"/>\n" \
39         "  <property name=\"KillMode\" type=\"s\" access=\"read\"/>\n"  \
40         "  <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n"   \
41         "  <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
42         "  <property name=\"SysVPath\" type=\"s\" access=\"read\"/>\n"  \
43         "  <property name=\"BusName\" type=\"s\" access=\"read\"/>\n"   \
44         "  <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
45        " </interface>\n"
46
47 #define INTROSPECTION                                                   \
48         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
49         "<node>\n"                                                      \
50         BUS_UNIT_INTERFACE                                              \
51         BUS_SERVICE_INTERFACE                                           \
52         BUS_PROPERTIES_INTERFACE                                        \
53         BUS_INTROSPECTABLE_INTERFACE                                    \
54         "</node>\n"
55
56 const char bus_service_interface[] = BUS_SERVICE_INTERFACE;
57
58 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
59 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
60
61 DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
62         const BusProperty properties[] = {
63                 BUS_UNIT_PROPERTIES,
64                 { "org.freedesktop.systemd1.Service", "Type",                   bus_service_append_type,    "s", &u->service.type },
65                 { "org.freedesktop.systemd1.Service", "Restart",                bus_service_append_restart, "s", &u->service.restart },
66                 { "org.freedesktop.systemd1.Service", "PIDFile",                bus_property_append_string, "s", u->service.pid_file },
67                 { "org.freedesktop.systemd1.Service", "RestartUSec",            bus_property_append_usec,   "t", &u->service.restart_usec },
68                 { "org.freedesktop.systemd1.Service", "TimeoutUSec",            bus_property_append_usec,   "t", &u->service.timeout_usec },
69                 /* ExecCommand */
70                 BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Service", u->service.exec_context),
71                 { "org.freedesktop.systemd1.Service", "PermissionsStartOnly",   bus_property_append_bool,   "b", &u->service.permissions_start_only },
72                 { "org.freedesktop.systemd1.Service", "RootDirectoryStartOnly", bus_property_append_bool,   "b", &u->service.root_directory_start_only },
73                 { "org.freedesktop.systemd1.Service", "ValidNoProcess",         bus_property_append_bool,   "b", &u->service.valid_no_process },
74                 { "org.freedesktop.systemd1.Service", "KillMode",               bus_unit_append_kill_mode,  "s", &u->service.kill_mode },
75                 /* MainExecStatus */
76                 { "org.freedesktop.systemd1.Service", "MainPID",                bus_property_append_pid,    "u", &u->service.main_pid },
77                 { "org.freedesktop.systemd1.Service", "ControlPID",             bus_property_append_pid,    "u", &u->service.control_pid },
78                 { "org.freedesktop.systemd1.Service", "SysVPath",               bus_property_append_string, "s", u->service.sysv_path },
79                 { "org.freedesktop.systemd1.Service", "BusName",                bus_property_append_string, "s", u->service.bus_name },
80                 { "org.freedesktop.systemd1.Service", "StatusText",             bus_property_append_string, "s", u->service.status_text },
81                 { NULL, NULL, NULL, NULL, NULL }
82         };
83
84         return bus_default_message_handler(u->meta.manager, connection, message, INTROSPECTION, properties);
85 }