logind-session-dbus.c revision 7fd1b19bc9e9f5574f2877936b8ac267c7706947
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <string.h>
#include "logind.h"
#include "logind-session.h"
#include "dbus-common.h"
#include "util.h"
#define BUS_SESSION_INTERFACE \
" <interface name=\"org.freedesktop.login1.Session\">\n" \
" <method name=\"Terminate\"/>\n" \
" <method name=\"Activate\"/>\n" \
" <method name=\"Lock\"/>\n" \
" <method name=\"Unlock\"/>\n" \
" <method name=\"SetIdleHint\">\n" \
" <arg name=\"b\" type=\"b\"/>\n" \
" </method>\n" \
" <method name=\"Kill\">\n" \
" <arg name=\"who\" type=\"s\"/>\n" \
" <arg name=\"signal\" type=\"s\"/>\n" \
" </method>\n" \
" <signal name=\"Lock\"/>\n" \
" <signal name=\"Unlock\"/>\n" \
" <property name=\"Id\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"User\" type=\"(uo)\" access=\"read\"/>\n" \
" <property name=\"Name\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Timestamp\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"TimestampMonotonic\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"DefaultControlGroup\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"VTNr\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"Seat\" type=\"(so)\" access=\"read\"/>\n" \
" <property name=\"TTY\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Display\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Remote\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"RemoteHost\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"RemoteUser\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Service\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Leader\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"Audit\" type=\"u\" access=\"read\"/>\n" \
" <property name=\"Type\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Class\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Active\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"State\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"Controllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"ResetControllers\" type=\"as\" access=\"read\"/>\n" \
" <property name=\"KillProcesses\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"IdleHint\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"IdleSinceHint\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"IdleSinceHintMonotonic\" type=\"t\" access=\"read\"/>\n" \
" </interface>\n"
#define INTROSPECTION \
"<node>\n" \
"</node>\n"
#define INTERFACES_LIST \
"org.freedesktop.login1.Session\0"
char *p = NULL;
assert(i);
assert(s);
return -ENOMEM;
if (s->seat) {
if (!p)
return -ENOMEM;
} else {
id = "";
path = "/";
}
return -ENOMEM;
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
_cleanup_free_ char *p = NULL;
assert(i);
assert(u);
return -ENOMEM;
p = user_bus_path(u);
if (!p)
return -ENOMEM;
return -ENOMEM;
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
dbus_bool_t b;
assert(i);
assert(s);
b = session_is_active(s);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
int b;
assert(i);
assert(s);
b = session_get_idle_hint(s, NULL) > 0;
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &b))
return -ENOMEM;
return 0;
}
static int bus_session_append_idle_hint_since(DBusMessageIter *i, const char *property, void *data) {
uint64_t u;
int r;
assert(i);
assert(s);
r = session_get_idle_hint(s, &t);
if (r < 0)
return r;
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
return -ENOMEM;
return 0;
}
static int bus_session_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) {
_cleanup_free_ char *t = NULL;
int r;
bool success;
assert(i);
assert(s);
if (r < 0)
return r;
}
const char *state;
assert(i);
assert(s);
return -ENOMEM;
return 0;
}
Session *s;
char *id;
assert(m);
return -EINVAL;
if (!id)
return -ENOMEM;
if (!s)
return -ENOENT;
*_s = s;
return 0;
}
static const BusProperty bus_login_session_properties[] = {
{ NULL, }
};
static const BusProperty bus_login_session_user_properties[] = {
{ NULL, }
};
Session *s,
DBusMessage *message) {
int r;
assert(s);
r = session_stop(s);
if (r < 0)
if (!reply)
goto oom;
r = session_activate(s);
if (r < 0)
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,
if (ul == (unsigned long) -1)
session_set_idle_hint(s, b);
if (!reply)
goto oom;
const char *swho;
if (!dbus_message_get_args(
&error,
else {
if (who < 0)
}
if (r < 0)
if (!reply)
goto oom;
} else {
const BusBoundProperties bps[] = {
{ "org.freedesktop.login1.Session", bus_login_session_properties, s },
{ NULL, }
};
}
if (reply) {
goto oom;
}
return DBUS_HANDLER_RESULT_HANDLED;
oom:
return DBUS_HANDLER_RESULT_NEED_MEMORY;
}
void *userdata) {
Session *s;
int r;
if (r < 0) {
if (r == -ENOMEM)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
if (r == -ENOENT) {
DBusError e;
dbus_error_init(&e);
}
}
}
const DBusObjectPathVTable bus_session_vtable = {
};
char *session_bus_path(Session *s) {
_cleanup_free_ char *t;
assert(s);
t = bus_path_escape(s->id);
if (!t)
return NULL;
return strappend("/org/freedesktop/login1/session/", t);
}
_cleanup_free_ char *p = NULL;
assert(s);
m = dbus_message_new_signal("/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
if (!m)
return -ENOMEM;
p = session_bus_path(s);
if (!p)
return -ENOMEM;
if (!dbus_message_append_args(
m,
DBUS_TYPE_STRING, &s->id,
return -ENOMEM;
return -ENOMEM;
return 0;
}
_cleanup_free_ char *p = NULL;
assert(s);
if (!s->started)
return 0;
p = session_bus_path(s);
if (!p)
return -ENOMEM;
if (!m)
return -ENOMEM;
return -ENOMEM;
return 0;
}
bool b;
_cleanup_free_ char *p = NULL;
assert(s);
p = session_bus_path(s);
if (!p)
return -ENOMEM;
if (!m)
return -ENOMEM;
if (!b)
return -ENOMEM;
return 0;
}
Iterator i;
int r = 0;
assert(m);
int k;
if (k < 0)
r = k;
}
return r;
}