logind-session-dbus.c revision cc3773810855956bad92337cee8fa193584ab62e
/*-*- 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 "util.h"
#include "strv.h"
#include "bus-util.h"
#include "logind.h"
#include "logind-session.h"
#include "logind-session-device.h"
static int property_get_user(
const char *path,
const char *interface,
const char *property,
void *userdata) {
_cleanup_free_ char *p = NULL;
assert(s);
p = user_bus_path(s->user);
if (!p)
return -ENOMEM;
}
static int property_get_name(
const char *path,
const char *interface,
const char *property,
void *userdata) {
assert(s);
}
static int property_get_seat(
const char *path,
const char *interface,
const char *property,
void *userdata) {
_cleanup_free_ char *p = NULL;
assert(s);
if (!p)
return -ENOMEM;
}
static int property_get_active(
const char *path,
const char *interface,
const char *property,
void *userdata) {
assert(s);
}
static int property_get_state(
const char *path,
const char *interface,
const char *property,
void *userdata) {
assert(s);
}
static int property_get_idle_hint(
const char *path,
const char *interface,
const char *property,
void *userdata) {
assert(s);
}
static int property_get_idle_since_hint(
const char *path,
const char *interface,
const char *property,
void *userdata) {
uint64_t u;
int r;
assert(s);
r = session_get_idle_hint(s, &t);
if (r < 0)
return r;
}
int r;
assert(s);
r = session_stop(s);
if (r < 0)
}
int r;
assert(s);
r = session_activate(s);
if (r < 0)
}
int r;
assert(s);
if (r < 0)
}
int r, b;
assert(s);
if (r < 0)
if (r < 0)
return sd_bus_reply_method_errorf(bus, message, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session my set idle hint");
session_set_idle_hint(s, b);
}
const char *swho;
int r;
assert(s);
if (r < 0)
else {
if (who < 0)
return sd_bus_reply_method_errorf(bus, message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
}
return sd_bus_reply_method_errorf(bus, message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
if (r < 0)
}
int r, force;
assert(s);
if (r < 0)
if (r < 0)
return sd_bus_reply_method_errorf(bus, message, SD_BUS_ERROR_ACCESS_DENIED, "Only owner of session may take control");
if (r < 0)
}
assert(s);
return sd_bus_reply_method_errorf(bus, message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
}
int r;
assert(s);
if (r < 0)
return sd_bus_reply_method_errorf(bus, message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
if (sd)
/* We don't allow retrieving a device multiple times.
* The related ReleaseDevice call is not ref-counted.
* The caller should use dup() if it requires more
* than one fd (it would be functionally
* equivalent). */
if (r < 0)
if (r < 0)
return r;
}
int r;
assert(s);
if (r < 0)
return sd_bus_reply_method_errorf(bus, message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
if (!sd)
}
int r;
assert(s);
if (r < 0)
return sd_bus_reply_method_errorf(bus, message, BUS_ERROR_NOT_IN_CONTROL, "You are not in control of this session");
if (!sd)
}
const sd_bus_vtable session_vtable[] = {
SD_BUS_PROPERTY("IdleSinceHint", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("IdleSinceHintMonotonic", "t", property_get_idle_since_hint, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
};
int session_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
_cleanup_free_ char *e = NULL;
const char *p;
assert(m);
if (!p)
return 0;
e = bus_path_unescape(p);
if (!e)
return -ENOMEM;
if (!session)
return 0;
return 1;
}
char *session_bus_path(Session *s) {
_cleanup_free_ char *t = NULL;
assert(s);
t = bus_path_escape(s->id);
if (!t)
return NULL;
return strappend("/org/freedesktop/login1/session/", t);
}
_cleanup_strv_free_ char **l = NULL;
Iterator i;
int r;
char *p;
p = session_bus_path(session);
if (!p)
return -ENOMEM;
r = strv_push(&l, p);
if (r < 0) {
free(p);
return r;
}
}
*nodes = l;
l = NULL;
return 1;
}
_cleanup_free_ char *p = NULL;
assert(s);
p = session_bus_path(s);
if (!p)
return -ENOMEM;
return sd_bus_emit_signal(
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"so", s->id, p);
}
_cleanup_free_ char *p = NULL;
char **l;
assert(s);
if (!s->started)
return 0;
p = session_bus_path(s);
if (!p)
return -ENOMEM;
return sd_bus_emit_properties_changed_strv(s->manager->bus, p, "org.freedesktop.login1.Session", l);
}
_cleanup_free_ char *p = NULL;
assert(s);
p = session_bus_path(s);
if (!p)
return -ENOMEM;
return sd_bus_emit_signal(
p,
"org.freedesktop.login1.Session",
NULL);
}
Iterator i;
int r = 0;
assert(m);
int k;
if (k < 0)
r = k;
}
return r;
}
_cleanup_free_ char *p = NULL;
assert(s);
/* This is called after the session scope was successfully
* created, and finishes where bus_manager_create_session()
* left off. */
if (!s->create_message)
return 0;
c = s->create_message;
s->create_message = NULL;
if (error)
/* Update the session state file before we notify the client
* about the result. */
session_save(s);
fifo_fd = session_create_fifo(s);
if (fifo_fd < 0)
return fifo_fd;
p = session_bus_path(s);
if (!p)
return -ENOMEM;
return sd_bus_reply_method_return(
"soshsub",
s->id,
p,
s->user->runtime_path,
false);
}