chiark / gitweb /
main: add configuration option to alter capability bounding set for PID 1
[elogind.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-service.h"
27 #include "dbus-common.h"
28
29 #ifdef HAVE_SYSV_COMPAT
30 #define BUS_SERVICE_SYSV_INTERFACE_FRAGMENT                            \
31         "  <property name=\"SysVStartPriority\" type=\"i\" access=\"read\"/>\n" \
32         "  <property name=\"SysVRunLevels\" type=\"s\" access=\"read\"/>\n"
33 #else
34 #define BUS_SERVICE_SYSV_INTERFACE_FRAGMENT ""
35 #endif
36
37 #define BUS_SERVICE_INTERFACE                                           \
38         " <interface name=\"org.freedesktop.systemd1.Service\">\n"      \
39         "  <property name=\"Type\" type=\"s\" access=\"read\"/>\n"      \
40         "  <property name=\"Restart\" type=\"s\" access=\"read\"/>\n"   \
41         "  <property name=\"PIDFile\" type=\"s\" access=\"read\"/>\n"   \
42         "  <property name=\"NotifyAccess\" type=\"s\" access=\"read\"/>\n" \
43         "  <property name=\"RestartUSec\" type=\"t\" access=\"read\"/>\n" \
44         "  <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
45         "  <property name=\"WatchdogUSec\" type=\"t\" access=\"read\"/>\n" \
46         "  <property name=\"WatchdogTimestamp\" type=\"t\" access=\"read\"/>\n" \
47         "  <property name=\"WatchdogTimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
48         "  <property name=\"StartLimitInterval\" type=\"t\" access=\"read\"/>\n" \
49         "  <property name=\"StartLimitBurst\" type=\"u\" access=\"read\"/>\n" \
50         "  <property name=\"StartLimitAction\" type=\"s\" access=\"readwrite\"/>\n" \
51         BUS_EXEC_COMMAND_INTERFACE("ExecStartPre")                      \
52         BUS_EXEC_COMMAND_INTERFACE("ExecStart")                         \
53         BUS_EXEC_COMMAND_INTERFACE("ExecStartPost")                     \
54         BUS_EXEC_COMMAND_INTERFACE("ExecReload")                        \
55         BUS_EXEC_COMMAND_INTERFACE("ExecStop")                          \
56         BUS_EXEC_COMMAND_INTERFACE("ExecStopPost")                      \
57         BUS_EXEC_CONTEXT_INTERFACE                                      \
58         "  <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>\n" \
59         "  <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
60         "  <property name=\"RemainAfterExit\" type=\"b\" access=\"read\"/>\n" \
61         BUS_EXEC_STATUS_INTERFACE("ExecMain")                           \
62         "  <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n"   \
63         "  <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
64         "  <property name=\"BusName\" type=\"s\" access=\"read\"/>\n"   \
65         "  <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
66         "  <property name=\"FsckPassNo\" type=\"i\" access=\"read\"/>\n" \
67         "  <property name=\"Result\" type=\"s\" access=\"read\"/>\n"    \
68         BUS_SERVICE_SYSV_INTERFACE_FRAGMENT                             \
69        " </interface>\n"
70
71 #define INTROSPECTION                                                   \
72         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
73         "<node>\n"                                                      \
74         BUS_UNIT_INTERFACE                                              \
75         BUS_SERVICE_INTERFACE                                           \
76         BUS_PROPERTIES_INTERFACE                                        \
77         BUS_PEER_INTERFACE                                              \
78         BUS_INTROSPECTABLE_INTERFACE                                    \
79         "</node>\n"
80
81 #define INTERFACES_LIST                              \
82         BUS_UNIT_INTERFACES_LIST                     \
83         "org.freedesktop.systemd1.Service\0"
84
85 const char bus_service_interface[] _introspect_("Service") = BUS_SERVICE_INTERFACE;
86
87 const char bus_service_invalidating_properties[] =
88         "ExecStartPre\0"
89         "ExecStart\0"
90         "ExecStartPost\0"
91         "ExecReload\0"
92         "ExecStop\0"
93         "ExecStopPost\0"
94         "ExecMain\0"
95         "WatchdogTimestamp\0"
96         "WatchdogTimestampMonotonic\0"
97         "MainPID\0"
98         "ControlPID\0"
99         "StatusText\0"
100         "Result\0";
101
102 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
103 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
104 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_notify_access, notify_access, NotifyAccess);
105 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_service_result, service_result, ServiceResult);
106 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_start_limit_action, start_limit_action, StartLimitAction);
107 static DEFINE_BUS_PROPERTY_SET_ENUM(bus_service_set_start_limit_action, start_limit_action, StartLimitAction);
108
109 static const BusProperty bus_exec_main_status_properties[] = {
110         { "ExecMainStartTimestamp",         bus_property_append_usec, "t", offsetof(ExecStatus, start_timestamp.realtime)  },
111         { "ExecMainStartTimestampMonotonic",bus_property_append_usec, "t", offsetof(ExecStatus, start_timestamp.monotonic) },
112         { "ExecMainExitTimestamp",          bus_property_append_usec, "t", offsetof(ExecStatus, start_timestamp.realtime)  },
113         { "ExecMainExitTimestampMonotonic", bus_property_append_usec, "t", offsetof(ExecStatus, start_timestamp.monotonic) },
114         { "ExecMainPID",                    bus_property_append_pid,  "u", offsetof(ExecStatus, pid)                       },
115         { "ExecMainCode",                   bus_property_append_int,  "i", offsetof(ExecStatus, code)                      },
116         { "ExecMainStatus",                 bus_property_append_int,  "i", offsetof(ExecStatus, status)                    },
117         { NULL, }
118 };
119
120 static const BusProperty bus_service_properties[] = {
121         { "Type",                   bus_service_append_type,          "s", offsetof(Service, type)                         },
122         { "Restart",                bus_service_append_restart,       "s", offsetof(Service, restart)                      },
123         { "PIDFile",                bus_property_append_string,       "s", offsetof(Service, pid_file),               true },
124         { "NotifyAccess",           bus_service_append_notify_access, "s", offsetof(Service, notify_access)                },
125         { "RestartUSec",            bus_property_append_usec,         "t", offsetof(Service, restart_usec)                 },
126         { "TimeoutUSec",            bus_property_append_usec,         "t", offsetof(Service, timeout_usec)                 },
127         { "WatchdogUSec",           bus_property_append_usec,         "t", offsetof(Service, watchdog_usec)                },
128         { "WatchdogTimestamp",      bus_property_append_usec,         "t", offsetof(Service, watchdog_timestamp.realtime)  },
129         { "WatchdogTimestampMonotonic",bus_property_append_usec,      "t", offsetof(Service, watchdog_timestamp.monotonic) },
130         { "StartLimitInterval",     bus_property_append_usec,         "t", offsetof(Service, start_limit.interval)         },
131         { "StartLimitBurst",        bus_property_append_uint32,       "u", offsetof(Service, start_limit.burst)            },
132         { "StartLimitAction",       bus_service_append_start_limit_action,"s", offsetof(Service, start_limit_action), false, bus_service_set_start_limit_action},
133         BUS_EXEC_COMMAND_PROPERTY("ExecStartPre",  offsetof(Service, exec_command[SERVICE_EXEC_START_PRE]),  true ),
134         BUS_EXEC_COMMAND_PROPERTY("ExecStart",     offsetof(Service, exec_command[SERVICE_EXEC_START]),      true ),
135         BUS_EXEC_COMMAND_PROPERTY("ExecStartPost", offsetof(Service, exec_command[SERVICE_EXEC_START_POST]), true ),
136         BUS_EXEC_COMMAND_PROPERTY("ExecReload",    offsetof(Service, exec_command[SERVICE_EXEC_RELOAD]),     true ),
137         BUS_EXEC_COMMAND_PROPERTY("ExecStop",      offsetof(Service, exec_command[SERVICE_EXEC_STOP]),       true ),
138         BUS_EXEC_COMMAND_PROPERTY("ExecStopPost",  offsetof(Service, exec_command[SERVICE_EXEC_STOP_POST]),  true ),
139         { "PermissionsStartOnly",   bus_property_append_bool,         "b", offsetof(Service, permissions_start_only)       },
140         { "RootDirectoryStartOnly", bus_property_append_bool,         "b", offsetof(Service, root_directory_start_only)    },
141         { "RemainAfterExit",        bus_property_append_bool,         "b", offsetof(Service, remain_after_exit)            },
142         { "GuessMainPID",           bus_property_append_bool,         "b", offsetof(Service, guess_main_pid)               },
143         { "MainPID",                bus_property_append_pid,          "u", offsetof(Service, main_pid)                     },
144         { "ControlPID",             bus_property_append_pid,          "u", offsetof(Service, control_pid)                  },
145         { "BusName",                bus_property_append_string,       "s", offsetof(Service, bus_name),               true },
146         { "StatusText",             bus_property_append_string,       "s", offsetof(Service, status_text),            true },
147 #ifdef HAVE_SYSV_COMPAT
148         { "SysVRunLevels",          bus_property_append_string,       "s", offsetof(Service, sysv_runlevels),         true },
149         { "SysVStartPriority",      bus_property_append_int,          "i", offsetof(Service, sysv_start_priority)          },
150 #endif
151         { "FsckPassNo",             bus_property_append_int,          "i", offsetof(Service, fsck_passno)                  },
152         { "Result",                 bus_service_append_service_result,"s", offsetof(Service, result)                       },
153         { NULL, }
154 };
155
156 DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
157         Service *s = SERVICE(u);
158         const BusBoundProperties bps[] = {
159                 { "org.freedesktop.systemd1.Unit",    bus_unit_properties,             u },
160                 { "org.freedesktop.systemd1.Service", bus_service_properties,          s },
161                 { "org.freedesktop.systemd1.Service", bus_exec_context_properties,     &s->exec_context },
162                 { "org.freedesktop.systemd1.Service", bus_exec_main_status_properties, &s->main_exec_status },
163                 { NULL, }
164         };
165
166         return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, bps);
167 }