Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:tsaupe:testpackages
systemd-bsc1218671
1002-logind-store-a-timestamp-when-the-ACPI-pow...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 1002-logind-store-a-timestamp-when-the-ACPI-power-button-.patch of Package systemd-bsc1218671
From cb182c324f0ba5761f8f42b6dbcab793a546d830 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 1002/1016] 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 613fb0f86f..4b0674d9cd 100644 --- a/src/basic/login-util.h +++ b/src/basic/login-util.h @@ -9,10 +9,11 @@ #define SD_LOGIND_SOFT_REBOOT (UINT64_C(1) << 2) /* 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|SD_LOGIND_SOFT_REBOOT) -#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 42dc36b670..1e321d2077 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -9,6 +9,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" @@ -182,6 +183,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 b3a36d0d05..1ca6ef6f9c 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -1738,6 +1738,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; @@ -1761,7 +1762,19 @@ static int verify_shutdown_creds( blocked = manager_is_inhibited(m, a->inhibit_what, INHIBIT_BLOCK, NULL, false, true, uid, NULL); interactive = flags & SD_LOGIND_INTERACTIVE; - if (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 && !shutdown_through_acpi) { r = bus_verify_polkit_async( message, CAP_SYS_BOOT, @@ -1797,7 +1810,7 @@ static int verify_shutdown_creds( return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ } - if (!multiple_sessions && !blocked) { + if (!multiple_sessions && !blocked && !shutdown_through_acpi) { r = bus_verify_polkit_async(message, CAP_SYS_BOOT, a->polkit_action, @@ -1907,6 +1920,8 @@ static int method_do_shutdown_or_sleep( sleep_operation_to_string(a->sleep_operation)); if (r < 0) return r; + + flags |= SD_LOGIND_SLEEP_VERB; } r = verify_shutdown_creds(m, message, a, flags, error); -- 2.35.3
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