Since we are catching the keys, we might as well just do
suspend/reboot/etc handling here.
session->create_message = sd_bus_message_ref(message);
session->create_message = sd_bus_message_ref(message);
- /* Now, let's wait until the slice unit and stuff got
- * created. We send the reply back from
- * session_send_create_reply(). */
-
- /* Elogind note: replying directly, since we're not actually
- starting slices and thus we aren't waiting on systemd. */
+ /* Here upstream systemd starts cgroups and the user systemd,
+ and arranges to reply asynchronously. We reply
+ directly. */
r = session_send_create_reply(session, NULL);
if (r < 0)
r = session_send_create_reply(session, NULL);
if (r < 0)
static int bus_manager_log_shutdown(
Manager *m,
InhibitWhat w,
static int bus_manager_log_shutdown(
Manager *m,
InhibitWhat w,
- const char *unit_name) {
const char *p, *q;
assert(m);
const char *p, *q;
assert(m);
if (w != INHIBIT_SHUTDOWN)
return 0;
if (w != INHIBIT_SHUTDOWN)
return 0;
- if (streq(unit_name, SPECIAL_POWEROFF_TARGET)) {
+ switch (action) {
+ case HANDLE_POWEROFF:
p = "MESSAGE=System is powering down.";
q = "SHUTDOWN=power-off";
p = "MESSAGE=System is powering down.";
q = "SHUTDOWN=power-off";
- } else if (streq(unit_name, SPECIAL_HALT_TARGET)) {
+ break;
+ case HANDLE_HALT:
p = "MESSAGE=System is halting.";
q = "SHUTDOWN=halt";
p = "MESSAGE=System is halting.";
q = "SHUTDOWN=halt";
- } else if (streq(unit_name, SPECIAL_REBOOT_TARGET)) {
+ break;
+ case HANDLE_REBOOT:
p = "MESSAGE=System is rebooting.";
q = "SHUTDOWN=reboot";
p = "MESSAGE=System is rebooting.";
q = "SHUTDOWN=reboot";
- } else if (streq(unit_name, SPECIAL_KEXEC_TARGET)) {
+ break;
+ case HANDLE_KEXEC:
p = "MESSAGE=System is rebooting with kexec.";
q = "SHUTDOWN=kexec";
p = "MESSAGE=System is rebooting with kexec.";
q = "SHUTDOWN=kexec";
p = "MESSAGE=System is shutting down.";
q = NULL;
p = "MESSAGE=System is shutting down.";
q = NULL;
}
return log_struct(LOG_NOTICE,
}
return log_struct(LOG_NOTICE,
static int execute_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
static int execute_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
sd_bus_error *error) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
- bus_manager_log_shutdown(m, w, unit_name);
+ bus_manager_log_shutdown(m, w, action);
+
+ /* FIXME: here do the thing. */
r = sd_bus_call_method(
m->bus,
r = sd_bus_call_method(
m->bus,
"StartUnit",
error,
&reply,
"StartUnit",
error,
&reply,
- "ss", unit_name, "replace-irreversibly");
+ "ss", NULL, "replace-irreversibly");
- m->action_unit = unit_name;
- free(m->action_job);
- m->action_job = c;
- m->action_what = w;
-
- /* Make sure the lid switch is ignored for a while */
+ /* Make sure the lid switch is ignored for a while (?) */
manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC) + m->holdoff_timeout_usec);
return 0;
manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC) + m->holdoff_timeout_usec);
return 0;
static int delay_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
static int delay_shutdown_or_sleep(
Manager *m,
InhibitWhat w,
- const char *unit_name) {
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
m->action_timestamp = now(CLOCK_MONOTONIC);
m->action_timestamp = now(CLOCK_MONOTONIC);
- m->action_unit = unit_name;
+ m->pending_action = action;
m->action_what = w;
return 0;
m->action_what = w;
return 0;
int bus_manager_shutdown_or_sleep_now_or_later(
Manager *m,
int bus_manager_shutdown_or_sleep_now_or_later(
Manager *m,
InhibitWhat w,
sd_bus_error *error) {
InhibitWhat w,
sd_bus_error *error) {
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
- assert(!m->action_job);
/* Tell everybody to prepare for shutdown/sleep */
send_prepare_for(m, w, true);
/* Tell everybody to prepare for shutdown/sleep */
send_prepare_for(m, w, true);
if (delayed)
/* Shutdown is delayed, keep in mind what we
* want to do, and start a timeout */
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);
+ r = delay_shutdown_or_sleep(m, w, action);
else
/* Shutdown is not delayed, execute it
* immediately */
else
/* Shutdown is not delayed, execute it
* immediately */
- r = execute_shutdown_or_sleep(m, w, unit_name, error);
+ r = execute_shutdown_or_sleep(m, w, action, error);
static int method_do_shutdown_or_sleep(
Manager *m,
sd_bus_message *message,
static int method_do_shutdown_or_sleep(
Manager *m,
sd_bus_message *message,
+ HandleAction sleep_action,
InhibitWhat w,
const char *action,
const char *action_multiple_sessions,
InhibitWhat w,
const char *action,
const char *action_multiple_sessions,
assert(m);
assert(message);
assert(m);
assert(message);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
assert(action);
assert(w >= 0);
assert(w <= _INHIBIT_WHAT_MAX);
assert(action);
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
}
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
}
- r = bus_manager_shutdown_or_sleep_now_or_later(m, unit_name, w, error);
+ r = bus_manager_shutdown_or_sleep_now_or_later(m, sleep_action, w, error);
return method_do_shutdown_or_sleep(
m, message,
return method_do_shutdown_or_sleep(
m, message,
- SPECIAL_POWEROFF_TARGET,
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
return method_do_shutdown_or_sleep(
m, message,
return method_do_shutdown_or_sleep(
m, message,
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
INHIBIT_SHUTDOWN,
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
return method_do_shutdown_or_sleep(
m, message,
return method_do_shutdown_or_sleep(
m, message,
- SPECIAL_SUSPEND_TARGET,
INHIBIT_SLEEP,
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
INHIBIT_SLEEP,
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
return method_do_shutdown_or_sleep(
m, message,
return method_do_shutdown_or_sleep(
m, message,
- SPECIAL_HIBERNATE_TARGET,
INHIBIT_SLEEP,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
INHIBIT_SLEEP,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
return method_do_shutdown_or_sleep(
m, message,
return method_do_shutdown_or_sleep(
m, message,
- SPECIAL_HYBRID_SLEEP_TARGET,
INHIBIT_SLEEP,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
INHIBIT_SLEEP,
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
-static int session_jobs_reply(Session *s, const char *unit, const char *result) {
- int r = 0;
-
- assert(s);
- assert(unit);
-
- if (!s->started)
- return r;
-
- if (streq(result, "done"))
- r = session_send_create_reply(s, NULL);
- else {
- _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
-
- sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
- r = session_send_create_reply(s, &e);
- }
-
- return r;
-}
-
int manager_send_changed(Manager *manager, const char *property, ...) {
char **l;
int manager_send_changed(Manager *manager, const char *property, ...) {
char **l;
- if (manager->action_what == 0 || manager->action_job)
+ if (manager->action_what == 0)
return 0;
/* Continue delay? */
return 0;
/* Continue delay? */
}
/* Actually do the operation */
}
/* Actually do the operation */
- r = execute_shutdown_or_sleep(manager, manager->action_what, manager->action_unit, &error);
+ r = execute_shutdown_or_sleep(manager, manager->action_what, manager->pending_action, &error);
if (r < 0) {
log_warning("Failed to send delayed message: %s", bus_error_message(&error, r));
if (r < 0) {
log_warning("Failed to send delayed message: %s", bus_error_message(&error, r));
- manager->action_unit = NULL;
+ manager->pending_action = HANDLE_IGNORE;
manager->action_what = 0;
return r;
}
manager->action_what = 0;
return r;
}
#include "bus-util.h"
#include "bus-error.h"
#include "udev-util.h"
#include "bus-util.h"
#include "bus-error.h"
#include "udev-util.h"
-#include "formats-util.h"
#include "signal-util.h"
#include "logind.h"
#include "signal-util.h"
#include "logind.h"
-static void manager_free(Manager *m);
-
-static Manager *manager_new(void) {
+Manager *manager_new(void) {
-static void manager_free(Manager *m) {
+void manager_free(Manager *m) {
Session *session;
User *u;
Device *d;
Session *session;
User *u;
Device *d;
set_free_free(m->busnames);
sd_event_source_unref(m->idle_action_event_source);
set_free_free(m->busnames);
sd_event_source_unref(m->idle_action_event_source);
- sd_event_source_unref(m->inhibit_timeout_source);
- sd_event_source_unref(m->scheduled_shutdown_timeout_source);
- sd_event_source_unref(m->nologin_timeout_source);
- sd_event_source_unref(m->wall_message_timeout_source);
sd_event_source_unref(m->console_active_event_source);
sd_event_source_unref(m->udev_seat_event_source);
sd_event_source_unref(m->console_active_event_source);
sd_event_source_unref(m->udev_seat_event_source);
if (m->udev)
udev_unref(m->udev);
if (m->udev)
udev_unref(m->udev);
- if (m->unlink_nologin)
- (void) unlink("/run/nologin");
-
bus_verify_polkit_async_registry_free(m->polkit_registry);
sd_bus_unref(m->bus);
bus_verify_polkit_async_registry_free(m->polkit_registry);
sd_bus_unref(m->bus);
strv_free(m->kill_only_users);
strv_free(m->kill_exclude_users);
strv_free(m->kill_only_users);
strv_free(m->kill_exclude_users);
- free(m->scheduled_shutdown_type);
- free(m->scheduled_shutdown_tty);
- free(m->wall_message);
- free(m->action_job);
-static void manager_gc(Manager *m, bool drop_not_started) {
+void manager_gc(Manager *m, bool drop_not_started) {
Seat *seat;
Session *session;
User *user;
Seat *seat;
Session *session;
User *user;
-static int manager_startup(Manager *m) {
+int manager_startup(Manager *m) {
int r;
Seat *seat;
Session *session;
int r;
Seat *seat;
Session *session;
-static int manager_run(Manager *m) {
+int manager_run(Manager *m) {
int r;
assert(m);
for (;;) {
int r;
assert(m);
for (;;) {
+ usec_t us = (uint64_t) -1;
+
r = sd_event_get_state(m->event);
if (r < 0)
return r;
r = sd_event_get_state(m->event);
if (r < 0)
return r;
- r = manager_dispatch_delayed(m, false);
- if (r < 0)
- return r;
- if (r > 0)
+ if (manager_dispatch_delayed(m) > 0)
- r = sd_event_run(m->event, (uint64_t) -1);
+ if (m->action_what != 0) {
+ usec_t x, y;
+
+ x = now(CLOCK_MONOTONIC);
+ y = m->action_timestamp + m->inhibit_delay_max;
+
+ us = x >= y ? 0 : y - x;
+ }
+
+ r = sd_event_run(m->event, us);
InhibitWhat action_what;
/* If a shutdown/suspend was delayed due to a inhibitor this
InhibitWhat action_what;
/* If a shutdown/suspend was delayed due to a inhibitor this
- contains the unit name we are supposed to start after the
+ contains the action we are supposed to perform after the
- const char *action_unit;
-
- /* If a shutdown/suspend is currently executed, then this is
- * the job of it */
- char *action_job;
+ HandleAction pending_action;
usec_t action_timestamp;
sd_event_source *idle_action_event_source;
usec_t action_timestamp;
sd_event_source *idle_action_event_source;
extern const sd_bus_vtable manager_vtable[];
extern const sd_bus_vtable manager_vtable[];
-int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, const char *unit_name, InhibitWhat w, sd_bus_error *error);
+int bus_manager_shutdown_or_sleep_now_or_later(Manager *m, HandleAction action, InhibitWhat w, sd_bus_error *error);
int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;
int manager_send_changed(Manager *manager, const char *property, ...) _sentinel_;