summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-21 11:57:48 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-21 11:57:48 +0200
commit409133be63387fc04d927e8aecd2f6ba03d2f143 (patch)
tree53805338e9e71c3344d6f46320c9dbf506612768 /src/login
parent68e9f6e6be9e6e14a71788b490ba8cdc3ed7f2b5 (diff)
logind: allow users to override their own suspend/sleep inhibitors
Diffstat (limited to 'src/login')
-rw-r--r--src/login/logind-button.c4
-rw-r--r--src/login/logind-dbus.c33
-rw-r--r--src/login/logind-inhibit.c9
-rw-r--r--src/login/logind-inhibit.h2
-rw-r--r--src/login/logind.c2
5 files changed, 29 insertions, 21 deletions
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index d0c9ccd833..e2d9fd2b0f 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -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 */
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 4ae5ba70ba..650be34656 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -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;
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index fce2f4dd90..66e4c29f36 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -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 ||
diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h
index d89a1b36af..f5cfb9b9f5 100644
--- a/src/login/logind-inhibit.h
+++ b/src/login/logind-inhibit.h
@@ -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);
diff --git a/src/login/logind.c b/src/login/logind.c
index 14c83551b9..ccd18b9898 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -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;