chiark / gitweb /
unit: record inactive enter/exit timestamps to facilitate syslog lookups
[elogind.git] / dbus-mount.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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-mount.h"
26 #include "dbus-execute.h"
27
28 static const char introspection[] =
29         DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
30         "<node>"
31         BUS_UNIT_INTERFACE
32         BUS_PROPERTIES_INTERFACE
33         " <interface name=\"org.freedesktop.systemd1.Mount\">"
34         "  <property name=\"Where\" type=\"s\" access=\"read\"/>"
35         "  <property name=\"What\" type=\"s\" access=\"read\"/>"
36         "  <property name=\"Options\" type=\"s\" access=\"read\"/>"
37         "  <property name=\"Type\" type=\"s\" access=\"read\"/>"
38         "  <property name=\"TimeoutUSec\" type=\"t\" access=\"read\"/>"
39         BUS_EXEC_CONTEXT_INTERFACE
40         "  <property name=\"KillMode\" type=\"s\" access=\"read\"/>"
41         "  <property name=\"ControlPID\" type=\"u\" access=\"read\"/>"
42         " </interface>"
43         BUS_INTROSPECTABLE_INTERFACE
44         "</node>";
45
46 static int bus_mount_append_what(Manager *n, DBusMessageIter *i, const char *property, void *data) {
47         Mount *m = data;
48         const char *d;
49
50         assert(n);
51         assert(i);
52         assert(property);
53         assert(m);
54
55         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.what)
56                 d = m->parameters_proc_self_mountinfo.what;
57         else if (m->from_fragment && m->parameters_fragment.what)
58                 d = m->parameters_fragment.what;
59         else if (m->from_etc_fstab && m->parameters_etc_fstab.what)
60                 d = m->parameters_etc_fstab.what;
61         else
62                 d = "";
63
64         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
65                 return -ENOMEM;
66
67         return 0;
68 }
69
70 static int bus_mount_append_options(Manager *n, DBusMessageIter *i, const char *property, void *data) {
71         Mount *m = data;
72         const char *d;
73
74         assert(n);
75         assert(i);
76         assert(property);
77         assert(m);
78
79         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.options)
80                 d = m->parameters_proc_self_mountinfo.options;
81         else if (m->from_fragment && m->parameters_fragment.options)
82                 d = m->parameters_fragment.options;
83         else if (m->from_etc_fstab && m->parameters_etc_fstab.options)
84                 d = m->parameters_etc_fstab.options;
85         else
86                 d = "";
87
88         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
89                 return -ENOMEM;
90
91         return 0;
92 }
93
94 static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *property, void *data) {
95         Mount *m = data;
96         const char *d;
97
98         assert(n);
99         assert(i);
100         assert(property);
101         assert(m);
102
103         if (m->from_proc_self_mountinfo && m->parameters_proc_self_mountinfo.fstype)
104                 d = m->parameters_proc_self_mountinfo.fstype;
105         else if (m->from_fragment && m->parameters_fragment.fstype)
106                 d = m->parameters_fragment.fstype;
107         else if (m->from_etc_fstab && m->parameters_etc_fstab.fstype)
108                 d = m->parameters_etc_fstab.fstype;
109         else
110                 d = "";
111
112         if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &d))
113                 return -ENOMEM;
114
115         return 0;
116 }
117
118 DBusHandlerResult bus_mount_message_handler(Unit *u, DBusMessage *message) {
119         const BusProperty properties[] = {
120                 BUS_UNIT_PROPERTIES,
121                 { "org.freedesktop.systemd1.Mount", "Where",       bus_property_append_string, "s", u->mount.where         },
122                 { "org.freedesktop.systemd1.Mount", "What",        bus_mount_append_what,      "s", u                      },
123                 { "org.freedesktop.systemd1.Mount", "Options",     bus_mount_append_options,   "s", u                      },
124                 { "org.freedesktop.systemd1.Mount", "Type",        bus_mount_append_type,      "s", u                      },
125                 { "org.freedesktop.systemd1.Mount", "TimeoutUSec", bus_property_append_usec,   "t", &u->mount.timeout_usec },
126                 /* ExecCommand */
127                 BUS_EXEC_CONTEXT_PROPERTIES("org.freedesktop.systemd1.Mount", u->mount.exec_context),
128                 { "org.freedesktop.systemd1.Mount", "KillMode",    bus_unit_append_kill_mode,  "s", &u->mount.kill_mode    },
129                 { "org.freedesktop.systemd1.Mount", "ControlPID",  bus_property_append_pid,    "u", &u->mount.control_pid  },
130                 { NULL, NULL, NULL, NULL, NULL }
131         };
132
133         return bus_default_message_handler(u->meta.manager, message, introspection, properties);
134 }