chiark / gitweb /
dbus: expose distribution name and features on manager object as properties
[elogind.git] / src / dbus-manager.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.h"
25 #include "log.h"
26 #include "dbus-manager.h"
27 #include "strv.h"
28 #include "bus-errors.h"
29 #include "build.h"
30
31 #define BUS_MANAGER_INTERFACE_BEGIN                                     \
32         " <interface name=\"org.freedesktop.systemd1.Manager\">\n"
33
34 #define BUS_MANAGER_INTERFACE_METHODS                                   \
35         "  <method name=\"GetUnit\">\n"                                 \
36         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
37         "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n"        \
38         "  </method>\n"                                                 \
39         "  <method name=\"GetUnitByPID\">\n"                            \
40         "   <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n"          \
41         "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n"        \
42         "  </method>\n"                                                 \
43         "  <method name=\"LoadUnit\">\n"                                \
44         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
45         "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n"        \
46         "  </method>\n"                                                 \
47         "  <method name=\"StartUnit\">\n"                               \
48         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
49         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
50         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
51         "  </method>\n"                                                 \
52         "  <method name=\"StartUnitReplace\">\n"                        \
53         "   <arg name=\"old_unit\" type=\"s\" direction=\"in\"/>\n"     \
54         "   <arg name=\"new_unit\" type=\"s\" direction=\"in\"/>\n"     \
55         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
56         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
57         "  </method>\n"                                                 \
58         "  <method name=\"StopUnit\">\n"                                \
59         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
60         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
61         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
62         "  </method>\n"                                                 \
63         "  <method name=\"ReloadUnit\">\n"                              \
64         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
65         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
66         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
67         "  </method>\n"                                                 \
68         "  <method name=\"RestartUnit\">\n"                             \
69         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
70         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
71         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
72         "  </method>\n"                                                 \
73         "  <method name=\"TryRestartUnit\">\n"                          \
74         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
75         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
76         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
77         "  </method>\n"                                                 \
78         "  <method name=\"ReloadOrRestartUnit\">\n"                     \
79         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
80         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
81         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
82         "  </method>\n"                                                 \
83         "  <method name=\"ReloadOrTryRestartUnit\">\n"                  \
84         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
85         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
86         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
87         "  </method>\n"                                                 \
88         "  <method name=\"KillUnit\">\n"                                \
89         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
90         "   <arg name=\"who\" type=\"s\" direction=\"in\"/>\n"          \
91         "   <arg name=\"mode\" type=\"s\" direction=\"in\"/>\n"         \
92         "   <arg name=\"signal\" type=\"i\" direction=\"in\"/>\n"       \
93         "  </method>\n"                                                 \
94         "  <method name=\"ResetFailedUnit\">\n"                         \
95         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
96         "  </method>\n"                                                 \
97         "  <method name=\"GetJob\">\n"                                  \
98         "   <arg name=\"id\" type=\"u\" direction=\"in\"/>\n"           \
99         "   <arg name=\"job\" type=\"o\" direction=\"out\"/>\n"         \
100         "  </method>\n"                                                 \
101         "  <method name=\"ClearJobs\"/>\n"                              \
102         "  <method name=\"ResetFailed\"/>\n"                            \
103         "  <method name=\"ListUnits\">\n"                               \
104         "   <arg name=\"units\" type=\"a(ssssssouso)\" direction=\"out\"/>\n" \
105         "  </method>\n"                                                 \
106         "  <method name=\"ListJobs\">\n"                                \
107         "   <arg name=\"jobs\" type=\"a(usssoo)\" direction=\"out\"/>\n" \
108         "  </method>\n"                                                 \
109         "  <method name=\"Subscribe\"/>\n"                              \
110         "  <method name=\"Unsubscribe\"/>\n"                            \
111         "  <method name=\"Dump\"/>\n"                                   \
112         "  <method name=\"CreateSnapshot\">\n"                          \
113         "   <arg name=\"name\" type=\"s\" direction=\"in\"/>\n"         \
114         "   <arg name=\"cleanup\" type=\"b\" direction=\"in\"/>\n"      \
115         "   <arg name=\"unit\" type=\"o\" direction=\"out\"/>\n"        \
116         "  </method>\n"                                                 \
117         "  <method name=\"Reload\"/>\n"                                 \
118         "  <method name=\"Reexecute\"/>\n"                              \
119         "  <method name=\"Exit\"/>\n"                                   \
120         "  <method name=\"Reboot\"/>\n"                                 \
121         "  <method name=\"PowerOff\"/>\n"                               \
122         "  <method name=\"Halt\"/>\n"                                   \
123         "  <method name=\"KExec\"/>\n"                                  \
124         "  <method name=\"SetEnvironment\">\n"                          \
125         "   <arg name=\"names\" type=\"as\" direction=\"in\"/>\n"       \
126         "  </method>\n"                                                 \
127         "  <method name=\"UnsetEnvironment\">\n"                        \
128         "   <arg name=\"names\" type=\"as\" direction=\"in\"/>\n"       \
129         "  </method>\n"
130
131 #define BUS_MANAGER_INTERFACE_SIGNALS                                   \
132         "  <signal name=\"UnitNew\">\n"                                 \
133         "   <arg name=\"id\" type=\"s\"/>\n"                            \
134         "   <arg name=\"unit\" type=\"o\"/>\n"                          \
135         "  </signal>\n"                                                 \
136         "  <signal name=\"UnitRemoved\">\n"                             \
137         "   <arg name=\"id\" type=\"s\"/>\n"                            \
138         "   <arg name=\"unit\" type=\"o\"/>\n"                          \
139         "  </signal>\n"                                                 \
140         "  <signal name=\"JobNew\">\n"                                  \
141         "   <arg name=\"id\" type=\"u\"/>\n"                            \
142         "   <arg name=\"job\" type=\"o\"/>\n"                           \
143         "  </signal>\n"                                                 \
144         "  <signal name=\"JobRemoved\">\n"                              \
145         "   <arg name=\"id\" type=\"u\"/>\n"                            \
146         "   <arg name=\"job\" type=\"o\"/>\n"                           \
147         "   <arg name=\"result\" type=\"s\"/>\n"                        \
148         "  </signal>"
149
150 #define BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL                        \
151         "  <property name=\"Version\" type=\"s\" access=\"read\"/>\n"   \
152         "  <property name=\"Distribution\" type=\"s\" access=\"read\"/>\n" \
153         "  <property name=\"Features\" type=\"s\" access=\"read\"/\n"   \
154         "  <property name=\"RunningAs\" type=\"s\" access=\"read\"/>\n" \
155         "  <property name=\"InitRDTimestamp\" type=\"t\" access=\"read\"/>\n" \
156         "  <property name=\"StartupTimestamp\" type=\"t\" access=\"read\"/>\n" \
157         "  <property name=\"FinishTimestamp\" type=\"t\" access=\"read\"/>\n" \
158         "  <property name=\"LogLevel\" type=\"s\" access=\"read\"/>\n"  \
159         "  <property name=\"LogTarget\" type=\"s\" access=\"read\"/>\n" \
160         "  <property name=\"NNames\" type=\"u\" access=\"read\"/>\n"    \
161         "  <property name=\"NJobs\" type=\"u\" access=\"read\"/>\n"     \
162         "  <property name=\"NInstalledJobs\" type=\"u\" access=\"read\"/>\n" \
163         "  <property name=\"NFailedJobs\" type=\"u\" access=\"read\"/>\n" \
164         "  <property name=\"Progress\" type=\"d\" access=\"read\"/>\n"  \
165         "  <property name=\"Environment\" type=\"as\" access=\"read\"/>\n" \
166         "  <property name=\"ConfirmSpawn\" type=\"b\" access=\"read\"/>\n" \
167         "  <property name=\"ShowStatus\" type=\"b\" access=\"read\"/>\n" \
168         "  <property name=\"UnitPath\" type=\"as\" access=\"read\"/>\n" \
169         "  <property name=\"NotifySocket\" type=\"s\" access=\"read\"/>\n" \
170         "  <property name=\"ControlGroupHierarchy\" type=\"s\" access=\"read\"/>\n" \
171         "  <property name=\"MountAuto\" type=\"b\" access=\"read\"/>\n" \
172         "  <property name=\"SwapAuto\" type=\"b\" access=\"read\"/>\n"  \
173         "  <property name=\"DefaultControllers\" type=\"as\" access=\"read\"/>\n" \
174         "  <property name=\"DefaultStandardOutput\" type=\"s\" access=\"read\"/>\n" \
175         "  <property name=\"DefaultStandardError\" type=\"s\" access=\"read\"/>\n"
176
177 #ifdef HAVE_SYSV_COMPAT
178 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV                           \
179         "  <property name=\"SysVConsole\" type=\"b\" access=\"read\"/>\n" \
180         "  <property name=\"SysVInitPath\" type=\"as\" access=\"read\"/>\n" \
181         "  <property name=\"SysVRcndPath\" type=\"as\" access=\"read\"/>\n"
182 #else
183 #define BUS_MANAGER_INTERFACE_PROPERTIES_SYSV
184 #endif
185
186 #define BUS_MANAGER_INTERFACE_END                                       \
187         " </interface>\n"
188
189 #define BUS_MANAGER_INTERFACE                                           \
190         BUS_MANAGER_INTERFACE_BEGIN                                     \
191         BUS_MANAGER_INTERFACE_METHODS                                   \
192         BUS_MANAGER_INTERFACE_SIGNALS                                   \
193         BUS_MANAGER_INTERFACE_PROPERTIES_GENERAL                        \
194         BUS_MANAGER_INTERFACE_PROPERTIES_SYSV                           \
195         BUS_MANAGER_INTERFACE_END
196
197 #define INTROSPECTION_BEGIN                                             \
198         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE                       \
199         "<node>\n"                                                      \
200         BUS_MANAGER_INTERFACE                                           \
201         BUS_PROPERTIES_INTERFACE                                        \
202         BUS_PEER_INTERFACE                                              \
203         BUS_INTROSPECTABLE_INTERFACE
204
205 #define INTROSPECTION_END                                               \
206         "</node>\n"
207
208 const char bus_manager_interface[] _introspect_("Manager") = BUS_MANAGER_INTERFACE;
209
210 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs);
211 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput);
212
213 static int bus_manager_append_log_target(Manager *m, DBusMessageIter *i, const char *property, void *data) {
214         const char *t;
215
216         assert(m);
217         assert(i);
218         assert(property);
219
220         t = log_target_to_string(log_get_target());
221
222         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
223                 return -ENOMEM;
224
225         return 0;
226 }
227
228 static int bus_manager_append_log_level(Manager *m, DBusMessageIter *i, const char *property, void *data) {
229         const char *t;
230
231         assert(m);
232         assert(i);
233         assert(property);
234
235         t = log_level_to_string(log_get_max_level());
236
237         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
238                 return -ENOMEM;
239
240         return 0;
241 }
242
243 static int bus_manager_append_n_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
244         uint32_t u;
245
246         assert(m);
247         assert(i);
248         assert(property);
249
250         u = hashmap_size(m->units);
251
252         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
253                 return -ENOMEM;
254
255         return 0;
256 }
257
258 static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char *property, void *data) {
259         uint32_t u;
260
261         assert(m);
262         assert(i);
263         assert(property);
264
265         u = hashmap_size(m->jobs);
266
267         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, &u))
268                 return -ENOMEM;
269
270         return 0;
271 }
272
273 static int bus_manager_append_progress(Manager *m, DBusMessageIter *i, const char *property, void *data) {
274         double d;
275
276         assert(m);
277         assert(i);
278         assert(property);
279
280         if (dual_timestamp_is_set(&m->finish_timestamp))
281                 d = 1.0;
282         else
283                 d = 1.0 - ((double) hashmap_size(m->jobs) / (double) m->n_installed_jobs);
284
285         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_DOUBLE, &d))
286                 return -ENOMEM;
287
288         return 0;
289 }
290
291 static const char *message_get_sender_with_fallback(DBusMessage *m) {
292         const char *s;
293
294         assert(m);
295
296         if ((s = dbus_message_get_sender(m)))
297                 return s;
298
299         /* When the message came in from a direct connection the
300          * message will have no sender. We fix that here. */
301
302         return ":no-sender";
303 }
304
305 static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection, DBusMessage *message, void *data) {
306         Manager *m = data;
307
308         const BusProperty properties[] = {
309                 { "org.freedesktop.systemd1.Manager", "Version",       bus_property_append_string,    "s",  PACKAGE_STRING     },
310                 { "org.freedesktop.systemd1.Manager", "Distribution",  bus_property_append_string,    "s",  DISTRIBUTION       },
311                 { "org.freedesktop.systemd1.Manager", "Features",      bus_property_append_string,    "s",  SYSTEMD_FEATURES   },
312                 { "org.freedesktop.systemd1.Manager", "RunningAs",     bus_manager_append_running_as, "s",  &m->running_as     },
313                 { "org.freedesktop.systemd1.Manager", "InitRDTimestamp", bus_property_append_uint64,  "t",  &m->initrd_timestamp.realtime },
314                 { "org.freedesktop.systemd1.Manager", "StartupTimestamp", bus_property_append_uint64, "t",  &m->startup_timestamp.realtime },
315                 { "org.freedesktop.systemd1.Manager", "FinishTimestamp", bus_property_append_uint64,  "t",  &m->finish_timestamp.realtime },
316                 { "org.freedesktop.systemd1.Manager", "LogLevel",      bus_manager_append_log_level,  "s",  NULL               },
317                 { "org.freedesktop.systemd1.Manager", "LogTarget",     bus_manager_append_log_target, "s",  NULL               },
318                 { "org.freedesktop.systemd1.Manager", "NNames",        bus_manager_append_n_names,    "u",  NULL               },
319                 { "org.freedesktop.systemd1.Manager", "NJobs",         bus_manager_append_n_jobs,     "u",  NULL               },
320                 { "org.freedesktop.systemd1.Manager", "NInstalledJobs",bus_property_append_uint32,    "u",  &m->n_installed_jobs },
321                 { "org.freedesktop.systemd1.Manager", "NFailedJobs",   bus_property_append_uint32,    "u",  &m->n_failed_jobs  },
322                 { "org.freedesktop.systemd1.Manager", "Progress",      bus_manager_append_progress,   "d",  NULL               },
323                 { "org.freedesktop.systemd1.Manager", "Environment",   bus_property_append_strv,      "as", m->environment     },
324                 { "org.freedesktop.systemd1.Manager", "ConfirmSpawn",  bus_property_append_bool,      "b",  &m->confirm_spawn  },
325                 { "org.freedesktop.systemd1.Manager", "ShowStatus",    bus_property_append_bool,      "b",  &m->show_status    },
326                 { "org.freedesktop.systemd1.Manager", "UnitPath",      bus_property_append_strv,      "as", m->lookup_paths.unit_path },
327                 { "org.freedesktop.systemd1.Manager", "NotifySocket",  bus_property_append_string,    "s",  m->notify_socket   },
328                 { "org.freedesktop.systemd1.Manager", "ControlGroupHierarchy", bus_property_append_string, "s", m->cgroup_hierarchy },
329                 { "org.freedesktop.systemd1.Manager", "MountAuto",     bus_property_append_bool,      "b",  &m->mount_auto     },
330                 { "org.freedesktop.systemd1.Manager", "SwapAuto",      bus_property_append_bool,      "b",  &m->swap_auto      },
331                 { "org.freedesktop.systemd1.Manager", "DefaultControllers", bus_property_append_strv, "as", m->default_controllers },
332                 { "org.freedesktop.systemd1.Manager", "DefaultStandardOutput", bus_manager_append_exec_output, "s", &m->default_std_output },
333                 { "org.freedesktop.systemd1.Manager", "DefaultStandardError",  bus_manager_append_exec_output, "s", &m->default_std_error  },
334 #ifdef HAVE_SYSV_COMPAT
335                 { "org.freedesktop.systemd1.Manager", "SysVConsole",   bus_property_append_bool,      "b",  &m->sysv_console   },
336                 { "org.freedesktop.systemd1.Manager", "SysVInitPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvinit_path },
337                 { "org.freedesktop.systemd1.Manager", "SysVRcndPath",  bus_property_append_strv,      "as", m->lookup_paths.sysvrcnd_path },
338 #endif
339                 { NULL, NULL, NULL, NULL, NULL }
340         };
341
342         int r;
343         DBusError error;
344         DBusMessage *reply = NULL;
345         char * path = NULL;
346         JobType job_type = _JOB_TYPE_INVALID;
347         bool reload_if_possible = false;
348
349         assert(connection);
350         assert(message);
351         assert(m);
352
353         dbus_error_init(&error);
354
355         if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnit")) {
356                 const char *name;
357                 Unit *u;
358
359                 if (!dbus_message_get_args(
360                                     message,
361                                     &error,
362                                     DBUS_TYPE_STRING, &name,
363                                     DBUS_TYPE_INVALID))
364                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
365
366                 if (!(u = manager_get_unit(m, name))) {
367                         dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
368                         return bus_send_error_reply(m, connection, message, &error, -ENOENT);
369                 }
370
371                 if (!(reply = dbus_message_new_method_return(message)))
372                         goto oom;
373
374                 if (!(path = unit_dbus_path(u)))
375                         goto oom;
376
377                 if (!dbus_message_append_args(
378                                     reply,
379                                     DBUS_TYPE_OBJECT_PATH, &path,
380                                     DBUS_TYPE_INVALID))
381                         goto oom;
382         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetUnitByPID")) {
383                 Unit *u;
384                 uint32_t pid;
385
386                 if (!dbus_message_get_args(
387                                     message,
388                                     &error,
389                                     DBUS_TYPE_UINT32, &pid,
390                                     DBUS_TYPE_INVALID))
391                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
392
393                 if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
394                         dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
395                         return bus_send_error_reply(m, connection, message, &error, -ENOENT);
396                 }
397
398                 if (!(reply = dbus_message_new_method_return(message)))
399                         goto oom;
400
401                 if (!(path = unit_dbus_path(u)))
402                         goto oom;
403
404                 if (!dbus_message_append_args(
405                                     reply,
406                                     DBUS_TYPE_OBJECT_PATH, &path,
407                                     DBUS_TYPE_INVALID))
408                         goto oom;
409         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "LoadUnit")) {
410                 const char *name;
411                 Unit *u;
412
413                 if (!dbus_message_get_args(
414                                     message,
415                                     &error,
416                                     DBUS_TYPE_STRING, &name,
417                                     DBUS_TYPE_INVALID))
418                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
419
420                 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
421                         return bus_send_error_reply(m, connection, message, &error, r);
422
423                 if (!(reply = dbus_message_new_method_return(message)))
424                         goto oom;
425
426                 if (!(path = unit_dbus_path(u)))
427                         goto oom;
428
429                 if (!dbus_message_append_args(
430                                     reply,
431                                     DBUS_TYPE_OBJECT_PATH, &path,
432                                     DBUS_TYPE_INVALID))
433                         goto oom;
434
435         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnit"))
436                 job_type = JOB_START;
437         else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
438                 job_type = JOB_START;
439         else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StopUnit"))
440                 job_type = JOB_STOP;
441         else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadUnit"))
442                 job_type = JOB_RELOAD;
443         else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "RestartUnit"))
444                 job_type = JOB_RESTART;
445         else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "TryRestartUnit"))
446                 job_type = JOB_TRY_RESTART;
447         else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrRestartUnit")) {
448                 reload_if_possible = true;
449                 job_type = JOB_RESTART;
450         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ReloadOrTryRestartUnit")) {
451                 reload_if_possible = true;
452                 job_type = JOB_TRY_RESTART;
453         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KillUnit")) {
454                 const char *name, *swho, *smode;
455                 int32_t signo;
456                 Unit *u;
457                 KillMode mode;
458                 KillWho who;
459
460                 if (!dbus_message_get_args(
461                                     message,
462                                     &error,
463                                     DBUS_TYPE_STRING, &name,
464                                     DBUS_TYPE_STRING, &swho,
465                                     DBUS_TYPE_STRING, &smode,
466                                     DBUS_TYPE_INT32, &signo,
467                                     DBUS_TYPE_INVALID))
468                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
469
470                 if ((mode = kill_mode_from_string(smode)) < 0 ||
471                     (who = kill_who_from_string(swho)) < 0 ||
472                     signo <= 0 ||
473                     signo >= _NSIG)
474                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
475
476                 if (!(u = manager_get_unit(m, name))) {
477                         dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
478                         return bus_send_error_reply(m, connection, message, &error, -ENOENT);
479                 }
480
481                 if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
482                         return bus_send_error_reply(m, connection, message, &error, r);
483
484                 if (!(reply = dbus_message_new_method_return(message)))
485                         goto oom;
486
487         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "GetJob")) {
488                 uint32_t id;
489                 Job *j;
490
491                 if (!dbus_message_get_args(
492                                     message,
493                                     &error,
494                                     DBUS_TYPE_UINT32, &id,
495                                     DBUS_TYPE_INVALID))
496                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
497
498                 if (!(j = manager_get_job(m, id))) {
499                         dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
500                         return bus_send_error_reply(m, connection, message, &error, -ENOENT);
501                 }
502
503                 if (!(reply = dbus_message_new_method_return(message)))
504                         goto oom;
505
506                 if (!(path = job_dbus_path(j)))
507                         goto oom;
508
509                 if (!dbus_message_append_args(
510                                     reply,
511                                     DBUS_TYPE_OBJECT_PATH, &path,
512                                     DBUS_TYPE_INVALID))
513                         goto oom;
514
515         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ClearJobs")) {
516
517                 manager_clear_jobs(m);
518
519                 if (!(reply = dbus_message_new_method_return(message)))
520                         goto oom;
521
522         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailed")) {
523
524                 manager_reset_failed(m);
525
526                 if (!(reply = dbus_message_new_method_return(message)))
527                         goto oom;
528
529         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ResetFailedUnit")) {
530                 const char *name;
531                 Unit *u;
532
533                 if (!dbus_message_get_args(
534                                     message,
535                                     &error,
536                                     DBUS_TYPE_STRING, &name,
537                                     DBUS_TYPE_INVALID))
538                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
539
540                 if (!(u = manager_get_unit(m, name))) {
541                         dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
542                         return bus_send_error_reply(m, connection, message, &error, -ENOENT);
543                 }
544
545                 unit_reset_failed(u);
546
547                 if (!(reply = dbus_message_new_method_return(message)))
548                         goto oom;
549
550         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListUnits")) {
551                 DBusMessageIter iter, sub;
552                 Iterator i;
553                 Unit *u;
554                 const char *k;
555
556                 if (!(reply = dbus_message_new_method_return(message)))
557                         goto oom;
558
559                 dbus_message_iter_init_append(reply, &iter);
560
561                 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssssssouso)", &sub))
562                         goto oom;
563
564                 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
565                         char *u_path, *j_path;
566                         const char *description, *load_state, *active_state, *sub_state, *sjob_type, *following;
567                         DBusMessageIter sub2;
568                         uint32_t job_id;
569                         Unit *f;
570
571                         if (k != u->meta.id)
572                                 continue;
573
574                         if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
575                                 goto oom;
576
577                         description = unit_description(u);
578                         load_state = unit_load_state_to_string(u->meta.load_state);
579                         active_state = unit_active_state_to_string(unit_active_state(u));
580                         sub_state = unit_sub_state_to_string(u);
581
582                         f = unit_following(u);
583                         following = f ? f->meta.id : "";
584
585                         if (!(u_path = unit_dbus_path(u)))
586                                 goto oom;
587
588                         if (u->meta.job) {
589                                 job_id = (uint32_t) u->meta.job->id;
590
591                                 if (!(j_path = job_dbus_path(u->meta.job))) {
592                                         free(u_path);
593                                         goto oom;
594                                 }
595
596                                 sjob_type = job_type_to_string(u->meta.job->type);
597                         } else {
598                                 job_id = 0;
599                                 j_path = u_path;
600                                 sjob_type = "";
601                         }
602
603                         if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &u->meta.id) ||
604                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &description) ||
605                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &load_state) ||
606                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &active_state) ||
607                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sub_state) ||
608                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &following) ||
609                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path) ||
610                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &job_id) ||
611                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &sjob_type) ||
612                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path)) {
613                                 free(u_path);
614                                 if (u->meta.job)
615                                         free(j_path);
616                                 goto oom;
617                         }
618
619                         free(u_path);
620                         if (u->meta.job)
621                                 free(j_path);
622
623                         if (!dbus_message_iter_close_container(&sub, &sub2))
624                                 goto oom;
625                 }
626
627                 if (!dbus_message_iter_close_container(&iter, &sub))
628                         goto oom;
629
630         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "ListJobs")) {
631                 DBusMessageIter iter, sub;
632                 Iterator i;
633                 Job *j;
634
635                 if (!(reply = dbus_message_new_method_return(message)))
636                         goto oom;
637
638                 dbus_message_iter_init_append(reply, &iter);
639
640                 if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(usssoo)", &sub))
641                         goto oom;
642
643                 HASHMAP_FOREACH(j, m->jobs, i) {
644                         char *u_path, *j_path;
645                         const char *state, *type;
646                         uint32_t id;
647                         DBusMessageIter sub2;
648
649                         if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
650                                 goto oom;
651
652                         id = (uint32_t) j->id;
653                         state = job_state_to_string(j->state);
654                         type = job_type_to_string(j->type);
655
656                         if (!(j_path = job_dbus_path(j)))
657                                 goto oom;
658
659                         if (!(u_path = unit_dbus_path(j->unit))) {
660                                 free(j_path);
661                                 goto oom;
662                         }
663
664                         if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &id) ||
665                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &j->unit->meta.id) ||
666                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &type) ||
667                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &state) ||
668                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &j_path) ||
669                             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &u_path)) {
670                                 free(j_path);
671                                 free(u_path);
672                                 goto oom;
673                         }
674
675                         free(j_path);
676                         free(u_path);
677
678                         if (!dbus_message_iter_close_container(&sub, &sub2))
679                                 goto oom;
680                 }
681
682                 if (!dbus_message_iter_close_container(&iter, &sub))
683                         goto oom;
684
685         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Subscribe")) {
686                 char *client;
687                 Set *s;
688
689                 if (!(s = BUS_CONNECTION_SUBSCRIBED(m, connection))) {
690                         if (!(s = set_new(string_hash_func, string_compare_func)))
691                                 goto oom;
692
693                         if (!(dbus_connection_set_data(connection, m->subscribed_data_slot, s, NULL))) {
694                                 set_free(s);
695                                 goto oom;
696                         }
697                 }
698
699                 if (!(client = strdup(message_get_sender_with_fallback(message))))
700                         goto oom;
701
702                 if ((r = set_put(s, client)) < 0) {
703                         free(client);
704                         return bus_send_error_reply(m, connection, message, NULL, r);
705                 }
706
707                 if (!(reply = dbus_message_new_method_return(message)))
708                         goto oom;
709
710         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Unsubscribe")) {
711                 char *client;
712
713                 if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
714                         dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
715                         return bus_send_error_reply(m, connection, message, &error, -ENOENT);
716                 }
717
718                 free(client);
719
720                 if (!(reply = dbus_message_new_method_return(message)))
721                         goto oom;
722
723         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Dump")) {
724                 FILE *f;
725                 char *dump = NULL;
726                 size_t size;
727
728                 if (!(reply = dbus_message_new_method_return(message)))
729                         goto oom;
730
731                 if (!(f = open_memstream(&dump, &size)))
732                         goto oom;
733
734                 manager_dump_units(m, f, NULL);
735                 manager_dump_jobs(m, f, NULL);
736
737                 if (ferror(f)) {
738                         fclose(f);
739                         free(dump);
740                         goto oom;
741                 }
742
743                 fclose(f);
744
745                 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &dump, DBUS_TYPE_INVALID)) {
746                         free(dump);
747                         goto oom;
748                 }
749
750                 free(dump);
751         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "CreateSnapshot")) {
752                 const char *name;
753                 dbus_bool_t cleanup;
754                 Snapshot *s;
755
756                 if (!dbus_message_get_args(
757                                     message,
758                                     &error,
759                                     DBUS_TYPE_STRING, &name,
760                                     DBUS_TYPE_BOOLEAN, &cleanup,
761                                     DBUS_TYPE_INVALID))
762                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
763
764                 if (name && name[0] == 0)
765                         name = NULL;
766
767                 if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
768                         return bus_send_error_reply(m, connection, message, &error, r);
769
770                 if (!(reply = dbus_message_new_method_return(message)))
771                         goto oom;
772
773                 if (!(path = unit_dbus_path(UNIT(s))))
774                         goto oom;
775
776                 if (!dbus_message_append_args(
777                                     reply,
778                                     DBUS_TYPE_OBJECT_PATH, &path,
779                                     DBUS_TYPE_INVALID))
780                         goto oom;
781
782         } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect")) {
783                 char *introspection = NULL;
784                 FILE *f;
785                 Iterator i;
786                 Unit *u;
787                 Job *j;
788                 const char *k;
789                 size_t size;
790
791                 if (!(reply = dbus_message_new_method_return(message)))
792                         goto oom;
793
794                 /* We roll our own introspection code here, instead of
795                  * relying on bus_default_message_handler() because we
796                  * need to generate our introspection string
797                  * dynamically. */
798
799                 if (!(f = open_memstream(&introspection, &size)))
800                         goto oom;
801
802                 fputs(INTROSPECTION_BEGIN, f);
803
804                 HASHMAP_FOREACH_KEY(u, k, m->units, i) {
805                         char *p;
806
807                         if (k != u->meta.id)
808                                 continue;
809
810                         if (!(p = bus_path_escape(k))) {
811                                 fclose(f);
812                                 free(introspection);
813                                 goto oom;
814                         }
815
816                         fprintf(f, "<node name=\"unit/%s\"/>", p);
817                         free(p);
818                 }
819
820                 HASHMAP_FOREACH(j, m->jobs, i)
821                         fprintf(f, "<node name=\"job/%lu\"/>", (unsigned long) j->id);
822
823                 fputs(INTROSPECTION_END, f);
824
825                 if (ferror(f)) {
826                         fclose(f);
827                         free(introspection);
828                         goto oom;
829                 }
830
831                 fclose(f);
832
833                 if (!introspection)
834                         goto oom;
835
836                 if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID)) {
837                         free(introspection);
838                         goto oom;
839                 }
840
841                 free(introspection);
842
843         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reload")) {
844
845                 assert(!m->queued_message);
846
847                 /* Instead of sending the reply back right away, we
848                  * just remember that we need to and then send it
849                  * after the reload is finished. That way the caller
850                  * knows when the reload finished. */
851
852                 if (!(m->queued_message = dbus_message_new_method_return(message)))
853                         goto oom;
854
855                 m->queued_message_connection = connection;
856                 m->exit_code = MANAGER_RELOAD;
857
858         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reexecute")) {
859
860                 if (!(reply = dbus_message_new_method_return(message)))
861                         goto oom;
862
863                 m->exit_code = MANAGER_REEXECUTE;
864
865         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Exit")) {
866
867                 if (m->running_as == MANAGER_SYSTEM) {
868                         dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
869                         return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
870                 }
871
872                 if (!(reply = dbus_message_new_method_return(message)))
873                         goto oom;
874
875                 m->exit_code = MANAGER_EXIT;
876
877         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Reboot")) {
878
879                 if (m->running_as != MANAGER_SYSTEM) {
880                         dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
881                         return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
882                 }
883
884                 if (!(reply = dbus_message_new_method_return(message)))
885                         goto oom;
886
887                 m->exit_code = MANAGER_REBOOT;
888
889         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "PowerOff")) {
890
891                 if (m->running_as != MANAGER_SYSTEM) {
892                         dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
893                         return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
894                 }
895
896                 if (!(reply = dbus_message_new_method_return(message)))
897                         goto oom;
898
899                 m->exit_code = MANAGER_POWEROFF;
900
901         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "Halt")) {
902
903                 if (m->running_as != MANAGER_SYSTEM) {
904                         dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
905                         return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
906                 }
907
908                 if (!(reply = dbus_message_new_method_return(message)))
909                         goto oom;
910
911                 m->exit_code = MANAGER_HALT;
912
913         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "KExec")) {
914
915                 if (m->running_as != MANAGER_SYSTEM) {
916                         dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
917                         return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
918                 }
919
920                 if (!(reply = dbus_message_new_method_return(message)))
921                         goto oom;
922
923                 m->exit_code = MANAGER_KEXEC;
924
925         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "SetEnvironment")) {
926                 char **l = NULL, **e = NULL;
927
928                 if ((r = bus_parse_strv(message, &l)) < 0) {
929                         if (r == -ENOMEM)
930                                 goto oom;
931
932                         return bus_send_error_reply(m, connection, message, NULL, r);
933                 }
934
935                 e = strv_env_merge(2, m->environment, l);
936                 strv_free(l);
937
938                 if (!e)
939                         goto oom;
940
941                 if (!(reply = dbus_message_new_method_return(message))) {
942                         strv_free(e);
943                         goto oom;
944                 }
945
946                 strv_free(m->environment);
947                 m->environment = e;
948
949         } else if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "UnsetEnvironment")) {
950                 char **l = NULL, **e = NULL;
951
952                 if ((r = bus_parse_strv(message, &l)) < 0) {
953                         if (r == -ENOMEM)
954                                 goto oom;
955
956                         return bus_send_error_reply(m, connection, message, NULL, r);
957                 }
958
959                 e = strv_env_delete(m->environment, 1, l);
960                 strv_free(l);
961
962                 if (!e)
963                         goto oom;
964
965                 if (!(reply = dbus_message_new_method_return(message)))
966                         goto oom;
967
968                 strv_free(m->environment);
969                 m->environment = e;
970
971         } else
972                 return bus_default_message_handler(m, connection, message, NULL, properties);
973
974         if (job_type != _JOB_TYPE_INVALID) {
975                 const char *name, *smode, *old_name = NULL;
976                 JobMode mode;
977                 Job *j;
978                 Unit *u;
979                 bool b;
980
981                 if (dbus_message_is_method_call(message, "org.freedesktop.systemd1.Manager", "StartUnitReplace"))
982                         b = dbus_message_get_args(
983                                         message,
984                                         &error,
985                                         DBUS_TYPE_STRING, &old_name,
986                                         DBUS_TYPE_STRING, &name,
987                                         DBUS_TYPE_STRING, &smode,
988                                         DBUS_TYPE_INVALID);
989                 else
990                         b = dbus_message_get_args(
991                                         message,
992                                         &error,
993                                         DBUS_TYPE_STRING, &name,
994                                         DBUS_TYPE_STRING, &smode,
995                                         DBUS_TYPE_INVALID);
996
997                 if (!b)
998                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
999
1000                 if (old_name)
1001                         if (!(u = manager_get_unit(m, old_name)) ||
1002                             !u->meta.job ||
1003                             u->meta.job->type != JOB_START) {
1004                                 dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
1005                                 return bus_send_error_reply(m, connection, message, &error, -ENOENT);
1006                         }
1007
1008
1009                 if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
1010                         dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
1011                         return bus_send_error_reply(m, connection, message, &error, -EINVAL);
1012                 }
1013
1014                 if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
1015                         return bus_send_error_reply(m, connection, message, &error, r);
1016
1017                 if (reload_if_possible && unit_can_reload(u)) {
1018                         if (job_type == JOB_RESTART)
1019                                 job_type = JOB_RELOAD_OR_START;
1020                         else if (job_type == JOB_TRY_RESTART)
1021                                 job_type = JOB_RELOAD;
1022                 }
1023
1024                 if ((job_type == JOB_START && u->meta.refuse_manual_start) ||
1025                     (job_type == JOB_STOP && u->meta.refuse_manual_stop) ||
1026                     ((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
1027                      (u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
1028                         dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
1029                         return bus_send_error_reply(m, connection, message, &error, -EPERM);
1030                 }
1031
1032                 if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
1033                         return bus_send_error_reply(m, connection, message, &error, r);
1034
1035                 if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
1036                         goto oom;
1037
1038                 j->bus = connection;
1039
1040                 if (!(reply = dbus_message_new_method_return(message)))
1041                         goto oom;
1042
1043                 if (!(path = job_dbus_path(j)))
1044                         goto oom;
1045
1046                 if (!dbus_message_append_args(
1047                                     reply,
1048                                     DBUS_TYPE_OBJECT_PATH, &path,
1049                                     DBUS_TYPE_INVALID))
1050                         goto oom;
1051         }
1052
1053         free(path);
1054
1055         if (reply) {
1056                 if (!dbus_connection_send(connection, reply, NULL))
1057                         goto oom;
1058
1059                 dbus_message_unref(reply);
1060         }
1061
1062         return DBUS_HANDLER_RESULT_HANDLED;
1063
1064 oom:
1065         free(path);
1066
1067         if (reply)
1068                 dbus_message_unref(reply);
1069
1070         dbus_error_free(&error);
1071
1072         return DBUS_HANDLER_RESULT_NEED_MEMORY;
1073 }
1074
1075 const DBusObjectPathVTable bus_manager_vtable = {
1076         .message_function = bus_manager_message_handler
1077 };