[systemd-devel] [PATCH] Support system freeze

Cristian Rodríguez crrodriguez at opensuse.org
Thu Feb 28 17:22:38 PST 2013


As implemented in kernel 3.9

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commit;h=7e73c5ae6e7991a6c01f6d096ff8afaef4458c36
---
 Makefile.am                     |  2 ++
 man/systemd-suspend.service.xml | 19 ++++++++++++++-----
 src/sleep/sleep.c               |  8 ++++++++
 units/freeze.target             | 13 +++++++++++++
 units/systemd-freeze.service.in | 17 +++++++++++++++++
 5 files changed, 54 insertions(+), 5 deletions(-)
 create mode 100644 units/freeze.target
 create mode 100644 units/systemd-freeze.service.in

diff --git a/Makefile.am b/Makefile.am
index d00ca11..b540b12 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -359,6 +359,7 @@ dist_systemunit_DATA = \
 	units/sleep.target \
 	units/sockets.target \
 	units/suspend.target \
+	units/freeze.target \
 	units/swap.target \
 	units/systemd-initctl.socket \
 	units/systemd-shutdownd.socket \
@@ -452,6 +453,7 @@ EXTRA_DIST += \
 	units/systemd-hibernate.service.in \
 	units/systemd-hybrid-sleep.service.in \
 	units/systemd-suspend.service.in \
+	units/systemd-freeze.service.in \
 	units/quotaon.service.in \
 	introspect.awk \
 	man/custom-html.xsl
diff --git a/man/systemd-suspend.service.xml b/man/systemd-suspend.service.xml
index 9b8bad4..97806d5 100644
--- a/man/systemd-suspend.service.xml
+++ b/man/systemd-suspend.service.xml
@@ -46,6 +46,7 @@
                 <refname>systemd-suspend.service</refname>
                 <refname>systemd-hibernate.service</refname>
                 <refname>systemd-hybrid-sleep.service</refname>
+                <refname>systemd-freeze.service</refname>
                 <refname>systemd-sleep</refname>
                 <refpurpose>System sleep state logic</refpurpose>
         </refnamediv>
@@ -54,6 +55,7 @@
                 <para><filename>systemd-suspend.service</filename></para>
                 <para><filename>systemd-hibernate.service</filename></para>
                 <para><filename>systemd-hybrid-sleep.service</filename></para>
+                <para><filename>systemd-freeze.service</filename></para>
                 <para><filename>/usr/lib/systemd/systemd-sleep</filename></para>
         </refsynopsisdiv>
 
@@ -66,11 +68,14 @@
                 for the actual system suspend. Similar,
                 <filename>systemd-hibernate.service</filename> is
                 pulled in by <filename>hibernate.target</filename> to
-                execute the actual hibernation. Finally,
+                execute the actual hibernation.
                 <filename>systemd-hybrid-sleep.service</filename> is
                 pulled in by <filename>hybrid-sleep.target</filename>
                 to execute hybrid hibernation with system
-                suspend.</para>
+                suspend.
+                <filename>systemd-freeze.service</filename> is
+                pulled in by <filename>freeze.target</filename>
+                to execute a system freeze.</para>
 
                 <para>Immediately before entering system suspend
                 and/or hibernation
@@ -81,8 +86,9 @@
                 and pass two arguments to them. The first argument
                 will be "<literal>pre</literal>", the second either
                 "<literal>suspend</literal>",
-                "<literal>hibernate</literal>", or
-                "<literal>hybrid-sleep</literal>" depending on the
+                "<literal>hibernate</literal>",
+                "<literal>hybrid-sleep</literal>" or
+                "<literal>freeze</literal>" depending on the
                 chosen action. Immediately after leaving system
                 suspend and/or hibernation the same executables are run,
                 but the first argument is now
@@ -100,7 +106,8 @@
 
                 <para>Note that
                 <filename>systemd-suspend.service</filename>,
-                <filename>systemd-hibernate.service</filename> and
+                <filename>systemd-hibernate.service</filename>,
+                <filename>systemd-freeze.service</filename> and
                 <filename>systemd-hybrid-sleep.service</filename>
                 should never be executed directly. Instead, trigger
                 system sleep states with a command such as
@@ -111,6 +118,8 @@
                 <literal>mem</literal> into
                 <filename>/sys/power/state</filename>, to trigger the
                 actual system suspend.</para>
+
+                <para>System freeze is only supported in kernel 3.9 or later.</para>
         </refsect1>
 
         <refsect1>
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 0707625..a80f3fb 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -49,6 +49,8 @@ int main(int argc, char *argv[]) {
                 verb = "mem";
         else if (streq(argv[1], "hibernate") || streq(argv[1], "hybrid-sleep"))
                 verb = "disk";
+        else if(streq(argv[1], "freeze"))
+                verb = "freeze";
         else {
                 log_error("Unknown action '%s'.", argv[1]);
                 r = -EINVAL;
@@ -90,6 +92,12 @@ int main(int argc, char *argv[]) {
                            "MESSAGE=Hibernating system...",
                            "SLEEP=hibernate",
                            NULL);
+        else if (streq(argv[1], "freeze"))
+                log_struct(LOG_INFO,
+                           MESSAGE_ID(SD_MESSAGE_SLEEP_START),
+                           "MESSAGE=Freezing system...",
+                           "SLEEP=freeze",
+                           NULL);
         else
                 log_struct(LOG_INFO,
                            MESSAGE_ID(SD_MESSAGE_SLEEP_START),
diff --git a/units/freeze.target b/units/freeze.target
new file mode 100644
index 0000000..5bd0bd7
--- /dev/null
+++ b/units/freeze.target
@@ -0,0 +1,13 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Freeze
+Documentation=man:systemd.special(7)
+DefaultDependencies=no
+RefuseManualStart=yes
+StopWhenUnneeded=yes
diff --git a/units/systemd-freeze.service.in b/units/systemd-freeze.service.in
new file mode 100644
index 0000000..842d7cf
--- /dev/null
+++ b/units/systemd-freeze.service.in
@@ -0,0 +1,17 @@
+#  This file is part of systemd.
+#
+#  systemd is free software; you can redistribute it and/or modify it
+#  under the terms of the GNU Lesser General Public License as published by
+#  the Free Software Foundation; either version 2.1 of the License, or
+#  (at your option) any later version.
+
+[Unit]
+Description=Freeze
+Documentation=man:systemd-suspend.service(8)
+DefaultDependencies=no
+Requires=freeze.target
+After=freeze.target
+
+[Service]
+Type=oneshot
+ExecStart=@rootlibexecdir@/systemd-sleep freeze
-- 
1.8.1.4



More information about the systemd-devel mailing list