logind-session-dbus.c revision 118ecf32425a590ea266b5c2b6de7962bb242356
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering This file is part of systemd.
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering Copyright 2011 Lennart Poettering
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering systemd is free software; you can redistribute it and/or modify it
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering under the terms of the GNU Lesser General Public License as published by
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering (at your option) any later version.
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering systemd is distributed in the hope that it will be useful, but
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering Lesser General Public License for more details.
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering You should have received a copy of the GNU Lesser General Public License
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <interface name=\"org.freedesktop.login1.Session\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"Terminate\"/>\n" \
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering " <method name=\"Activate\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"Lock\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"Unlock\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"SetIdleHint\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"b\" type=\"b\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </method>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"Kill\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"who\" type=\"s\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"signal\" type=\"s\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </method>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"TakeControl\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"force\" type=\"b\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </method>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"ReleaseControl\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"TakeDevice\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"major\" type=\"u\" direction=\"in\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"minor\" type=\"u\" direction=\"in\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"fd\" type=\"h\" direction=\"out\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"paused\" type=\"b\" direction=\"out\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </method>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"ReleaseDevice\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"major\" type=\"u\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"minor\" type=\"u\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </method>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <method name=\"PauseDeviceComplete\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"major\" type=\"u\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"minor\" type=\"u\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </method>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <signal name=\"PauseDevice\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"major\" type=\"u\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"minor\" type=\"u\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"type\" type=\"s\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </signal>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <signal name=\"ResumeDevice\">\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <arg name=\"major\" type=\"u\"/>\n" \
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering " <arg name=\"minor\" type=\"u\"/>\n" \
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering " <arg name=\"fd\" type=\"h\"/>\n" \
c30a0c62fdbf6f11902be9db64ade99fb508adfdLennart Poettering " </signal>\n" \
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering " <signal name=\"Lock\"/>\n" \
c30a0c62fdbf6f11902be9db64ade99fb508adfdLennart Poettering " <signal name=\"Unlock\"/>\n" \
c30a0c62fdbf6f11902be9db64ade99fb508adfdLennart Poettering " <property name=\"Id\" type=\"s\" access=\"read\"/>\n" \
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering " <property name=\"User\" type=\"(uo)\" access=\"read\"/>\n" \
c30a0c62fdbf6f11902be9db64ade99fb508adfdLennart Poettering " <property name=\"Name\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Timestamp\" type=\"t\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"TimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"VTNr\" type=\"u\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Seat\" type=\"(so)\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"TTY\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Display\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Remote\" type=\"b\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"RemoteHost\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"RemoteUser\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Service\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Scope\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Leader\" type=\"u\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Audit\" type=\"u\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Class\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"Active\" type=\"b\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"State\" type=\"s\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering " </interface>\n"
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering "org.freedesktop.login1.Session\0"
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poetteringstatic int bus_session_append_seat(DBusMessageIter *i, const char *property, void *data) {
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path))
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering if (!dbus_message_iter_close_container(i, &sub))
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poetteringstatic int bus_session_append_user(DBusMessageIter *i, const char *property, void *data) {
8e7fd6ade44ce5dde0867ba748c7978ed1206865Lennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
c485437f50450c0087bae3df4aed462e4a86ee83Zbigniew Jędrzejewski-Szmek if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &u->uid) ||
c485437f50450c0087bae3df4aed462e4a86ee83Zbigniew Jędrzejewski-Szmek !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p))
7b77ed8cf36e8eca6017791626044b61ae2d68e7Lennart Poettering if (!dbus_message_iter_close_container(i, &sub))
c485437f50450c0087bae3df4aed462e4a86ee83Zbigniew Jędrzejewski-Szmekstatic int bus_session_append_active(DBusMessageIter *i, const char *property, void *data) {
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
65b5116220a8ebf8a260716152409aa05377aaccLennart Poetteringstatic int bus_session_append_idle_hint(DBusMessageIter *i, const char *property, void *data) {
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
65b5116220a8ebf8a260716152409aa05377aaccLennart Poetteringstatic int bus_session_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) {
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poettering u = streq(property, "IdleSinceHint") ? t.realtime : t.monotonic;
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
e9d21f240704f87c6bb5f7fca1c5e6d0f31c84cdLennart Poetteringstatic DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_type, session_type, SessionType);
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_class, session_class, SessionClass);
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic int bus_session_append_state(DBusMessageIter *i, const char *property, void *data) {
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering state = session_state_to_string(session_get_state(s));
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &state))
cc3773810855956bad92337cee8fa193584ab62eLennart Poetteringstatic int get_session_for_path(Manager *m, const char *path, Session **_s) {
cc3773810855956bad92337cee8fa193584ab62eLennart Poettering if (!startswith(path, "/org/freedesktop/login1/session/"))
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poetteringstatic const BusProperty bus_login_session_properties[] = {
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Id", bus_property_append_string, "s", offsetof(Session, id), true },
65b5116220a8ebf8a260716152409aa05377aaccLennart Poettering { "Timestamp", bus_property_append_usec, "t", offsetof(Session, timestamp.realtime) },
65b5116220a8ebf8a260716152409aa05377aaccLennart Poettering { "TimestampMonotonic", bus_property_append_usec, "t", offsetof(Session, timestamp.monotonic) },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "VTNr", bus_property_append_uint32, "u", offsetof(Session, vtnr) },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Seat", bus_session_append_seat, "(so)", 0 },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "TTY", bus_property_append_string, "s", offsetof(Session, tty), true },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Display", bus_property_append_string, "s", offsetof(Session, display), true },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Remote", bus_property_append_bool, "b", offsetof(Session, remote) },
65b5116220a8ebf8a260716152409aa05377aaccLennart Poettering { "RemoteUser", bus_property_append_string, "s", offsetof(Session, remote_user), true },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "RemoteHost", bus_property_append_string, "s", offsetof(Session, remote_host), true },
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poettering { "Service", bus_property_append_string, "s", offsetof(Session, service), true },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Scope", bus_property_append_string, "s", offsetof(Session, scope), true },
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poettering { "Leader", bus_property_append_pid, "u", offsetof(Session, leader) },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Audit", bus_property_append_uint32, "u", offsetof(Session, audit_id) },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Type", bus_session_append_type, "s", offsetof(Session, type) },
ed4ba7e4f652150310d062ffbdfefb4521ce1054Lennart Poettering { "Class", bus_session_append_class, "s", offsetof(Session, class) },
65b5116220a8ebf8a260716152409aa05377aaccLennart Poettering { "Active", bus_session_append_active, "b", 0 },
{ NULL, }
{ NULL, }
Session *s,
assert(s);
r = session_stop(s);
if (!reply)
goto oom;
r = session_activate(s);
if (!reply)
goto oom;
goto oom;
if (!reply)
goto oom;
dbus_bool_t b;
unsigned long ul;
if (!dbus_message_get_args(
&error,
DBUS_TYPE_BOOLEAN, &b,
session_set_idle_hint(s, b);
if (!reply)
goto oom;
const char *swho;
if (!dbus_message_get_args(
&error,
if (who < 0)
if (!reply)
goto oom;
unsigned long ul;
if (!dbus_message_get_args(
&error,
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "ReleaseControl")) {
if (!reply)
goto oom;
if (!dbus_message_get_args(
&error,
if (sd) {
if (!reply) {
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "ReleaseDevice")) {
if (!dbus_message_get_args(
&error,
if (!sd)
if (!reply)
goto oom;
} else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "PauseDeviceComplete")) {
if (!dbus_message_get_args(
&error,
if (!sd)
if (!reply)
goto oom;
{ NULL, }
if (reply) {
goto oom;
return DBUS_HANDLER_RESULT_HANDLED;
oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
void *userdata) {
Session *s;
if (r == -ENOMEM)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (r == -ENOENT) {
DBusError e;
dbus_error_init(&e);
assert(s);
return NULL;
assert(s);
return -ENOMEM;
p = session_bus_path(s);
return -ENOMEM;
if (!dbus_message_append_args(
return -ENOMEM;
return -ENOMEM;
assert(s);
if (!s->started)
p = session_bus_path(s);
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
assert(s);
p = session_bus_path(s);
return -ENOMEM;
return -ENOMEM;
return -ENOMEM;
Iterator i;
assert(m);
assert(s);
if (!s->create_message)
if (error) {
if (!reply)
return log_oom();
const char *cseat;
if (fifo_fd < 0) {
return fifo_fd;
if (!path)
return log_oom();
if (!reply)
return log_oom();
exists = false;
if (!dbus_message_append_args(
return log_oom();
session_save(s);
return log_oom();