logind-session-dbus.c revision d200735e13c52dcfe36c0e066f9f6c2fbfb85a9c
/*-*- 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 General Public License as published by
the Free Software Foundation; either version 2 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
General Public License for more details.
You should have received a copy of the GNU 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" \
" <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=\"ControlGroupPath\" 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=\"Active\" type=\"b\" 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 = "/";
}
free(p);
return -ENOMEM;
}
free(p);
if (!dbus_message_iter_close_container(i, &sub))
return -ENOMEM;
return 0;
}
char *p = NULL;
assert(i);
assert(u);
return -ENOMEM;
p = user_bus_path(u);
if (!p)
return -ENOMEM;
free(p);
return -ENOMEM;
}
free(p);
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;
assert(i);
assert(s);
session_get_idle_hint(s, &t);
if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
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[] = {
};
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:
if (reply)
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) {
char *t, *r;
assert(s);
t = bus_path_escape(s->id);
if (!t)
return NULL;
r = strappend("/org/freedesktop/login1/session/", t);
free(t);
return r;
}
DBusMessage *m;
int r = -ENOMEM;
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)
goto finish;
if (!dbus_message_append_args(
m,
DBUS_TYPE_STRING, &s->id,
goto finish;
goto finish;
r = 0;
free(p);
return r;
}
DBusMessage *m;
int r = -ENOMEM;
char *p = NULL;
assert(s);
if (!s->started)
return 0;
p = session_bus_path(s);
if (!p)
return -ENOMEM;
if (!m)
goto finish;
goto finish;
r = 0;
if (m)
free(p);
return r;
}
DBusMessage *m;
bool b;
char *p;
assert(s);
p = session_bus_path(s);
if (!p)
return -ENOMEM;
free(p);
if (!m)
return -ENOMEM;
if (!b)
return -ENOMEM;
return 0;
}