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