]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/dbus-service.c
service: make main pid guessing optional, and reread pid file after reloads
[thirdparty/systemd.git] / src / 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 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 #ifdef HAVE_SYSV_COMPAT
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" \
37 BUS_EXEC_COMMAND_INTERFACE("ExecStartPre") \
38 BUS_EXEC_COMMAND_INTERFACE("ExecStart") \
39 BUS_EXEC_COMMAND_INTERFACE("ExecStartPost") \
40 BUS_EXEC_COMMAND_INTERFACE("ExecReload") \
41 BUS_EXEC_COMMAND_INTERFACE("ExecStop") \
42 BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \
43 BUS_EXEC_CONTEXT_INTERFACE \
44 " <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>\n" \
45 " <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
46 " <property name=\"RemainAfterExit\" type=\"b\" access=\"read\"/>\n" \
47 BUS_EXEC_STATUS_INTERFACE("ExecMain") \
48 " <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n" \
49 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
50 " <property name=\"SysVStartPriority\" type=\"i\" access=\"read\"/>\n" \
51 " <property name=\"SysVRunLevels\" type=\"s\" access=\"read\"/>\n" \
52 " <property name=\"SysVPath\" type=\"s\" access=\"read\"/>\n" \
53 " <property name=\"BusName\" type=\"s\" access=\"read\"/>\n" \
54 " <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
55 " </interface>\n"
56 #else
57 #define BUS_SERVICE_INTERFACE \
58 " <interface name=\"org.freedesktop.systemd1.Service\">\n" \
59 " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
60 " <property name=\"Restart\" type=\"s\" access=\"read\"/>\n" \
61 " <property name=\"PIDFile\" type=\"s\" access=\"read\"/>\n" \
62 " <property name=\"NotifyAccess\" type=\"s\" access=\"read\"/>\n" \
63 " <property name=\"RestartUSec\" type=\"t\" access=\"read\"/>\n" \
64 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
65 BUS_EXEC_COMMAND_INTERFACE("ExecStartPre") \
66 BUS_EXEC_COMMAND_INTERFACE("ExecStart") \
67 BUS_EXEC_COMMAND_INTERFACE("ExecStartPost") \
68 BUS_EXEC_COMMAND_INTERFACE("ExecReload") \
69 BUS_EXEC_COMMAND_INTERFACE("ExecStop") \
70 BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \
71 BUS_EXEC_CONTEXT_INTERFACE \
72 " <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>\n" \
73 " <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
74 " <property name=\"RemainAfterExit\" type=\"b\" access=\"read\"/>\n" \
75 BUS_EXEC_STATUS_INTERFACE("ExecMain") \
76 " <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n" \
77 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
78 " <property name=\"BusName\" type=\"s\" access=\"read\"/>\n" \
79 " <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
80 " </interface>\n"
81 #endif
82
83 #define INTROSPECTION \
84 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
85 "<node>\n" \
86 BUS_UNIT_INTERFACE \
87 BUS_SERVICE_INTERFACE \
88 BUS_PROPERTIES_INTERFACE \
89 BUS_PEER_INTERFACE \
90 BUS_INTROSPECTABLE_INTERFACE \
91 "</node>\n"
92
93 const char bus_service_interface[] _introspect_("Service") = BUS_SERVICE_INTERFACE;
94
95 const char bus_service_invalidating_properties[] =
96 "ExecStartPre\0"
97 "ExecStart\0"
98 "ExecStartPost\0"
99 "ExecReload\0"
100 "ExecStop\0"
101 "ExecStopPost\0"
102 "ExecMain\0"
103 "MainPID\0"
104 "ControlPID\0"
105 "StatusText\0"
106 "\0";
107
108 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
109 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
110 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_notify_access, notify_access, NotifyAccess);
111
112 DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
113 const BusProperty properties[] = {
114 BUS_UNIT_PROPERTIES,
115 { "org.freedesktop.systemd1.Service", "Type", bus_service_append_type, "s", &u->service.type },
116 { "org.freedesktop.systemd1.Service", "Restart", bus_service_append_restart, "s", &u->service.restart },
117 { "org.freedesktop.systemd1.Service", "PIDFile", bus_property_append_string, "s", u->service.pid_file },
118 { "org.freedesktop.systemd1.Service", "NotifyAccess", bus_service_append_notify_access, "s", &u->service.notify_access },
119 { "org.freedesktop.systemd1.Service", "RestartUSec", bus_property_append_usec, "t", &u->service.restart_usec },
120 { "org.freedesktop.systemd1.Service", "TimeoutUSec", bus_property_append_usec, "t", &u->service.timeout_usec },
121 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_START_PRE], "ExecStartPre"),
122 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_START], "ExecStart"),
123 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_START_POST], "ExecStartPost"),
124 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_RELOAD], "ExecReload"),
125 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_STOP], "ExecStop"),
126 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_STOP_POST], "ExecStopPost"),
127 BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Service", u->service.exec_context),
128 { "org.freedesktop.systemd1.Service", "PermissionsStartOnly", bus_property_append_bool, "b", &u->service.permissions_start_only },
129 { "org.freedesktop.systemd1.Service", "RootDirectoryStartOnly", bus_property_append_bool, "b", &u->service.root_directory_start_only },
130 { "org.freedesktop.systemd1.Service", "RemainAfterExit", bus_property_append_bool, "b", &u->service.remain_after_exit },
131 { "org.freedesktop.systemd1.Service", "GuessMainPID", bus_property_append_bool, "b", &u->service.guess_main_pid },
132 BUS_EXEC_STATUS_PROPERTIES("org.freedesktop.systemd1.Service", u->service.main_exec_status, "ExecMain"),
133 { "org.freedesktop.systemd1.Service", "MainPID", bus_property_append_pid, "u", &u->service.main_pid },
134 { "org.freedesktop.systemd1.Service", "ControlPID", bus_property_append_pid, "u", &u->service.control_pid },
135 #ifdef HAVE_SYSV_COMPAT
136 { "org.freedesktop.systemd1.Service", "SysVPath", bus_property_append_string, "s", u->service.sysv_path },
137 #endif
138 { "org.freedesktop.systemd1.Service", "BusName", bus_property_append_string, "s", u->service.bus_name },
139 { "org.freedesktop.systemd1.Service", "StatusText", bus_property_append_string, "s", u->service.status_text },
140 #ifdef HAVE_SYSV_COMPAT
141 { "org.freedesktop.systemd1.Service", "SysVRunLevels", bus_property_append_string, "s", u->service.sysv_runlevels },
142 { "org.freedesktop.systemd1.Service", "SysVStartPriority", bus_property_append_int, "i", &u->service.sysv_start_priority },
143 #endif
144 { "org.freedesktop.systemd1.Service", "FsckPassNo", bus_property_append_int, "i", &u->service.fsck_passno },
145 { NULL, NULL, NULL, NULL, NULL }
146 };
147
148 return bus_default_message_handler(u->meta.manager, connection, message, INTROSPECTION, properties);
149 }