logind: allow users to override their own suspend/sleep inhibitors
This commit is contained in:
parent
68e9f6e6be
commit
409133be63
4
TODO
4
TODO
|
@ -19,6 +19,10 @@ F18:
|
|||
|
||||
Features:
|
||||
|
||||
* allow users from "wheel" to start/stop services
|
||||
|
||||
* systemctl: when powering down/suspending check for inhibitors, and warn.
|
||||
|
||||
* instantiated [Install] for target units
|
||||
https://bugs.freedesktop.org/show_bug.cgi?id=54377
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ static int button_handle(
|
|||
}
|
||||
|
||||
/* If the key handling is inhibited, don't do anything */
|
||||
if (manager_is_inhibited(b->manager, inhibit_key, INHIBIT_BLOCK, NULL, true)) {
|
||||
if (manager_is_inhibited(b->manager, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0)) {
|
||||
log_debug("Refusing key handling, %s is inhibited.", inhibit_what_to_string(inhibit_key));
|
||||
return 0;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ static int button_handle(
|
|||
|
||||
/* If the actual operation is inhibited, warn and fail */
|
||||
if (!ignore_inhibited &&
|
||||
manager_is_inhibited(b->manager, inhibit_operation, INHIBIT_BLOCK, NULL, false)) {
|
||||
manager_is_inhibited(b->manager, inhibit_operation, INHIBIT_BLOCK, NULL, false, false, 0)) {
|
||||
|
||||
|
||||
/* If this is just a recheck of the lid switch then don't warn about anything */
|
||||
|
|
|
@ -956,24 +956,17 @@ static int flush_devices(Manager *m) {
|
|||
}
|
||||
|
||||
static int have_multiple_sessions(
|
||||
DBusConnection *connection,
|
||||
Manager *m,
|
||||
DBusMessage *message,
|
||||
DBusError *error) {
|
||||
uid_t uid) {
|
||||
|
||||
Session *session;
|
||||
Iterator i;
|
||||
unsigned long ul;
|
||||
|
||||
assert(m);
|
||||
|
||||
ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
|
||||
if (ul == (unsigned long) -1)
|
||||
return -EIO;
|
||||
|
||||
/* Check for other users' sessions. Greeter sessions do not count. */
|
||||
HASHMAP_FOREACH(session, m->sessions, i)
|
||||
if (session->class == SESSION_USER && session->user->uid != ul)
|
||||
if (session->class == SESSION_USER && session->user->uid != uid)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -1060,6 +1053,7 @@ static int bus_manager_can_shutdown_or_sleep(
|
|||
const char *result;
|
||||
DBusMessage *reply = NULL;
|
||||
int r;
|
||||
unsigned long ul;
|
||||
|
||||
assert(m);
|
||||
assert(connection);
|
||||
|
@ -1083,12 +1077,16 @@ static int bus_manager_can_shutdown_or_sleep(
|
|||
}
|
||||
}
|
||||
|
||||
r = have_multiple_sessions(connection, m, message, error);
|
||||
ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
|
||||
if (ul == (unsigned long) -1)
|
||||
return -EIO;
|
||||
|
||||
r = have_multiple_sessions(m, (uid_t) ul);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
multiple_sessions = r > 0;
|
||||
blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false);
|
||||
blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, (uid_t) ul);
|
||||
|
||||
if (multiple_sessions) {
|
||||
r = verify_polkit(connection, message, action_multiple_sessions, false, &challenge, error);
|
||||
|
@ -1202,7 +1200,7 @@ int bus_manager_shutdown_or_sleep_now_or_later(
|
|||
|
||||
delayed =
|
||||
m->inhibit_delay_max > 0 &&
|
||||
manager_is_inhibited(m, w, INHIBIT_DELAY, NULL, false);
|
||||
manager_is_inhibited(m, w, INHIBIT_DELAY, NULL, false, false, 0);
|
||||
|
||||
if (delayed)
|
||||
/* Shutdown is delayed, keep in mind what we
|
||||
|
@ -1236,6 +1234,7 @@ static int bus_manager_do_shutdown_or_sleep(
|
|||
bool multiple_sessions, blocked;
|
||||
DBusMessage *reply = NULL;
|
||||
int r;
|
||||
unsigned long ul;
|
||||
|
||||
assert(m);
|
||||
assert(connection);
|
||||
|
@ -1265,12 +1264,16 @@ static int bus_manager_do_shutdown_or_sleep(
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
r = have_multiple_sessions(connection, m, message, error);
|
||||
ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
|
||||
if (ul == (unsigned long) -1)
|
||||
return -EIO;
|
||||
|
||||
r = have_multiple_sessions(m, (uid_t) ul);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
multiple_sessions = r > 0;
|
||||
blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false);
|
||||
blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, (uid_t) ul);
|
||||
|
||||
if (multiple_sessions) {
|
||||
r = verify_polkit(connection, message, action_multiple_sessions, interactive, NULL, error);
|
||||
|
@ -2303,7 +2306,7 @@ int manager_dispatch_delayed(Manager *manager) {
|
|||
/* Continue delay? */
|
||||
delayed =
|
||||
manager->delayed_timestamp + manager->inhibit_delay_max > now(CLOCK_MONOTONIC) &&
|
||||
manager_is_inhibited(manager, manager->delayed_what, INHIBIT_DELAY, NULL, false);
|
||||
manager_is_inhibited(manager, manager->delayed_what, INHIBIT_DELAY, NULL, false, false, 0);
|
||||
if (delayed)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -364,7 +364,9 @@ bool manager_is_inhibited(
|
|||
InhibitWhat w,
|
||||
InhibitMode mm,
|
||||
dual_timestamp *since,
|
||||
bool only_active) {
|
||||
bool ignore_inactive,
|
||||
bool ignore_uid,
|
||||
uid_t uid) {
|
||||
|
||||
Inhibitor *i;
|
||||
Iterator j;
|
||||
|
@ -381,7 +383,10 @@ bool manager_is_inhibited(
|
|||
if (i->mode != mm)
|
||||
continue;
|
||||
|
||||
if (only_active && pid_is_active(m, i->pid) <= 0)
|
||||
if (ignore_inactive && pid_is_active(m, i->pid) <= 0)
|
||||
continue;
|
||||
|
||||
if (ignore_uid && i->uid == uid)
|
||||
continue;
|
||||
|
||||
if (!inhibited ||
|
||||
|
|
|
@ -83,7 +83,7 @@ int inhibitor_create_fifo(Inhibitor *i);
|
|||
void inhibitor_remove_fifo(Inhibitor *i);
|
||||
|
||||
InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm);
|
||||
bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool only_active);
|
||||
bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid);
|
||||
|
||||
const char *inhibit_what_to_string(InhibitWhat k);
|
||||
InhibitWhat inhibit_what_from_string(const char *s);
|
||||
|
|
|
@ -1407,7 +1407,7 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
|
|||
|
||||
assert(m);
|
||||
|
||||
idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false);
|
||||
idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false, false, 0);
|
||||
|
||||
HASHMAP_FOREACH(s, m->sessions, i) {
|
||||
dual_timestamp k;
|
||||
|
|
Loading…
Reference in New Issue