]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/dbus-service.c
core: don't do runaway fork()s if we hit a segfault from our segfault handler
[thirdparty/systemd.git] / src / core / dbus-service.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
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 Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser 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-kill.h"
27 #include "dbus-service.h"
28 #include "dbus-common.h"
29 #include "selinux-access.h"
30
31 #define BUS_SERVICE_INTERFACE \
32 " <interface name=\"org.freedesktop.systemd1.Service\">\n" \
33 " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
34 " <property name=\"Restart\" type=\"s\" access=\"read\"/>\n" \
35 " <property name=\"PIDFile\" type=\"s\" access=\"read\"/>\n" \
36 " <property name=\"NotifyAccess\" type=\"s\" access=\"read\"/>\n" \
37 " <property name=\"RestartUSec\" type=\"t\" access=\"read\"/>\n" \
38 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
39 " <property name=\"WatchdogUSec\" type=\"t\" access=\"read\"/>\n" \
40 " <property name=\"WatchdogTimestamp\" type=\"t\" access=\"read\"/>\n" \
41 " <property name=\"WatchdogTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
42 " <property name=\"StartLimitInterval\" type=\"t\" access=\"read\"/>\n" \
43 " <property name=\"StartLimitBurst\" type=\"u\" access=\"read\"/>\n" \
44 " <property name=\"StartLimitAction\" type=\"s\" access=\"readwrite\"/>\n" \
45 BUS_EXEC_COMMAND_INTERFACE("ExecStartPre") \
46 BUS_EXEC_COMMAND_INTERFACE("ExecStart") \
47 BUS_EXEC_COMMAND_INTERFACE("ExecStartPost") \
48 BUS_EXEC_COMMAND_INTERFACE("ExecReload") \
49 BUS_EXEC_COMMAND_INTERFACE("ExecStop") \
50 BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \
51 BUS_EXEC_CONTEXT_INTERFACE \
52 BUS_KILL_CONTEXT_INTERFACE \
53 BUS_UNIT_CGROUP_INTERFACE \
54 " <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>\n" \
55 " <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
56 " <property name=\"RemainAfterExit\" type=\"b\" access=\"read\"/>\n" \
57 BUS_EXEC_STATUS_INTERFACE("ExecMain") \
58 " <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n" \
59 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
60 " <property name=\"BusName\" type=\"s\" access=\"read\"/>\n" \
61 " <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
62 " <property name=\"Result\" type=\"s\" access=\"read\"/>\n" \
63 " </interface>\n"
64
65 #define INTROSPECTION \
66 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
67 "<node>\n" \
68 BUS_UNIT_INTERFACE \
69 BUS_SERVICE_INTERFACE \
70 BUS_PROPERTIES_INTERFACE \
71 BUS_PEER_INTERFACE \
72 BUS_INTROSPECTABLE_INTERFACE \
73 "</node>\n"
74
75 #define INTERFACES_LIST \
76 BUS_UNIT_INTERFACES_LIST \
77 "org.freedesktop.systemd1.Service\0"
78
79 const char bus_service_interface[] _introspect_("Service") = BUS_SERVICE_INTERFACE;
80
81 const char bus_service_invalidating_properties[] =
82 "ExecStartPre\0"
83 "ExecStart\0"
84 "ExecStartPost\0"
85 "ExecReload\0"
86 "ExecStop\0"
87 "ExecStopPost\0"
88 "ExecMain\0"
89 "WatchdogTimestamp\0"
90 "WatchdogTimestampMonotonic\0"
91 "MainPID\0"
92 "ControlPID\0"
93 "StatusText\0"
94 "Result\0";
95
96 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
97 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
98 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_notify_access, notify_access, NotifyAccess);
99 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_service_result, service_result, ServiceResult);
100 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_start_limit_action, start_limit_action, StartLimitAction);
101 static DEFINE_BUS_PROPERTY_SET_ENUM(bus_service_set_start_limit_action, start_limit_action, StartLimitAction);
102
103 static const BusProperty bus_exec_main_status_properties[] = {
104 { "ExecMainStartTimestamp", bus_property_append_usec, "t", offsetof(ExecStatus, start_timestamp.realtime) },
105 { "ExecMainStartTimestampMonotonic",bus_property_append_usec, "t", offsetof(ExecStatus, start_timestamp.monotonic) },
106 { "ExecMainExitTimestamp", bus_property_append_usec, "t", offsetof(ExecStatus, exit_timestamp.realtime) },
107 { "ExecMainExitTimestampMonotonic", bus_property_append_usec, "t", offsetof(ExecStatus, exit_timestamp.monotonic) },
108 { "ExecMainPID", bus_property_append_pid, "u", offsetof(ExecStatus, pid) },
109 { "ExecMainCode", bus_property_append_int, "i", offsetof(ExecStatus, code) },
110 { "ExecMainStatus", bus_property_append_int, "i", offsetof(ExecStatus, status) },
111 { NULL, }
112 };
113
114 static const BusProperty bus_service_properties[] = {
115 { "Type", bus_service_append_type, "s", offsetof(Service, type) },
116 { "Restart", bus_service_append_restart, "s", offsetof(Service, restart) },
117 { "PIDFile", bus_property_append_string, "s", offsetof(Service, pid_file), true },
118 { "NotifyAccess", bus_service_append_notify_access, "s", offsetof(Service, notify_access) },
119 { "RestartUSec", bus_property_append_usec, "t", offsetof(Service, restart_usec) },
120 { "TimeoutUSec", bus_property_append_usec, "t", offsetof(Service, timeout_start_usec) },
121 { "TimeoutStartUSec", bus_property_append_usec, "t", offsetof(Service, timeout_start_usec) },
122 { "TimeoutStopUSec", bus_property_append_usec, "t", offsetof(Service, timeout_stop_usec) },
123 { "WatchdogUSec", bus_property_append_usec, "t", offsetof(Service, watchdog_usec) },
124 { "WatchdogTimestamp", bus_property_append_usec, "t", offsetof(Service, watchdog_timestamp.realtime) },
125 { "WatchdogTimestampMonotonic",bus_property_append_usec, "t", offsetof(Service, watchdog_timestamp.monotonic) },
126 { "StartLimitInterval", bus_property_append_usec, "t", offsetof(Service, start_limit.interval) },
127 { "StartLimitBurst", bus_property_append_uint32, "u", offsetof(Service, start_limit.burst) },
128 { "StartLimitAction", bus_service_append_start_limit_action,"s", offsetof(Service, start_limit_action), false, bus_service_set_start_limit_action},
129 BUS_EXEC_COMMAND_PROPERTY("ExecStartPre", offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]), true ),
130 BUS_EXEC_COMMAND_PROPERTY("ExecStart", offsetof(Service, exec_command[SERVICE_EXEC_START]), true ),
131 BUS_EXEC_COMMAND_PROPERTY("ExecStartPost", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), true ),
132 BUS_EXEC_COMMAND_PROPERTY("ExecReload", offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]), true ),
133 BUS_EXEC_COMMAND_PROPERTY("ExecStop", offsetof(Service, exec_command[SERVICE_EXEC_STOP]), true ),
134 BUS_EXEC_COMMAND_PROPERTY("ExecStopPost", offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]), true ),
135 { "PermissionsStartOnly", bus_property_append_bool, "b", offsetof(Service, permissions_start_only) },
136 { "RootDirectoryStartOnly", bus_property_append_bool, "b", offsetof(Service, root_directory_start_only) },
137 { "RemainAfterExit", bus_property_append_bool, "b", offsetof(Service, remain_after_exit) },
138 { "GuessMainPID", bus_property_append_bool, "b", offsetof(Service, guess_main_pid) },
139 { "MainPID", bus_property_append_pid, "u", offsetof(Service, main_pid) },
140 { "ControlPID", bus_property_append_pid, "u", offsetof(Service, control_pid) },
141 { "BusName", bus_property_append_string, "s", offsetof(Service, bus_name), true },
142 { "StatusText", bus_property_append_string, "s", offsetof(Service, status_text), true },
143 { "Result", bus_service_append_service_result,"s", offsetof(Service, result) },
144 { NULL, }
145 };
146
147 DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
148 Service *s = SERVICE(u);
149
150 const BusBoundProperties bps[] = {
151 { "org.freedesktop.systemd1.Unit", bus_unit_properties, u },
152 { "org.freedesktop.systemd1.Service", bus_service_properties, s },
153 { "org.freedesktop.systemd1.Service", bus_exec_context_properties, &s->exec_context },
154 { "org.freedesktop.systemd1.Service", bus_kill_context_properties, &s->kill_context },
155 { "org.freedesktop.systemd1.Service", bus_exec_main_status_properties, &s->main_exec_status },
156 { "org.freedesktop.systemd1.Service", bus_unit_cgroup_properties, u },
157 { NULL, }
158 };
159
160 SELINUX_UNIT_ACCESS_CHECK(u, connection, message, "status");
161
162 return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
163 }