Skip to content

Commit

Permalink
logind: support for hybrid sleep (i.e. suspend+hibernate at the same …
Browse files Browse the repository at this point in the history
…time)
  • Loading branch information
poettering committed Oct 27, 2012
1 parent 2001208 commit 6524990
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/test-journal-enum
/test-sleep
/localectl
/hostnamectl
/timedatectl
Expand Down
17 changes: 15 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ dist_systemunit_DATA = \
units/nss-user-lookup.target \
units/mail-transfer-agent.target \
units/hibernate.target \
units/hybrid-sleep.target \
units/http-daemon.target \
units/poweroff.target \
units/reboot.target \
Expand Down Expand Up @@ -329,6 +330,7 @@ nodist_systemunit_DATA = \
units/rescue.service \
units/[email protected] \
units/systemd-hibernate.service \
units/systemd-hybrid-sleep.service \
units/systemd-suspend.service \
units/systemd-halt.service \
units/systemd-poweroff.service \
Expand Down Expand Up @@ -379,6 +381,7 @@ EXTRA_DIST += \
units/systemd-udev-settle.service \
units/debug-shell.service.in \
units/systemd-hibernate.service.in \
units/systemd-hybrid-sleep.service.in \
units/systemd-suspend.service.in \
units/quotaon.service.in \
introspect.awk \
Expand Down Expand Up @@ -534,6 +537,7 @@ MANPAGES_ALIAS = \
man/systemd-shutdownd.socket.8 \
man/systemd-shutdownd.8 \
man/systemd-hibernate.service.8 \
man/systemd-hybrid-sleep.service.8 \
man/systemd-sleep.8 \
man/systemd-shutdown.8 \
man/systemd-poweroff.service.8 \
Expand Down Expand Up @@ -608,6 +612,7 @@ man/systemd-initctl.8: man/systemd-initctl.service.8
man/systemd-shutdownd.socket.8: man/systemd-shutdownd.service.8
man/systemd-shutdownd.8: man/systemd-shutdownd.service.8
man/systemd-hibernate.service.8: man/systemd-suspend.service.8
man/systemd-hybrid-sleep.service.8: man/systemd-suspend.service.8
man/systemd-sleep.8: man/systemd-suspend.service.8
man/systemd-shutdown.8: man/systemd-halt.service.8
man/systemd-poweroff.service.8: man/systemd-halt.service.8
Expand Down Expand Up @@ -1176,15 +1181,17 @@ noinst_PROGRAMS += \
test-unit-name \
test-log \
test-unit-file \
test-date
test-date \
test-sleep

TESTS += \
test-job-type \
test-env-replace \
test-strv \
test-unit-name \
test-unit-file \
test-date
test-date \
test-sleep

test_engine_SOURCES = \
src/test/test-engine.c
Expand Down Expand Up @@ -1252,6 +1259,12 @@ test_date_SOURCES = \
test_date_LDADD = \
libsystemd-core.la

test_sleep_SOURCES = \
src/test/test-sleep.c

test_sleep_LDADD = \
libsystemd-core.la

test_daemon_SOURCES = \
src/test/test-daemon.c

Expand Down
5 changes: 3 additions & 2 deletions man/logind.conf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@
<literal>poweroff</literal>,
<literal>reboot</literal>,
<literal>halt</literal>,
<literal>kexec</literal> and
<literal>hibernate</literal>. If
<literal>kexec</literal>,
<literal>hibernate</literal> and
<literal>hybrid-sleep</literal>. If
<literal>ignore</literal> logind will
never handle these keys. Otherwise the
specified action will be taken in the
Expand Down
5 changes: 5 additions & 0 deletions man/systemctl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,11 @@

<listitem><para>Hibernate the system.</para></listitem>
</varlistentry>
<varlistentry>
<term><command>hybrid-sleep</command></term>

<listitem><para>Hibernate and suspend the system.</para></listitem>
</varlistentry>
<varlistentry>
<term><command>switch-root [ROOT] [INIT]</command></term>

Expand Down
42 changes: 26 additions & 16 deletions man/systemd-suspend.service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@
<refnamediv>
<refname>systemd-suspend.service</refname>
<refname>systemd-hibernate.service</refname>
<refname>systemd-hybrid-sleep.service</refname>
<refname>systemd-sleep</refname>
<refpurpose>System sleep state logic</refpurpose>
</refnamediv>

<refsynopsisdiv>
<para><filename>systemd-suspend.service</filename></para>
<para><filename>systemd-hibernate.service</filename></para>
<para><filename>systemd-hybrid-sleep.service</filename></para>
<para><filename>/usr/lib/systemd/systemd-sleep</filename></para>
</refsynopsisdiv>

Expand All @@ -64,19 +66,25 @@
for the actual system suspend. Similar,
<filename>systemd-hibernate.service</filename> is
pulled in by <filename>hibernate.target</filename> to
execute the actual hibernation.</para>

<para>Immediately before entering system suspend and
hibernation
<filename>systemd-suspend.service</filename> will run
all executables in
execute the actual hibernation. Finally,
<filename>systemd-hybrid-sleep.service</filename> is
pulled in by <filename>hybrid-sleep.target</filename>
to execute hybrid hibernation with system
suspend.</para>

