logind-dbus.c revision df2d202e6ed4001a21c6512c244acad5d4706c87
/*-*- 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) {
assert(m);
}
static int property_get_idle_since_hint(
const char *path,
const char *interface,
const char *property,
void *userdata) {
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) {
InhibitWhat w;
assert(m);
}
static int property_get_preparing(
const char *path,
const char *interface,
const char *property,
void *userdata) {
bool b;
assert(m);
b = !!(m->action_what & INHIBIT_SHUTDOWN);
else
b = !!(m->action_what & INHIBIT_SLEEP);
}
_cleanup_free_ char *p = NULL;
const char *name;
int r;
assert(m);
if (r < 0)
if (!session)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
p = session_bus_path(session);
if (!p)
}
_cleanup_free_ char *p = NULL;
int r;
assert(m);
if (r < 0)
if (pid == 0) {
if (r < 0)
}
if (r < 0)
if (!session)
return sd_bus_reply_method_errorf(message, 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)
}
_cleanup_free_ char *p = NULL;
int r;
assert(m);
if (r < 0)
if (!user)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
p = user_bus_path(user);
if (!p)
}
_cleanup_free_ char *p = NULL;
int r;
assert(m);
if (r < 0)
if (pid == 0) {
if (r < 0)
}
if (r < 0)
if (!user)
return sd_bus_reply_method_errorf(message, 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)
}
_cleanup_free_ char *p = NULL;
const char *name;
int r;
assert(m);
if (r < 0)
if (!seat)
p = seat_bus_path(seat);
if (!p)
}
Iterator i;
int r;
assert(m);
if (r < 0)
if (r < 0)
_cleanup_free_ char *p = NULL;
p = session_bus_path(session);
if (!p)
p);
if (r < 0)
}
if (r < 0)
}
Iterator i;
int r;
assert(m);
if (r < 0)
if (r < 0)
_cleanup_free_ char *p = NULL;
p = user_bus_path(user);
if (!p)
p);
if (r < 0)
}
if (r < 0)
}
Iterator i;
int r;
assert(m);
if (r < 0)
if (r < 0)
_cleanup_free_ char *p = NULL;
p = seat_bus_path(seat);
if (!p)
if (r < 0)
}
if (r < 0)
}
Iterator i;
int r;
if (r < 0)
if (r < 0)
if (r < 0)
}
if (r < 0)
}
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)
if (leader == 1)
else {
t = session_type_from_string(type);
if (t < 0)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid session type %s", type);
}
else {
if (c < 0)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid session class %s", class);
}
else {
if (!seat)
}
int v;
if (!seat)
return sd_bus_reply_method_errorf(message, 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_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Cannot determine VT number from virtual console TTY %s", tty);
if (vtnr <= 0)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Specified TTY and VT number do not match");
} else if (tty_is_console(tty)) {
if (!seat)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Console TTY specified but seat is not seat0");
if (vtnr != 0)
return sd_bus_reply_method_errorf(message, 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)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Seat has no VTs but VT number not 0");
}
}
if (r < 0)
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)
}
if (session) {
/* Session already exists, client is probably
* something like "su" which changes uid but is still
* the same session */
if (fifo_fd < 0)
if (!path)
return sd_bus_reply_method_return(
message, "soshsub",
path,
true);
}
if (audit_id > 0) {
/* Keep our session IDs and the audit session IDs in sync */
/* 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 {
}
if (r < 0) {
goto fail;
}
if (r < 0) {
goto fail;
}
goto fail;
}
}
goto fail;
}
}
if (!isempty(remote_user)) {
if (!session->remote_user) {
goto fail;
}
}
if (!isempty(remote_host)) {
if (!session->remote_host) {
goto fail;
}
}
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;
}
const char *name;
int r;
assert(m);
if (r < 0)
if (!session)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
/* 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 */
}
const char *name;
int r;
assert(m);
if (r < 0)
if (!session)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
r = session_activate(session);
if (r < 0)
}
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)
if (!session)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", session_name);
if (!seat)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", seat_name);
return sd_bus_reply_method_errorf(message, BUS_ERROR_SESSION_NOT_ON_SEAT, "Session %s not on seat %s", session_name, seat_name);
r = session_activate(session);
if (r < 0)
}
const char *name;
int r;
assert(m);
if (r < 0)
if (!session)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
if (r < 0)
}
int r;
assert(m);
if (r < 0)
}
int r;
assert(m);
if (r < 0)
else {
if (who < 0)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
}
if (!session)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
if (r < 0)
}
int r;
assert(m);
if (r < 0)
if (!user)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
if (r < 0)
}
const char *name;
int r;
assert(m);
if (r < 0)
if (!session)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
r = session_stop(session);
if (r < 0)
}
int r;
assert(m);
if (r < 0)
if (!user)
return sd_bus_reply_method_errorf(message, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
if (r < 0)
}
const char *name;
int r;
assert(m);
if (r < 0)
if (!seat)
r = seat_stop_sessions(seat);
if (r < 0)
}
int b, r;
const char *path;
int interactive;
assert(m);
if (r < 0)
errno = 0;
if (!pw)
&m->polkit_registry,
"org.freedesktop.login1.set-user-linger",
&error,
if (r < 0)
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)
if (!cc)
if (b) {
User *u;
if (r < 0)
if (manager_add_user_by_uid(m, uid, &u) >= 0)
user_start(u);
} else {
User *u;
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);
}
int interactive, r;
assert(m);
if (r < 0)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Path %s is not in /sys", sysfs);
if (!seat_name_is_valid(seat))
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Seat %s is not valid", seat);
&m->polkit_registry,
"org.freedesktop.login1.attach-device",
&error,
method_attach_device, m);
if (r < 0)
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)
}
int interactive, r;
assert(m);
if (r < 0)
&m->polkit_registry,
"org.freedesktop.login1.flush-devices",
&error,
method_flush_devices, m);
if (r < 0)
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)
}
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,
bool multiple_sessions, blocked;
int interactive, r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
if (r < 0)
/* Don't allow multiple jobs being executed at the same time */
if (m->action_what)
return sd_bus_reply_method_errorf(message, 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)
if (r == 0)
return sd_bus_reply_method_errorf(message, BUS_ERROR_SLEEP_VERB_NOT_SUPPORTED, "Sleep verb not supported");
}
if (r < 0)
r = have_multiple_sessions(m, uid);
if (r < 0)
multiple_sessions = r > 0;
if (multiple_sessions) {
if (r < 0)
}
if (blocked) {
if (r < 0)
}
if (!multiple_sessions && !blocked) {
if (r < 0)
}
if (r < 0)
}
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,
}
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,
}
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",
}
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",
}
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",
}
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) {
int r;
assert(m);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
if (sleep_verb) {
r = can_sleep(sleep_verb);
if (r < 0)
if (r == 0)
}
if (r < 0)
r = have_multiple_sessions(m, uid);
if (r < 0)
multiple_sessions = r > 0;
if (multiple_sessions) {
if (r < 0)
if (r > 0)
result = "yes";
else if (challenge)
result = "challenge";
else
result = "no";
}
if (blocked) {
if (r < 0)
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)
if (r > 0)
result = "yes";
else if (challenge)
result = "challenge";
else
result = "no";
}
}
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);
}
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);
}
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");
}
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");
}
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");
}
InhibitWhat w;
int r;
assert(m);
if (r < 0)
w = inhibit_what_from_string(what);
if (w <= 0)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid what specification %s", what);
if (mm < 0)
return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid mode specification %s", mode);
return sd_bus_reply_method_errorf(message, 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_reply_method_errorf(message, 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)
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)
if (r < 0)
do {
r = manager_add_inhibitor(m, id, &i);
if (r < 0)
i->what = w;
goto fail;
}
fifo_fd = inhibitor_create_fifo(i);
if (fifo_fd < 0) {
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 0;
}
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(&error, 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 0;
}
if (session)
if (user)
return 0;
}
const char *path;
assert(m);
if (!path)
return 0;
if (!unit)
return 0;
if (session)
if (user)
return 0;
}
Iterator i;
int b, r;
if (r < 0) {
return 0;
}
if (b)
return 0;
/* systemd finished reloading, let's recheck all our sessions */
log_debug("System manager has been reloaded, rechecking sessions...");
return 0;
}
Iterator i;
int r;
char *key;
if (r < 0) {
return 0;
}
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? */
return 0;
log_info("Delay lock is active 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;
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;
}