logind-session-dbus.c revision 4bba9156da3e1df2cee24d10d7cd88c776ef4179
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering This file is part of systemd.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering Copyright 2011 Lennart Poettering
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering systemd is free software; you can redistribute it and/or modify it
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering under the terms of the GNU General Public License as published by
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering the Free Software Foundation; either version 2 of the License, or
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering (at your option) any later version.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering systemd is distributed in the hope that it will be useful, but
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering General Public License for more details.
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering You should have received a copy of the GNU General Public License
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1Lennart Poettering " <interface name=\"org.freedesktop.login1.Session\">\n" \
b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1Lennart Poettering " <method name=\"Terminate\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <method name=\"Activate\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " <method name=\"Lock\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <method name=\"Unlock\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " <method name=\"SetIdleHint\">\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <arg name=\"b\" type=\"b\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " </method>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <method name=\"Kill\">\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <arg name=\"who\" type=\"s\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <arg name=\"signal\" type=\"s\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " </method>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"Id\" type=\"s\" access=\"read\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " <property name=\"User\" type=\"(uo)\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"Name\" type=\"s\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"Timestamp\" type=\"t\" access=\"read\"/>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <property name=\"TimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"ControlGroupPath\" type=\"s\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"VTNr\" type=\"u\" access=\"read\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " <property name=\"Seat\" type=\"(so)\" access=\"read\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " <property name=\"TTY\" type=\"s\" access=\"read\"/>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <property name=\"Display\" type=\"s\" access=\"read\"/>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <property name=\"Remote\" type=\"b\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"RemoteHost\" type=\"s\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"RemoteUser\" type=\"s\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"Service\" type=\"s\" access=\"read\"/>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <property name=\"Leader\" type=\"u\" access=\"read\"/>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <property name=\"Audit\" type=\"u\" access=\"read\"/>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"Active\" type=\"b\" access=\"read\"/>\n" \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering " <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"KillProcesses\" type=\"b\" access=\"read\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering " <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering " </interface>\n"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE \
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering "org.freedesktop.login1.Session\0"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringstatic int bus_session_append_seat(DBusMessageIter *i, const char *property, void *data) {
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) {
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering if (!dbus_message_iter_close_container(i, &sub))
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poetteringstatic int bus_session_append_user(DBusMessageIter *i, const char *property, void *data) {
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering if (!dbus_message_iter_open_container(i, DBUS_TYPE_STRUCT, NULL, &sub))
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &s->user->uid) ||
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering if (!dbus_message_iter_close_container(i, &sub))
15411c0cb1192799b37ec8f25d6f30e8d7292fc6David Herrmannstatic int bus_session_append_active(DBusMessageIter *i, const char *property, void *data) {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poetteringstatic int bus_session_append_idle_hint(DBusMessageIter *i, const char *property, void *data) {
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poetteringstatic int bus_session_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) {
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering u = streq(property, "IdleSinceHint") ? t.realtime : t.monotonic;
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poetteringstatic DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_session_append_type, session_type, SessionType);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poetteringstatic int get_session_for_path(Manager *m, const char *path, Session **_s) {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering if (!startswith(path, "/org/freedesktop/login1/session/"))
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poetteringstatic DBusHandlerResult session_message_dispatch(
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "Id", bus_property_append_string, "s", s->id },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "User", bus_session_append_user, "(uo)", s },
dca348bcbb462305864526c587495a14a76bfcdeJan Engelhardt { "org.freedesktop.login1.Session", "Name", bus_property_append_string, "s", s->user->name },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "Timestamp", bus_property_append_usec, "t", &s->timestamp.realtime },
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering { "org.freedesktop.login1.Session", "TimestampMonotonic", bus_property_append_usec, "t", &s->timestamp.monotonic },
9444b1f20e311f073864d81e913bd4f32fe95cfdLennart Poettering { "org.freedesktop.login1.Session", "ControlGroupPath", bus_property_append_string, "s", s->cgroup_path },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "VTNr", bus_property_append_uint32, "u", &s->vtnr },
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering { "org.freedesktop.login1.Session", "Seat", bus_session_append_seat, "(so)", s },
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering { "org.freedesktop.login1.Session", "TTY", bus_property_append_string, "s", s->tty },
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering { "org.freedesktop.login1.Session", "Display", bus_property_append_string, "s", s->display },
79413b673b45adc98dfeaec882bbdda2343cb2f9Lennart Poettering { "org.freedesktop.login1.Session", "Remote", bus_property_append_bool, "b", &s->remote },
6569cae18ed640a4e9f52f73e2a3ec54b07d0406Lennart Poettering { "org.freedesktop.login1.Session", "RemoteUser", bus_property_append_string, "s", s->remote_user },
6569cae18ed640a4e9f52f73e2a3ec54b07d0406Lennart Poettering { "org.freedesktop.login1.Session", "RemoteHost", bus_property_append_string, "s", s->remote_host },
7584d236eac91f9b7128b1eb08bddf18be2bce9fZbigniew Jędrzejewski-Szmek { "org.freedesktop.login1.Session", "Service", bus_property_append_string, "s", s->service },
6aaa8c2f783cd1b3ac27c5ce40625d032e7e3d71Zbigniew Jędrzejewski-Szmek { "org.freedesktop.login1.Session", "Leader", bus_property_append_pid, "u", &s->leader },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "Audit", bus_property_append_uint32, "u", &s->audit_id },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "Type", bus_session_append_type, "s", &s->type },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "Active", bus_session_append_active, "b", s },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "Controllers", bus_property_append_strv, "as", s->controllers },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "ResetControllers", bus_property_append_strv, "as", s->reset_controllers },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "KillProcesses", bus_property_append_bool, "b", &s->kill_processes },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "IdleHint", bus_session_append_idle_hint, "b", s },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "IdleSinceHint", bus_session_append_idle_hint_since, "t", s },
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering { "org.freedesktop.login1.Session", "IdleSinceHintMonotonic", bus_session_append_idle_hint_since, "t", s },
6569cae18ed640a4e9f52f73e2a3ec54b07d0406Lennart Poettering if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Terminate")) {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering return bus_send_error_reply(connection, message, NULL, r);
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering reply = dbus_message_new_method_return(message);
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Activate")) {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering return bus_send_error_reply(connection, message, NULL, r);
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering reply = dbus_message_new_method_return(message);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Lock") ||
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "Unlock")) {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering if (session_send_signal(s, streq(dbus_message_get_member(message), "Lock")) < 0)
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering reply = dbus_message_new_method_return(message);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Session", "SetIdleHint")) {
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering unsigned long ul;
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering return bus_send_error_reply(connection, message, &error, -EINVAL);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), &error);
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering return bus_send_error_reply(connection, message, &error, -EIO);
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;
return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
if (reply) {
goto oom;
return DBUS_HANDLER_RESULT_HANDLED;
oom:
if (reply)
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;
free(t);
DBusMessage *m;
int r = -ENOMEM;
char *p = NULL;
assert(s);
return -ENOMEM;
p = session_bus_path(s);
goto finish;
if (!dbus_message_append_args(
goto finish;
goto finish;
free(p);
DBusMessage *m;
int r = -ENOMEM;
char *p = NULL;
assert(s);
if (!s->started)
p = session_bus_path(s);
return -ENOMEM;
goto finish;
goto finish;
free(p);
DBusMessage *m;
assert(s);
p = session_bus_path(s);
return -ENOMEM;
free(p);
return -ENOMEM;
return -ENOMEM;