<para>Immediately before entering system suspend
and/or hibernation
<filename>systemd-suspend.service</filename> (and the
other mentioned units, respectively) will run all
executables in
<filename>/usr/lib/systemd/system-sleep/</filename>
and pass two arguments to them. The first argument
will be "<literal>pre</literal>", the second either
"<literal>suspend</literal>" or
"<literal>hibernate</literal>", depending on the
"<literal>suspend</literal>",
"<literal>hibernate</literal>", or
"<literal>hybrid-sleep</literal>" depending on the
chosen action. Immediately after leaving system
suspend and hibernation the same executables are run,
suspend and/or hibernation the same executables are run,
but the first argument is now
"<literal>post</literal>". All executables in this
directory are executed in parallel, and execution of
Expand All @@ -87,15 +95,17 @@
<filename>/usr/lib/systemd/system-sleep/</filename>
are intended for local use only and should be
considered hacks. If applications want to be notified
of system suspend and resume there are much nicer
interfaces available.</para>
of system suspend/hibernation and resume there are
much nicer interfaces available.</para>

<para>Note that
<filename>systemd-suspend.service</filename> and
<filename>systemd-hibernate.service</filename> should
never be executed directly. Instead, trigger system
sleep states with a command such as "<literal>systemctl
suspend</literal>" or suchlike.</para>
<filename>systemd-suspend.service</filename>,
<filename>systemd-hibernate.service</filename> and
<filename>systemd-hybrid-sleep.service</filename>
should never be executed directly. Instead, trigger
system sleep states with a command such as
"<literal>systemctl suspend</literal>" or
similar.</para>
</refsect1>

<refsect1>
Expand Down
15 changes: 12 additions & 3 deletions man/systemd.special.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<filename>graphical.target</filename>,
<filename>hibernate.target</filename>,
<filename>http-daemon.target</filename>,
<filename>hybrid-sleep.target</filename>,
<filename>halt.target</filename>,
<filename>kbrequest.target</filename>,
<filename>kexec.target</filename>,
Expand Down Expand Up @@ -302,6 +303,15 @@
facility.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename>hybrid-sleep.target</filename></term>
<listitem>
<para>A special target unit
for hibernating and suspending the
system at the same time. This pulls in
<filename>sleep.target</filename>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename>halt.target</filename></term>
<listitem>
Expand Down Expand Up @@ -652,9 +662,8 @@
<listitem>
<para>A special target unit
that is pulled in by
<filename>suspend.target</filename>
and
<filename>hibernate.target</filename>
<filename>suspend.target</filename>,
<filename>hibernate.target</filename> and <filename>hybrid-sleep.target</filename>
and may be used to hook units
into the sleep state
logic.</para>
Expand Down
1 change: 1 addition & 0 deletions src/core/special.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define SPECIAL_EXIT_TARGET "exit.target"
#define SPECIAL_SUSPEND_TARGET "suspend.target"
#define SPECIAL_HIBERNATE_TARGET "hibernate.target"
#define SPECIAL_HYBRID_SLEEP_TARGET "hybrid-sleep.target"

/* Special boot targets */
#define SPECIAL_RESCUE_TARGET "rescue.target"
Expand Down
21 changes: 12 additions & 9 deletions src/login/logind-button.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,18 @@ static int button_handle(
[HANDLE_HALT] = "Halting...",
[HANDLE_KEXEC] = "Rebooting via kexec...",
[HANDLE_SUSPEND] = "Suspending...",
[HANDLE_HIBERNATE] = "Hibernating..."
[HANDLE_HIBERNATE] = "Hibernating...",
[HANDLE_HYBRID_SLEEP] = "Hibernating and suspend...",
};

static const char * const target_table[_HANDLE_BUTTON_MAX] = {
[HANDLE_POWEROFF] = "poweroff.target",
[HANDLE_REBOOT] = "reboot.target",
[HANDLE_HALT] = "halt.target",
[HANDLE_KEXEC] = "kexec.target",
[HANDLE_SUSPEND] = "suspend.target",
[HANDLE_HIBERNATE] = "hibernate.target"
[HANDLE_POWEROFF] = SPECIAL_POWEROFF_TARGET,
[HANDLE_REBOOT] = SPECIAL_REBOOT_TARGET,
[HANDLE_HALT] = SPECIAL_HALT_TARGET,
[HANDLE_KEXEC] = SPECIAL_KEXEC_TARGET,
[HANDLE_SUSPEND] = SPECIAL_SUSPEND_TARGET,
[HANDLE_HIBERNATE] = SPECIAL_HIBERNATE_TARGET,
[HANDLE_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET
};

DBusError error;
Expand All @@ -193,7 +195,7 @@ static int button_handle(
return 0;
}

inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE || handle == HANDLE_HYBRID_SLEEP ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;

/* If the actual operation is inhibited, warn and fail */
if (!ignore_inhibited &&
Expand Down Expand Up @@ -305,7 +307,8 @@ static const char* const handle_button_table[_HANDLE_BUTTON_MAX] = {
[HANDLE_HALT] = "halt",
[HANDLE_KEXEC] = "kexec",
[HANDLE_SUSPEND] = "suspend",
[HANDLE_HIBERNATE] = "hibernate"
[HANDLE_HIBERNATE] = "hibernate",
[HANDLE_HYBRID_SLEEP] = "hybrid-sleep",
};
DEFINE_STRING_TABLE_LOOKUP(handle_button, HandleButton);
DEFINE_CONFIG_PARSE_ENUM(config_parse_handle_button, handle_button, HandleButton, "Failed to parse handle button setting");
1 change: 1 addition & 0 deletions src/login/logind-button.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef enum HandleButton {
HANDLE_KEXEC,
HANDLE_SUSPEND,
HANDLE_HIBERNATE,
HANDLE_HYBRID_SLEEP,
_HANDLE_BUTTON_MAX,
_HANDLE_BUTTON_INVALID = -1
} HandleButton;
Expand Down
Loading

0 comments on commit 6524990

Please sign in to comment.