logind-dbus.c revision 92bd5ff3a062c3f9475b9d9d39b9335bfeb7705e
/*-*- 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 <unistd.h>
#include <pwd.h>
#include "sd-id128.h"
#include "sd-messages.h"
#include "strv.h"
#include "mkdir.h"
#include "path-util.h"
#include "special.h"
#include "sleep-config.h"
#include "fileio-label.h"
#include "label.h"
#include "utf8.h"
#include "unit-name.h"
#include "virt.h"
#include "audit.h"
#include "bus-util.h"
#include "bus-error.h"
#include "logind.h"
#include "bus-errors.h"
static int property_get_idle_hint(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
assert(m);
}
static int property_get_idle_since_hint(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
assert(m);
manager_get_idle_hint(m, &t);
return sd_bus_message_append(reply, "t", streq(property, "IdleSinceHint") ? t.realtime : t.monotonic);
}
static int property_get_inhibited(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
InhibitWhat w;
assert(m);
}
static int property_get_preparing(
const char *path,
const char *interface,
const char *property,
void *userdata,
sd_bus_error *error) {
bool b;
assert(m);
b = !!(m->action_what & INHIBIT_SHUTDOWN);
else
b = !!(m->action_what & INHIBIT_SLEEP);
}
static int method_get_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
const char *name;
int r;
assert(m);
if (r < 0)
return r;
if (!session)
p = session_bus_path(session);
if (!p)
return -ENOMEM;
}
static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
int r;
assert(m);
if (r < 0)
return r;
if (pid == 0) {
if (r < 0)
return r;
}
if (r < 0)
return r;
if (!session)
return sd_bus_error_setf(error, BUS_ERROR_NO_SESSION_FOR_PID, "PID %lu does not belong to any known session", (unsigned long) pid);
p = session_bus_path(session);
if (!p)
return -ENOMEM;
}
static int method_get_user(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
int r;
assert(m);
if (r < 0)
return r;
if (!user)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
p = user_bus_path(user);
if (!p)
return -ENOMEM;
}
static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
int r;
assert(m);
if (r < 0)
return r;
if (pid == 0) {
if (r < 0)
return r;
}
if (r < 0)
return r;
if (!user)
return sd_bus_error_setf(error, BUS_ERROR_NO_USER_FOR_PID, "PID %lu does not belong to any known or logged in user", (unsigned long) pid);
p = user_bus_path(user);
if (!p)
return -ENOMEM;
}
static int method_get_seat(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_free_ char *p = NULL;
const char *name;
int r;
assert(m);
if (r < 0)
return r;
if (!seat)
p = seat_bus_path(seat);
if (!p)
return -ENOMEM;
}
static int method_list_sessions(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Iterator i;
int r;
assert(m);
if (r < 0)
return r;
if (r < 0)
return r;
_cleanup_free_ char *p = NULL;
p = session_bus_path(session);
if (!p)
return -ENOMEM;
p);
if (r < 0)
return r;
}
if (r < 0)
return r;
}
static int method_list_users(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Iterator i;
int r;
assert(m);
if (r < 0)
return r;
if (r < 0)
return r;
_cleanup_free_ char *p = NULL;
p = user_bus_path(user);
if (!p)
return -ENOMEM;
p);
if (r < 0)
return r;
}
if (r < 0)
return r;
}
static int method_list_seats(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Iterator i;
int r;
assert(m);
if (r < 0)
return r;
if (r < 0)
return r;
_cleanup_free_ char *p = NULL;
p = seat_bus_path(seat);
if (!p)
return -ENOMEM;
if (r < 0)
return r;
}
if (r < 0)
return r;
}
static int method_list_inhibitors(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Iterator i;
int r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
}
if (r < 0)
return r;
}
static int method_create_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int remote;
SessionType t;
SessionClass c;
int r;
assert(m);
r = sd_bus_message_read(message, "uussssussbss", &uid, &leader, &service, &type, &class, &cseat, &vtnr, &tty, &display, &remote, &remote_user, &remote_host);
if (r < 0)
return r;
if (leader == 1)
else {
t = session_type_from_string(type);
if (t < 0)
}
else {
if (c < 0)
}
else {
if (!seat)
}
int v;
if (!seat)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "TTY %s is virtual console but seat %s is not seat0", tty, seat);
v = vtnr_from_tty(tty);
if (v <= 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Cannot determine VT number from virtual console TTY %s", tty);
if (!vtnr)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Specified TTY and VT number do not match");
} else if (tty_is_console(tty)) {
if (!seat)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Console TTY specified but seat is not seat0");
if (vtnr != 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Console TTY specified but VT number is not 0");
}
if (seat) {
if (seat_has_vts(seat)) {
if (vtnr > 63)
} else {
if (vtnr != 0)
}
}
if (r < 0)
return r;
if (t == _SESSION_TYPE_INVALID) {
t = SESSION_X11;
t = SESSION_TTY;
else
t = SESSION_UNSPECIFIED;
}
if (c == _SESSION_CLASS_INVALID) {
c = SESSION_USER;
else
c = SESSION_BACKGROUND;
}
if (leader <= 0) {
if (r < 0)
return r;
}
if (session) {
/* Session already exists, client is probably
* something like "su" which changes uid but is still
* the same session */
if (fifo_fd < 0)
return fifo_fd;
if (!path)
return -ENOMEM;
return sd_bus_reply_method_return(
message, "soshusub",
path,
true);
}
if (audit_id > 0) {
/* Keep our session IDs and the audit session IDs in sync */
return -ENOMEM;
/* Wut? There's already a session by this name and we
* didn't find it above? Weird, then let's not trust
* the audit data and let's better register a new
* ID */
audit_id = 0;
}
}
if (!id) {
do {
return -ENOMEM;
}
if (r < 0)
goto fail;
if (r < 0)
goto fail;
r = -ENOMEM;
goto fail;
}
}
r = -ENOMEM;
goto fail;
}
}
if (!isempty(remote_user)) {
if (!session->remote_user) {
r = -ENOMEM;
goto fail;
}
}
if (!isempty(remote_host)) {
if (!session->remote_host) {
r = -ENOMEM;
goto fail;
}
}
r = -ENOMEM;
goto fail;
}
}
if (seat) {
if (r < 0)
goto fail;
}
r = session_start(session);
if (r < 0)
goto fail;
/* Now, let's wait until the slice unit and stuff got
* created. We send the reply back from
* session_send_create_reply().*/
return 1;
fail:
if (session)
if (user)
return r;
}
static int method_release_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name;
int r;
assert(m);
if (r < 0)
return r;
if (!session)
/* We use the FIFO to detect stray sessions where the process
invoking PAM dies abnormally. We need to make sure that
that process is not killed if at the clean end of the
session it closes the FIFO. Hence, with this call
explicitly turn off the FIFO logic, so that the PAM code
can finish clean up on its own */
}
static int method_activate_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name;
int r;
assert(m);
if (r < 0)
return r;
if (!session)
r = session_activate(session);
if (r < 0)
return r;
}
static int method_activate_session_on_seat(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *session_name, *seat_name;
int r;
assert(m);
/* Same as ActivateSession() but refuses to work if
* the seat doesn't match */
if (r < 0)
return r;
if (!session)
if (!seat)
return sd_bus_error_setf(error, BUS_ERROR_SESSION_NOT_ON_SEAT, "Session %s not on seat %s", session_name, seat_name);
r = session_activate(session);
if (r < 0)
return r;
}
static int method_lock_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name;
int r;
assert(m);
if (r < 0)
return r;
if (!session)
if (r < 0)
return r;
}
static int method_lock_sessions(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int r;
assert(m);
if (r < 0)
return r;
}
static int method_kill_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int r;
assert(m);
if (r < 0)
return r;
else {
if (who < 0)
}
if (!session)
if (r < 0)
return r;
}
static int method_kill_user(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int r;
assert(m);
if (r < 0)
return r;
if (!user)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
if (r < 0)
return r;
}
static int method_terminate_session(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name;
int r;
assert(m);
if (r < 0)
return r;
if (!session)
r = session_stop(session);
if (r < 0)
return r;
}
static int method_terminate_user(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int r;
assert(m);
if (r < 0)
return r;
if (!user)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
if (r < 0)
return r;
}
static int method_terminate_seat(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *name;
int r;
assert(m);
if (r < 0)
return r;
if (!seat)
r = seat_stop_sessions(seat);
if (r < 0)
return r;
}
static int method_set_user_linger(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int b, r;
const char *path;
int interactive;
assert(m);
if (r < 0)
return r;
errno = 0;
if (!pw)
&m->polkit_registry,
"org.freedesktop.login1.set-user-linger",
if (r < 0)
return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
if (r < 0)
return r;
if (!cc)
return -ENOMEM;
if (b) {
User *u;
if (r < 0)
return r;
if (manager_add_user_by_uid(m, uid, &u) >= 0)
user_start(u);
} else {
User *u;
return -errno;
if (u)
}
}
struct udev_enumerate *e;
int r;
assert(m);
e = udev_enumerate_new(m->udev);
if (!e) {
r = -ENOMEM;
goto finish;
}
if (d) {
if (udev_enumerate_add_match_parent(e, d) < 0) {
r = -EIO;
goto finish;
}
}
if (udev_enumerate_scan_devices(e) < 0) {
r = -EIO;
goto finish;
}
_cleanup_free_ char *t = NULL;
const char *p;
p = udev_list_entry_get_name(item);
t = strappend(p, "/uevent");
if (!t) {
r = -ENOMEM;
goto finish;
}
write_string_file(t, "change");
}
r = 0;
if (e)
return r;
}
const char *id_for_seat;
struct udev_device *d;
int r;
assert(m);
if (!d)
return -ENODEV;
if (!udev_device_has_tag(d, "seat")) {
r = -ENODEV;
goto finish;
}
if (!id_for_seat) {
r = -ENODEV;
goto finish;
}
r = -ENOMEM;
goto finish;
}
if (asprintf(&rule, "TAG==\"seat\", ENV{ID_FOR_SEAT}==\"%s\", ENV{ID_SEAT}=\"%s\"", id_for_seat, seat) < 0) {
r = -ENOMEM;
goto finish;
}
label_init("/etc");
if (r < 0)
goto finish;
r = trigger_device(m, d);
if (d)
return r;
}
static int flush_devices(Manager *m) {
assert(m);
if (!d) {
log_warning("Failed to open /etc/udev/rules.d: %m");
} else {
if (!dirent_is_file(de))
continue;
continue;
continue;
}
}
return trigger_device(m, NULL);
}
static int method_attach_device(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int interactive, r;
assert(m);
if (r < 0)
return r;
if (!seat_name_is_valid(seat))
&m->polkit_registry,
"org.freedesktop.login1.attach-device",
method_attach_device, m);
if (r < 0)
return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
if (r < 0)
return r;
}
static int method_flush_devices(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
int interactive, r;
assert(m);
if (r < 0)
return r;
&m->polkit_registry,
"org.freedesktop.login1.flush-devices",
method_flush_devices, m);
if (r < 0)
return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
r = flush_devices(m);
if (r < 0)
return r;
}
static int have_multiple_sessions(
Manager *m,
Iterator i;
assert(m);
/* Check for other users' sessions. Greeter sessions do not
* count, and non-login sessions do not count either. */
return true;
return false;
}
static int bus_manager_log_shutdown(
Manager *m,
InhibitWhat w,
const char *unit_name) {
const char *p, *q;
assert(m);
if (w != INHIBIT_SHUTDOWN)
return 0;
p = "MESSAGE=System is powering down.";
q = "SHUTDOWN=power-off";
p = "MESSAGE=System is halting.";
q = "SHUTDOWN=halt";
p = "MESSAGE=System is rebooting.";
q = "SHUTDOWN=reboot";
p = "MESSAGE=System is rebooting with kexec.";
q = "SHUTDOWN=kexec";
} else {
p = "MESSAGE=System is shutting down.";
q = NULL;
}
p,
q, NULL);
}
static int execute_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
const char *unit_name,
sd_bus_error *error) {
const char *p;
char *c;
int r;
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
bus_manager_log_shutdown(m, w, unit_name);
r = sd_bus_call_method(
m->bus,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit",
&reply,
if (r < 0)
return r;
if (r < 0)
return r;
c = strdup(p);
if (!c)
return -ENOMEM;
m->action_unit = unit_name;
free(m->action_job);
m->action_job = c;
m->action_what = w;
return 0;
}
static int delay_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
const char *unit_name) {
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
m->action_unit = unit_name;
m->action_what = w;
return 0;
}
static const char * const signal_name[_INHIBIT_WHAT_MAX] = {
[INHIBIT_SHUTDOWN] = "PrepareForShutdown",
[INHIBIT_SLEEP] = "PrepareForSleep"
};
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
assert(signal_name[w]);
return sd_bus_emit_signal(m->bus,
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
signal_name[w],
"b",
active);
}
Manager *m,
const char *unit_name,
InhibitWhat w,
sd_bus_error *error) {
bool delayed;
int r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
assert(!m->action_job);
send_prepare_for(m, w, true);
delayed =
m->inhibit_delay_max > 0 &&
if (delayed)
/* Shutdown is delayed, keep in mind what we
* want to do, and start a timeout */
r = delay_shutdown_or_sleep(m, w, unit_name);
else
/* Shutdown is not delayed, execute it
* immediately */
return r;
}
static int method_do_shutdown_or_sleep(
Manager *m,
const char *unit_name,
InhibitWhat w,
const char *action,
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
const char *sleep_verb,
sd_bus_error *error) {
bool multiple_sessions, blocked;
int interactive, r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
if (r < 0)
return r;
/* Don't allow multiple jobs being executed at the same time */
if (m->action_what)
return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, "There's already a shutdown or sleep operation in progress");
if (sleep_verb) {
r = can_sleep(sleep_verb);
if (r < 0)
return r;
if (r == 0)
}
if (r < 0)
return r;
r = have_multiple_sessions(m, uid);
if (r < 0)
return r;
multiple_sessions = r > 0;
if (multiple_sessions) {
if (r < 0)
return r;
}
if (blocked) {
if (r < 0)
return r;
}
if (!multiple_sessions && !blocked) {
if (r < 0)
return r;
}
if (r < 0)
return r;
}
static int method_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_do_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
NULL,
error);
}
static int method_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_do_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
NULL,
error);
}
static int method_suspend(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_do_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
"suspend",
error);
}
static int method_hibernate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_do_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"hibernate",
error);
}
static int method_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_do_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"hybrid-sleep",
error);
}
static int method_can_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
const char *action,
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
const char *sleep_verb,
sd_bus_error *error) {
int r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
if (sleep_verb) {
r = can_sleep(sleep_verb);
if (r < 0)
return r;
if (r == 0)
}
if (r < 0)
return r;
r = have_multiple_sessions(m, uid);
if (r < 0)
return r;
multiple_sessions = r > 0;
if (multiple_sessions) {
if (r < 0)
return r;
if (r > 0)
result = "yes";
else if (challenge)
result = "challenge";
else
result = "no";
}
if (blocked) {
if (r < 0)
return r;
if (r > 0 && !result)
result = "yes";
result = "challenge";
else
result = "no";
}
if (!multiple_sessions && !blocked) {
/* If neither inhibit nor multiple sessions
* apply then just check the normal policy */
if (r < 0)
return r;
if (r > 0)
result = "yes";
else if (challenge)
result = "challenge";
else
result = "no";
}
}
static int method_can_poweroff(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_can_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
NULL,
error);
}
static int method_can_reboot(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_can_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
NULL,
error);
}
static int method_can_suspend(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_can_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
"suspend",
error);
}
static int method_can_hibernate(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_can_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"hibernate",
error);
}
static int method_can_hybrid_sleep(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
return method_can_shutdown_or_sleep(
m, message,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
"hybrid-sleep",
error);
}
static int method_inhibit(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
InhibitWhat w;
int r;
assert(m);
if (r < 0)
return r;
w = inhibit_what_from_string(what);
if (w <= 0)
if (mm < 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Delay inhibitors only supported for shutdown and sleep");
/* Don't allow taking delay locks while we are already
* executing the operation. We shouldn't create the impression
* that the lock was successful if the machine is about to go
if (m->action_what & w)
return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS, "The operation inhibition has been requested for is already running");
w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") :
w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") :
w == INHIBIT_IDLE ? "org.freedesktop.login1.inhibit-block-idle" :
w == INHIBIT_HANDLE_POWER_KEY ? "org.freedesktop.login1.inhibit-handle-power-key" :
w == INHIBIT_HANDLE_SUSPEND_KEY ? "org.freedesktop.login1.inhibit-handle-suspend-key" :
w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" :
"org.freedesktop.login1.inhibit-handle-lid-switch",
false, error, method_inhibit, m);
if (r < 0)
return r;
if (r == 0)
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
if (r < 0)
return r;
if (r < 0)
return r;
do {
return -ENOMEM;
r = manager_add_inhibitor(m, id, &i);
if (r < 0)
return r;
i->what = w;
r = -ENOMEM;
goto fail;
}
fifo_fd = inhibitor_create_fifo(i);
if (fifo_fd < 0) {
r = fifo_fd;
goto fail;
}
inhibitor_start(i);
fail:
if (i)
inhibitor_free(i);
return r;
}
const sd_bus_vtable manager_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),
SD_BUS_PROPERTY("BlockInhibited", "s", property_get_inhibited, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("DelayInhibited", "s", property_get_inhibited, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("HandlePowerKey", "s", property_get_handle_action, offsetof(Manager, handle_power_key), 0),
SD_BUS_PROPERTY("HandleSuspendKey", "s", property_get_handle_action, offsetof(Manager, handle_suspend_key), 0),
SD_BUS_PROPERTY("HandleHibernateKey", "s", property_get_handle_action, offsetof(Manager, handle_hibernate_key), 0),
SD_BUS_PROPERTY("HandleLidSwitch", "s", property_get_handle_action, offsetof(Manager, handle_lid_switch), 0),
};
int r;
assert(m);
if (r < 0) {
return r;
}
log_info("Operation finished.");
/* Tell people that they now may take a lock again */
send_prepare_for(m, m->action_what, false);
free(m->action_job);
m->action_job = NULL;
m->action_unit = NULL;
m->action_what = 0;
return 0;
}
if (session) {
}
else {
sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
}
} else
}
if (user) {
}
}
}
return 0;
}
int r;
assert(m);
if (r < 0) {
return r;
}
if (session)
if (user)
return 0;
}
int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
const char *path;
int r;
assert(m);
if (!path)
return 0;
if (r < 0)
return r;
if (session)
if (user)
return 0;
}
Iterator i;
int b, r;
if (r < 0) {
return r;
}
if (b)
return 0;
/* systemd finished reloading, let's recheck all our sessions */
log_debug("System manager has been reloaded, rechecking sessions...");
return 0;
}
int match_name_owner_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
Iterator i;
int r;
char *key;
if (r < 0) {
return r;
}
return 0;
if (!key)
return 0;
/* Drop all controllers owned by this name */
return 0;
}
char **l;
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
l);
}
int r;
return 0;
/* Continue delay? */
if (manager_is_inhibited(manager, manager->action_what, INHIBIT_DELAY, NULL, false, false, 0, &offending)) {
return 0;
log_info("Delay lock is active (UID %lu/%s, PID %lu/%s) but inhibitor timeout is reached.",
}
/* Actually do the operation */
if (r < 0) {
manager->action_what = 0;
return r;
}
return 1;
}
int manager_start_scope(
const char *scope,
const char *slice,
const char *description,
const char *after,
const char *kill_mode,
char **job) {
int r;
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartTransientUnit",
&m);
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
if (r < 0)
return r;
}
if (!isempty(description)) {
if (r < 0)
return r;
}
if (!isempty(description)) {
if (r < 0)
return r;
}
if (r < 0)
return r;
}
/* cgroup empty notification is not available in containers
* currently. To make this less problematic, let's shorten the
* stop timeout for sessions, so that we don't wait
* forever. */
if (r < 0)
return r;
/* Make sure that the session shells are terminated with
* SIGHUP since bash and friends tend to ignore SIGTERM */
if (r < 0)
return r;
if (r < 0)
return r;
r = sd_bus_message_close_container(m);
if (r < 0)
return r;
r = sd_bus_message_append(m, "a(sa(sv))", 0);
if (r < 0)
return r;
if (r < 0)
return r;
if (job) {
const char *j;
char *copy;
if (r < 0)
return r;
if (!copy)
return -ENOMEM;
}
return 1;
}
int r;
r = sd_bus_call_method(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StartUnit",
&reply,
if (r < 0)
return r;
if (job) {
const char *j;
char *copy;
if (r < 0)
return r;
if (!copy)
return -ENOMEM;
}
return 1;
}
int r;
r = sd_bus_call_method(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"StopUnit",
&reply,
if (r < 0) {
if (job)
return 0;
}
return r;
}
if (job) {
const char *j;
char *copy;
if (r < 0)
return r;
if (!copy)
return -ENOMEM;
}
return 1;
}
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error) {
return sd_bus_call_method(
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"KillUnit",
NULL,
}
const char *state;
int r;
if (!path)
return -ENOMEM;
r = sd_bus_get_property(
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Unit",
"ActiveState",
&error,
&reply,
"s");
if (r < 0) {
/* systemd might have droppped off momentarily, let's
* not make this an error */
return true;
/* If the unit is already unloaded then it's not
* active */
return false;
return r;
}
if (r < 0)
return -EINVAL;
}
int r;
r = sd_bus_get_property(
"org.freedesktop.systemd1",
path,
"org.freedesktop.systemd1.Job",
"State",
&error,
&reply,
"s");
if (r < 0) {
return true;
return false;
return r;
}
/* We don't actually care about the state really. The fact
* that we could read the job state is enough for us */
return true;
}