]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/dbus-service.c
service: rework killing logic so that we always kill the main process, even if it...
[thirdparty/systemd.git] / src / 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
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
4288f619
LP
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" \
d264aa33 33 " <property name=\"NotifyAccess\" type=\"s\" access=\"read\"/>\n" \
4288f619
LP
34 " <property name=\"RestartUSec\" type=\"t\" access=\"read\"/>\n" \
35 " <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>\n" \
fe68089d
LP
36 BUS_EXEC_COMMAND_INTERFACE("ExecStartPre") \
37 BUS_EXEC_COMMAND_INTERFACE("ExecStart") \
38 BUS_EXEC_COMMAND_INTERFACE("ExecStartPost") \
39 BUS_EXEC_COMMAND_INTERFACE("ExecReload") \
40 BUS_EXEC_COMMAND_INTERFACE("ExecStop") \
41 BUS_EXEC_COMMAND_INTERFACE("ExecStopPost") \
4288f619
LP
42 BUS_EXEC_CONTEXT_INTERFACE \
43 " <property name=\"PermissionsStartOnly\" type=\"b\" access=\"read\"/>\n" \
44 " <property name=\"RootDirectoryStartOnly\" type=\"b\" access=\"read\"/>\n" \
02ee865a 45 " <property name=\"RemainAfterExit\" type=\"b\" access=\"read\"/>\n" \
b58b4116 46 BUS_EXEC_STATUS_INTERFACE("ExecMain") \
4288f619
LP
47 " <property name=\"MainPID\" type=\"u\" access=\"read\"/>\n" \
48 " <property name=\"ControlPID\" type=\"u\" access=\"read\"/>\n" \
d264aa33
LP
49 " <property name=\"SysVStartPriority\" type=\"i\" access=\"read\"/>\n" \
50 " <property name=\"SysVRunLevels\" type=\"s\" access=\"read\"/>\n" \
4288f619
LP
51 " <property name=\"SysVPath\" type=\"s\" access=\"read\"/>\n" \
52 " <property name=\"BusName\" type=\"s\" access=\"read\"/>\n" \
8c47c732
LP
53 " <property name=\"StatusText\" type=\"s\" access=\"read\"/>\n" \
54 " </interface>\n"
4288f619
LP
55
56#define INTROSPECTION \
57 DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
58 "<node>\n" \
59 BUS_UNIT_INTERFACE \
60 BUS_SERVICE_INTERFACE \
61 BUS_PROPERTIES_INTERFACE \
c4e2ceae 62 BUS_PEER_INTERFACE \
4288f619
LP
63 BUS_INTROSPECTABLE_INTERFACE \
64 "</node>\n"
65
66const char bus_service_interface[] = BUS_SERVICE_INTERFACE;
4139c1b2 67
c4e2ceae
LP
68const char bus_service_invalidating_properties[] =
69 "ExecStartPre\0"
70 "ExecStart\0"
71 "ExecStartPost\0"
72 "ExecReload\0"
73 "ExecStop\0"
74 "ExecStopPost\0"
75 "ExecMain\0"
76 "MainPID\0"
77 "ControlPID\0"
78 "StatusText\0"
79 "\0";
80
4139c1b2
LP
81static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_type, service_type, ServiceType);
82static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_restart, service_restart, ServiceRestart);
d264aa33 83static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_service_append_notify_access, notify_access, NotifyAccess);
4139c1b2 84
5e8d1c9a 85DBusHandlerResult bus_service_message_handler(Unit *u, DBusConnection *connection, DBusMessage *message) {
4139c1b2
LP
86 const BusProperty properties[] = {
87 BUS_UNIT_PROPERTIES,
d264aa33
LP
88 { "org.freedesktop.systemd1.Service", "Type", bus_service_append_type, "s", &u->service.type },
89 { "org.freedesktop.systemd1.Service", "Restart", bus_service_append_restart, "s", &u->service.restart },
90 { "org.freedesktop.systemd1.Service", "PIDFile", bus_property_append_string, "s", u->service.pid_file },
91 { "org.freedesktop.systemd1.Service", "NotifyAccess", bus_service_append_notify_access, "s", &u->service.notify_access },
92 { "org.freedesktop.systemd1.Service", "RestartUSec", bus_property_append_usec, "t", &u->service.restart_usec },
93 { "org.freedesktop.systemd1.Service", "TimeoutUSec", bus_property_append_usec, "t", &u->service.timeout_usec },
fe68089d
LP
94 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_START_PRE], "ExecStartPre"),
95 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_START], "ExecStart"),
96 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_START_POST], "ExecStartPost"),
97 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_RELOAD], "ExecReload"),
98 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_STOP], "ExecStop"),
99 BUS_EXEC_COMMAND_PROPERTY("org.freedesktop.systemd1.Service", u->service.exec_command[SERVICE_EXEC_STOP_POST], "ExecStopPost"),
4139c1b2 100 BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Service", u->service.exec_context),
d264aa33 101 { "org.freedesktop.systemd1.Service", "PermissionsStartOnly", bus_property_append_bool, "b", &u->service.permissions_start_only },
4139c1b2 102 { "org.freedesktop.systemd1.Service", "RootDirectoryStartOnly", bus_property_append_bool, "b", &u->service.root_directory_start_only },
02ee865a 103 { "org.freedesktop.systemd1.Service", "RemainAfterExit", bus_property_append_bool, "b", &u->service.remain_after_exit },
b58b4116 104 BUS_EXEC_STATUS_PROPERTIES("org.freedesktop.systemd1.Service", u->service.main_exec_status, "ExecMain"),
d264aa33
LP
105 { "org.freedesktop.systemd1.Service", "MainPID", bus_property_append_pid, "u", &u->service.main_pid },
106 { "org.freedesktop.systemd1.Service", "ControlPID", bus_property_append_pid, "u", &u->service.control_pid },
107 { "org.freedesktop.systemd1.Service", "SysVPath", bus_property_append_string, "s", u->service.sysv_path },
108 { "org.freedesktop.systemd1.Service", "BusName", bus_property_append_string, "s", u->service.bus_name },
109 { "org.freedesktop.systemd1.Service", "StatusText", bus_property_append_string, "s", u->service.status_text },
110 { "org.freedesktop.systemd1.Service", "SysVRunLevels", bus_property_append_string, "s", u->service.sysv_runlevels },
111 { "org.freedesktop.systemd1.Service", "SysVStartPriority", bus_property_append_int, "i", &u->service.sysv_start_priority },
4139c1b2
LP
112 { NULL, NULL, NULL, NULL, NULL }
113 };
114
5e8d1c9a 115 return bus_default_message_handler(u->meta.manager, connection, message, INTROSPECTION, properties);
4139c1b2 116}