summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-21 15:44:14 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-21 15:44:14 +0200
commit8e7fd6ade44ce5dde0867ba748c7978ed1206865 (patch)
treeced70d8e4c3d4e14f70ac459277c9046bd26500c /src/login
parent636d30a0895f17eca8313d50f9b2fc1ec5e128da (diff)
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.
Diffstat (limited to 'src/login')
-rw-r--r--src/login/logind-button.c15
-rw-r--r--src/login/logind-dbus.c19
-rw-r--r--src/login/logind-gperf.gperf30
-rw-r--r--src/login/logind-inhibit.c14
-rw-r--r--src/login/logind-inhibit.h7
-rw-r--r--src/login/logind.c9
-rw-r--r--src/login/logind.conf6
-rw-r--r--src/login/logind.h6
-rw-r--r--src/login/org.freedesktop.login1.policy.in16
9 files changed, 79 insertions, 43 deletions
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index e2d9fd2b0f..8fdab789bc 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 650be34656..cbf43fe0a0 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -210,7 +210,8 @@
" <property name=\"DelayInhibited\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"InhibitDelayMaxUSec\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"HandlePowerKey\" type=\"s\" access=\"read\"/>\n" \
- " <property name=\"HandleSleepKey\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"HandleSuspendKey\" type=\"s\" access=\"read\"/>\n" \
+ " <property name=\"HandleHibernateKey\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"HandleLidSwitch\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"PreparingForShutdown\" type=\"b\" access=\"read\"/>\n" \
" <property name=\"PreparingForSleep\" type=\"b\" access=\"read\"/>\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 412dbb5941..1bd1b285d8 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 66e4c29f36..f1b9cca834 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 f5cfb9b9f5..4c158ee0fe 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 ccd18b9898..9cce481340 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 0ac02c0f01..2757fba30a 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 0b52bf7b09..f415dfbcbf 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 8d991e40fb..57dfb2a8b6 100644
--- a/src/login/org.freedesktop.login1.policy.in
+++ b/src/login/org.freedesktop.login1.policy.in
@@ -76,9 +76,19 @@
</defaults>
</action>
- <action id="org.freedesktop.login1.inhibit-handle-sleep-key">
- <_description>Allow applications to inhibit system handling of the sleep key</_description>
- <_message>Authentication is required to allow an application to inhibit system handling of the sleep key.</_message>
+ <action id="org.freedesktop.login1.inhibit-handle-suspend-key">
+ <_description>Allow applications to inhibit system handling of the suspend key</_description>
+ <_message>Authentication is required to allow an application to inhibit system handling of the suspend key.</_message>
+ <defaults>
+ <allow_any>no</allow_any>
+ <allow_inactive>yes</allow_inactive>
+ <allow_active>yes</allow_active>
+ </defaults>
+ </action>
+
+ <action id="org.freedesktop.login1.inhibit-handle-hibernate-key">
+ <_description>Allow applications to inhibit system handling of the hibernate key</_description>
+ <_message>Authentication is required to allow an application to inhibit system handling of the hibernate key.</_message>
<defaults>
<allow_any>no</allow_any>
<allow_inactive>yes</allow_inactive>