From 8e7fd6ade44ce5dde0867ba748c7978ed1206865 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 21 Sep 2012 15:44:14 +0200 Subject: [PATCH] logind: split up HandleSleepKey= into HandleSuspendKey= and HandleHibernateKey= The kernel and X11 distuingish these two, and Thinkpad keys have both, hence we really should distinguish them too. --- man/logind.conf.xml | 20 ++++++++++----- src/login/logind-button.c | 15 ++++++++--- src/login/logind-dbus.c | 19 ++++++++------ src/login/logind-gperf.gperf | 30 ++++++++++++---------- src/login/logind-inhibit.c | 14 ++++++---- src/login/logind-inhibit.h | 7 ++--- src/login/logind.c | 9 ++++--- src/login/logind.conf | 6 +++-- src/login/logind.h | 6 +++-- src/login/org.freedesktop.login1.policy.in | 16 +++++++++--- 10 files changed, 92 insertions(+), 50 deletions(-) diff --git a/man/logind.conf.xml b/man/logind.conf.xml index ccfc4abce..3d83d2c81 100644 --- a/man/logind.conf.xml +++ b/man/logind.conf.xml @@ -198,7 +198,8 @@ HandlePowerKey= - HandleSleepKey= + HandleSuspendKey= + HandleHibernateKey= HandleLidSwitch= Controls whether @@ -222,15 +223,19 @@ events. HandlePowerKey= defaults to poweroff. - HandleSleepKey= and + HandleSuspendKey= + and HandleLidSwitch= - default to - suspend. + default to suspend. + HandleHibernateKey= + defaults to + hibernate. PowerKeyIgnoreInhibited= - SleepKeyIgnoreInhibited= + SuspendKeyIgnoreInhibited= + HibernateKeyIgnoreInhibited= LidSwitchIgnoreInhibited= Controls whether @@ -244,9 +249,10 @@ respected, if on the requested operation is executed in any - case. PowerKeyIgnoreInhibited= + case. PowerKeyIgnoreInhibited=, + SuspendKeyIgnoreInhibited= and - SleepKeyIgnoreInhibited= + HibernateKeyIgnoreInhibited= defaults to off, LidSwitchIgnoreInhibited= defaults to diff --git a/src/login/logind-button.c b/src/login/logind-button.c index e2d9fd2b0..8fdab789b 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -249,12 +249,21 @@ int button_process(Button *b) { log_info("Power key pressed."); return button_handle(b, INHIBIT_HANDLE_POWER_KEY, b->manager->handle_power_key, b->manager->power_key_ignore_inhibited, true); + /* The kernel is a bit confused here: + + KEY_SLEEP = suspend-to-ram, which everybody else calls "suspend" + KEY_SUSPEND = suspend-to-disk, which everybody else calls "hibernate" + */ + case KEY_SLEEP: - case KEY_SUSPEND: - log_info("Sleep key pressed."); - return button_handle(b, INHIBIT_HANDLE_SLEEP_KEY, b->manager->handle_sleep_key, b->manager->sleep_key_ignore_inhibited, true); + log_info("Suspend key pressed."); + return button_handle(b, INHIBIT_HANDLE_SUSPEND_KEY, b->manager->handle_suspend_key, b->manager->suspend_key_ignore_inhibited, true); + case KEY_SUSPEND: + log_info("Hibernate key pressed."); + return button_handle(b, INHIBIT_HANDLE_HIBERNATE_KEY, b->manager->handle_hibernate_key, b->manager->hibernate_key_ignore_inhibited, true); } + } else if (ev.type == EV_SW && ev.value > 0) { switch (ev.code) { diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index 650be3465..cbf43fe0a 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -210,7 +210,8 @@ " \n" \ " \n" \ " \n" \ - " \n" \ + " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -729,12 +730,13 @@ static int bus_manager_inhibit(Manager *m, DBusConnection *connection, DBusMessa } r = verify_polkit(connection, message, - w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") : - w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") : - w == INHIBIT_IDLE ? "org.freedesktop.login1.inhibit-block-idle" : - w == INHIBIT_HANDLE_POWER_KEY ? "org.freedesktop.login1.inhibit-handle-power-key" : - w == INHIBIT_HANDLE_SLEEP_KEY ? "org.freedesktop.login1.inhibit-handle-sleep-key" : - "org.freedesktop.login1.inhibit-handle-lid-switch", + w == INHIBIT_SHUTDOWN ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-shutdown" : "org.freedesktop.login1.inhibit-delay-shutdown") : + w == INHIBIT_SLEEP ? (mm == INHIBIT_BLOCK ? "org.freedesktop.login1.inhibit-block-sleep" : "org.freedesktop.login1.inhibit-delay-sleep") : + w == INHIBIT_IDLE ? "org.freedesktop.login1.inhibit-block-idle" : + w == INHIBIT_HANDLE_POWER_KEY ? "org.freedesktop.login1.inhibit-handle-power-key" : + w == INHIBIT_HANDLE_SUSPEND_KEY ? "org.freedesktop.login1.inhibit-handle-suspend-key" : + w == INHIBIT_HANDLE_HIBERNATE_KEY ? "org.freedesktop.login1.inhibit-handle-hibernate-key" : + "org.freedesktop.login1.inhibit-handle-lid-switch", false, NULL, error); if (r < 0) goto fail; @@ -1322,7 +1324,8 @@ static const BusProperty bus_login_manager_properties[] = { { "DelayInhibited", bus_manager_append_inhibited, "s", 0 }, { "InhibitDelayMaxUSec", bus_property_append_usec, "t", offsetof(Manager, inhibit_delay_max) }, { "HandlePowerKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_power_key) }, - { "HandleSleepKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_sleep_key) }, + { "HandleSuspendKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_suspend_key) }, + { "HandleHibernateKey", bus_manager_append_handle_button, "s", offsetof(Manager, handle_hibernate_key)}, { "HandleLidSwitch", bus_manager_append_handle_button, "s", offsetof(Manager, handle_lid_switch) }, { "PreparingForShutdown", bus_manager_append_preparing, "b", 0 }, { "PreparingForSleep", bus_manager_append_preparing, "b", 0 }, diff --git a/src/login/logind-gperf.gperf b/src/login/logind-gperf.gperf index 412dbb594..1bd1b285d 100644 --- a/src/login/logind-gperf.gperf +++ b/src/login/logind-gperf.gperf @@ -14,17 +14,19 @@ struct ConfigPerfItem; %struct-type %includes %% -Login.NAutoVTs, config_parse_unsigned, 0, offsetof(Manager, n_autovts) -Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt) -Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes) -Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users) -Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users) -Login.Controllers, config_parse_strv, 0, offsetof(Manager, controllers) -Login.ResetControllers, config_parse_strv, 0, offsetof(Manager, reset_controllers) -Login.InhibitDelayMaxSec, config_parse_usec, 0, offsetof(Manager, inhibit_delay_max) -Login.HandlePowerKey, config_parse_handle_button, 0, offsetof(Manager, handle_power_key) -Login.HandleSleepKey, config_parse_handle_button, 0, offsetof(Manager, handle_sleep_key) -Login.HandleLidSwitch, config_parse_handle_button, 0, offsetof(Manager, handle_lid_switch) -Login.PowerKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, power_key_ignore_inhibited) -Login.SleepKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, sleep_key_ignore_inhibited) -Login.LidSwitchIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, lid_switch_ignore_inhibited) +Login.NAutoVTs, config_parse_unsigned, 0, offsetof(Manager, n_autovts) +Login.ReserveVT, config_parse_unsigned, 0, offsetof(Manager, reserve_vt) +Login.KillUserProcesses, config_parse_bool, 0, offsetof(Manager, kill_user_processes) +Login.KillOnlyUsers, config_parse_strv, 0, offsetof(Manager, kill_only_users) +Login.KillExcludeUsers, config_parse_strv, 0, offsetof(Manager, kill_exclude_users) +Login.Controllers, config_parse_strv, 0, offsetof(Manager, controllers) +Login.ResetControllers, config_parse_strv, 0, offsetof(Manager, reset_controllers) +Login.InhibitDelayMaxSec, config_parse_usec, 0, offsetof(Manager, inhibit_delay_max) +Login.HandlePowerKey, config_parse_handle_button, 0, offsetof(Manager, handle_power_key) +Login.HandleSuspendKey, config_parse_handle_button, 0, offsetof(Manager, handle_suspend_key) +Login.HandleHibernateKey, config_parse_handle_button, 0, offsetof(Manager, handle_hibernate_key) +Login.HandleLidSwitch, config_parse_handle_button, 0, offsetof(Manager, handle_lid_switch) +Login.PowerKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, power_key_ignore_inhibited) +Login.SuspendKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, suspend_key_ignore_inhibited) +Login.HibernateKeyIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, hibernate_key_ignore_inhibited) +Login.LidSwitchIgnoreInhibited, config_parse_bool, 0, offsetof(Manager, lid_switch_ignore_inhibited) diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 66e4c29f3..f1b9cca83 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -403,7 +403,7 @@ bool manager_is_inhibited( } const char *inhibit_what_to_string(InhibitWhat w) { - static __thread char buffer[73]; + static __thread char buffer[97]; char *p; if (w < 0 || w >= _INHIBIT_WHAT_MAX) @@ -418,8 +418,10 @@ const char *inhibit_what_to_string(InhibitWhat w) { p = stpcpy(p, "idle:"); if (w & INHIBIT_HANDLE_POWER_KEY) p = stpcpy(p, "handle-power-key:"); - if (w & INHIBIT_HANDLE_SLEEP_KEY) - p = stpcpy(p, "handle-sleep-key:"); + if (w & INHIBIT_HANDLE_SUSPEND_KEY) + p = stpcpy(p, "handle-suspend-key:"); + if (w & INHIBIT_HANDLE_HIBERNATE_KEY) + p = stpcpy(p, "handle-hibernate-key:"); if (w & INHIBIT_HANDLE_LID_SWITCH) p = stpcpy(p, "handle-lid-switch:"); @@ -445,8 +447,10 @@ InhibitWhat inhibit_what_from_string(const char *s) { what |= INHIBIT_IDLE; else if (l == 16 && strncmp(w, "handle-power-key", l) == 0) what |= INHIBIT_HANDLE_POWER_KEY; - else if (l == 16 && strncmp(w, "handle-sleep-key", l) == 0) - what |= INHIBIT_HANDLE_SLEEP_KEY; + else if (l == 18 && strncmp(w, "handle-suspend-key", l) == 0) + what |= INHIBIT_HANDLE_SUSPEND_KEY; + else if (l == 20 && strncmp(w, "handle-hibernate-key", l) == 0) + what |= INHIBIT_HANDLE_HIBERNATE_KEY; else if (l == 17 && strncmp(w, "handle-lid-switch", l) == 0) what |= INHIBIT_HANDLE_LID_SWITCH; else diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index f5cfb9b9f..4c158ee0f 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -32,9 +32,10 @@ typedef enum InhibitWhat { INHIBIT_SLEEP = 2, INHIBIT_IDLE = 4, INHIBIT_HANDLE_POWER_KEY = 8, - INHIBIT_HANDLE_SLEEP_KEY = 16, - INHIBIT_HANDLE_LID_SWITCH = 32, - _INHIBIT_WHAT_MAX = 64, + INHIBIT_HANDLE_SUSPEND_KEY = 16, + INHIBIT_HANDLE_HIBERNATE_KEY = 32, + INHIBIT_HANDLE_LID_SWITCH = 64, + _INHIBIT_WHAT_MAX = 128, _INHIBIT_WHAT_INVALID = -1 } InhibitWhat; diff --git a/src/login/logind.c b/src/login/logind.c index ccd18b989..9cce48134 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -56,7 +56,8 @@ Manager *manager_new(void) { m->reserve_vt = 6; m->inhibit_delay_max = 5 * USEC_PER_SEC; m->handle_power_key = HANDLE_POWEROFF; - m->handle_sleep_key = HANDLE_SUSPEND; + m->handle_suspend_key = HANDLE_SUSPEND; + m->handle_hibernate_key = HANDLE_HIBERNATE; m->handle_lid_switch = HANDLE_SUSPEND; m->lid_switch_ignore_inhibited = true; @@ -496,7 +497,8 @@ int manager_enumerate_buttons(Manager *m) { /* Loads buttons from udev */ if (m->handle_power_key == HANDLE_IGNORE && - m->handle_sleep_key == HANDLE_IGNORE && + m->handle_suspend_key == HANDLE_IGNORE && + m->handle_hibernate_key == HANDLE_IGNORE && m->handle_lid_switch == HANDLE_IGNORE) return 0; @@ -1306,7 +1308,8 @@ static int manager_connect_udev(Manager *m) { /* Don't watch keys if nobody cares */ if (m->handle_power_key != HANDLE_IGNORE || - m->handle_sleep_key != HANDLE_IGNORE || + m->handle_suspend_key != HANDLE_IGNORE || + m->handle_hibernate_key != HANDLE_IGNORE || m->handle_lid_switch != HANDLE_IGNORE) { m->udev_button_monitor = udev_monitor_new_from_netlink(m->udev, "udev"); diff --git a/src/login/logind.conf b/src/login/logind.conf index 0ac02c0f0..2757fba30 100644 --- a/src/login/logind.conf +++ b/src/login/logind.conf @@ -17,8 +17,10 @@ #ResetControllers=cpu #InhibitDelayMaxSec=5 #HandlePowerKey=poweroff -#HandleSleepKey=suspend +#HandleSuspendKey=suspend +#HandleHibernateKey=hibernate #HandleLidSwitch=suspend #PowerKeyIgnoreInhibited=no -#SleepKeyIgnoreInhibited=no +#SuspendKeyIgnoreInhibited=no +#HibernateKeyIgnoreInhibited=no #LidSwitchIgnoreInhibited=yes diff --git a/src/login/logind.h b/src/login/logind.h index 0b52bf7b0..f415dfbcb 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -100,11 +100,13 @@ struct Manager { usec_t inhibit_delay_max; HandleButton handle_power_key; - HandleButton handle_sleep_key; + HandleButton handle_suspend_key; + HandleButton handle_hibernate_key; HandleButton handle_lid_switch; bool power_key_ignore_inhibited; - bool sleep_key_ignore_inhibited; + bool suspend_key_ignore_inhibited; + bool hibernate_key_ignore_inhibited; bool lid_switch_ignore_inhibited; }; diff --git a/src/login/org.freedesktop.login1.policy.in b/src/login/org.freedesktop.login1.policy.in index 8d991e40f..57dfb2a8b 100644 --- a/src/login/org.freedesktop.login1.policy.in +++ b/src/login/org.freedesktop.login1.policy.in @@ -76,9 +76,19 @@ - - <_description>Allow applications to inhibit system handling of the sleep key - <_message>Authentication is required to allow an application to inhibit system handling of the sleep key. + + <_description>Allow applications to inhibit system handling of the suspend key + <_message>Authentication is required to allow an application to inhibit system handling of the suspend key. + + no + yes + yes + + + + + <_description>Allow applications to inhibit system handling of the hibernate key + <_message>Authentication is required to allow an application to inhibit system handling of the hibernate key. no yes -- 2.30.2