Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.4:Update
systemd.26701
1003-logind-store-a-timestamp-when-the-ACPI-pow...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 1003-logind-store-a-timestamp-when-the-ACPI-power-button-.patch of Package systemd.26701
From 95da8cb13e13d7a85ddcc810784900e71298de6e Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero <federico@gnome.org> Date: Thu, 16 Jun 2016 17:38:44 -0500 Subject: [PATCH 1003/1007] logind: store a timestamp when the ACPI power button is pressed When we get a D-Bus call to shutdown, we'll use the corresponding timestamp to see if this call is due to GDM responding to the ACPI power button itself, or just due to any random program calling the D-Bus shutdown method. [federico: fixes bsc#981830] [federico: fixes bsc#888612] [fbui: fixes bsc#1072933] --- src/basic/login-util.h | 3 ++- src/login/logind-action.c | 4 ++++ src/login/logind-dbus.c | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/basic/login-util.h b/src/basic/login-util.h index 841fd324f1..2b606873e0 100644 --- a/src/basic/login-util.h +++ b/src/basic/login-util.h @@ -8,10 +8,11 @@ #define SD_LOGIND_REBOOT_VIA_KEXEC (UINT64_C(1) << 1) /* For internal use only */ +#define SD_LOGIND_SLEEP_VERB (UINT64_C(1) << 62) #define SD_LOGIND_INTERACTIVE (UINT64_C(1) << 63) #define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC (SD_LOGIND_ROOT_CHECK_INHIBITORS|SD_LOGIND_REBOOT_VIA_KEXEC) -#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_ALL (SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC|SD_LOGIND_INTERACTIVE) +#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_ALL (SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC|SD_LOGIND_INTERACTIVE|SD_LOGIND_SLEEP_VERB) bool session_id_valid(const char *id); diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 8ed066c25e..bc6fffd075 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -7,6 +7,7 @@ #include "bus-util.h" #include "conf-parser.h" #include "format-util.h" +#include "fs-util.h" #include "logind-action.h" #include "logind-dbus.h" #include "logind-session-dbus.h" @@ -83,6 +84,9 @@ int manager_handle_action( /* If the key handling is inhibited, don't do anything */ if (inhibit_key > 0) { + if (inhibit_key == INHIBIT_HANDLE_POWER_KEY) + (void) touch("/run/systemd/acpi-shutdown"); + if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0, NULL)) { log_debug("Refusing %s operation, %s is inhibited.", handle_action_to_string(handle), diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 19c3f9bd6e..1f33740357 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1784,6 +1784,7 @@ static int verify_shutdown_creds( _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; bool multiple_sessions, blocked, interactive; + bool shutdown_through_acpi; uid_t uid; int r; @@ -1808,7 +1809,19 @@ static int verify_shutdown_creds( blocked = manager_is_inhibited(m, w, INHIBIT_BLOCK, NULL, false, true, uid, NULL); interactive = flags & SD_LOGIND_INTERACTIVE; - if (multiple_sessions && action_multiple_sessions) { + shutdown_through_acpi = false; + if (access("/run/systemd/acpi-shutdown", F_OK) == 0) { + struct stat buf; + + if (!(flags & SD_LOGIND_SLEEP_VERB) && + stat("/run/systemd/acpi-shutdown", &buf) == 0) + /* FIXME: this is really ugly. */ + shutdown_through_acpi = (time(NULL) - buf.st_mtime) <= 65; + + unlink("/run/systemd/acpi-shutdown"); + } + + if (multiple_sessions && action_multiple_sessions && !shutdown_through_acpi) { r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action_multiple_sessions, NULL, interactive, UID_INVALID, &m->polkit_registry, error); if (r < 0) return r; @@ -1831,7 +1844,7 @@ static int verify_shutdown_creds( } } - if (!multiple_sessions && !blocked && action) { + if (!multiple_sessions && !blocked && action && !shutdown_through_acpi) { r = bus_verify_polkit_async(message, CAP_SYS_BOOT, action, NULL, interactive, UID_INVALID, &m->polkit_registry, error); if (r < 0) return r; @@ -1903,6 +1916,8 @@ static int method_do_shutdown_or_sleep( "Sleep verb \"%s\" not supported", sleep_operation_to_string(sleep_operation)); if (r < 0) return r; + + flags |= SD_LOGIND_SLEEP_VERB; } r = verify_shutdown_creds(m, message, w, action, action_multiple_sessions, -- 2.31.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor