resume-generator understands resume= kernel command line parameter and instantiates the systemd-resume@.service accordingly if it is passed.
This enables resume from hibernation using device specified on the kernel command line, where the device path may point to an arbitrary udev-created symlink, not only "/dev/sdXY" which is understood by the in-kernel implementation. --- Makefile-man.am | 2 + man/kernel-command-line.xml | 13 ++++- man/systemd-resume-generator.xml | 91 ++++++++++++++++++++++++++++++++ src/resume-generator/Makefile | 1 + src/resume-generator/resume-generator.c | 93 +++++++++++++++++++++++++++++++++ 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 man/systemd-resume-generator.xml create mode 120000 src/resume-generator/Makefile create mode 100644 src/resume-generator/resume-generator.c diff --git a/Makefile-man.am b/Makefile-man.am index be19905..00daae2 100644 --- a/Makefile-man.am +++ b/Makefile-man.am @@ -76,6 +76,7 @@ MANPAGES += \ man/systemd-nspawn.1 \ man/systemd-path.1 \ man/systemd-remount-fs.service.8 \ + man/systemd-resume-generator.8 \ man/systemd-resume@.service.8 \ man/systemd-run.1 \ man/systemd-shutdownd.service.8 \ @@ -1632,6 +1633,7 @@ EXTRA_DIST += \ man/systemd-readahead-replay.service.xml \ man/systemd-remount-fs.service.xml \ man/systemd-resolved.service.xml \ + man/systemd-resume-generator.xml \ man/systemd-res...@.service.xml \ man/systemd-rfk...@.service.xml \ man/systemd-run.xml \ diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml index f244bfc..4bc6cee 100644 --- a/man/kernel-command-line.xml +++ b/man/kernel-command-line.xml @@ -351,6 +351,16 @@ </listitem> </varlistentry> + <varlistentry> + <term><varname>resume=</varname></term> + + <listitem> + <para>Enables resume from hibernation + using the specified device. For + details, see + <citerefentry><refentrytitle>systemd-resume-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para> + </listitem> + </varlistentry> </variablelist> </refsect1> @@ -373,7 +383,8 @@ <citerefentry><refentrytitle>systemd-gpt-auto-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd-modules-load.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, <citerefentry><refentrytitle>systemd-backlight@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, - <citerefentry><refentrytitle>systemd-rfkill@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> + <citerefentry><refentrytitle>systemd-rfkill@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd-resume-generator</refentrytitle><manvolnum>8</manvolnum></citerefentry> </para> </refsect1> diff --git a/man/systemd-resume-generator.xml b/man/systemd-resume-generator.xml new file mode 100644 index 0000000..7962534 --- /dev/null +++ b/man/systemd-resume-generator.xml @@ -0,0 +1,91 @@ +<?xml version="1.0"?> +<!--*-nxml-*--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> +<!-- + This file is part of systemd. + + Copyright 2014 Ivan Shapovalov + + 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. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +--> +<refentry id="systemd-resume-generator"> + + <refentryinfo> + <title>systemd-resume-generator</title> + <productname>systemd</productname> + + <authorgroup> + <author> + <contrib>Developer</contrib> + <firstname>Ivan</firstname> + <surname>Shapovalov</surname> + <email>intelfx...@gmail.com</email> + </author> + </authorgroup> + </refentryinfo> + + <refmeta> + <refentrytitle>systemd-resume-generator</refentrytitle> + <manvolnum>8</manvolnum> + </refmeta> + + <refnamediv> + <refname>systemd-resume-generator</refname> + <refpurpose>Unit generator for resume= kernel parameter</refpurpose> + </refnamediv> + + <refsynopsisdiv> + <para><filename>/usr/lib/systemd/system-generators/systemd-resume-generator</filename></para> + </refsynopsisdiv> + + <refsect1> + <title>Description</title> + + <para><filename>systemd-resume-generator</filename> is + a generator that instantiates + <citerefentry><refentrytitle>systemd-resume@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry> + unit according to the value of <option>resume=</option> + parameter specified on the kernel command line.</para> + </refsect1> + + <refsect1> + <title>Kernel Command Line</title> + + <para><filename>systemd-resume-generator</filename> understands + the following kernel command line parameters:</para> + + <variablelist class='kernel-commandline-options'> + + <varlistentry> + <term><varname>resume=</varname></term> + + <listitem><para>Takes a path to the resume + device. May point to any udev-created symlink, + including persistent block device pathes like + <filename>/dev/disk/by-label/foo</filename>.</para></listitem> + </varlistentry> + + </variablelist> + </refsect1> + + <refsect1> + <title>See Also</title> + <para> + <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, + <citerefentry><refentrytitle>systemd-resume@.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>, + <citerefentry><refentrytitle>kernel-command-line</refentrytitle><manvolnum>7</manvolnum></citerefentry> + </para> + </refsect1> + +</refentry> diff --git a/src/resume-generator/Makefile b/src/resume-generator/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/src/resume-generator/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/src/resume-generator/resume-generator.c b/src/resume-generator/resume-generator.c new file mode 100644 index 0000000..0f42b3b --- /dev/null +++ b/src/resume-generator/resume-generator.c @@ -0,0 +1,93 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +/*** + This file is part of systemd. + + Copyright 2014 Ivan Shapovalov + + 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. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <stdio.h> +#include <errno.h> + +#include "log.h" +#include "util.h" +#include "special.h" +#include "mkdir.h" +#include "unit-name.h" + +static const char *arg_dest = "/tmp"; +static char *arg_resume_dev = NULL; + +static int parse_proc_cmdline_item(const char *key, const char *value) { + if (streq(key, "resume") && value) { + free(arg_resume_dev); + arg_resume_dev = strdup(value); + if (!arg_resume_dev) + return log_oom(); + } + + return 0; +} + +static int process_resume(void) { + _cleanup_free_ char *name = NULL, *lnk = NULL; + + name = unit_name_from_path_instance("systemd-resume", arg_resume_dev, ".service"); + if (!name) + return log_oom(); + + lnk = strjoin(arg_dest, "/" SPECIAL_SYSINIT_TARGET ".wants/", name, NULL); + if (!lnk) + return log_oom(); + + mkdir_parents_label(lnk, 0755); + if (symlink(SYSTEM_DATA_UNIT_PATH "/systemd-resume@.service", lnk) < 0) { + log_error("Failed to create symlink %s: %m", lnk); + return -errno; + } +} + +int main(int argc, char *argv[]) { + int r = 0; + + if (argc > 1 && argc != 4) { + log_error("This program takes three or no arguments."); + return EXIT_FAILURE; + } + + if (argc > 1) + arg_dest = argv[1]; + + log_set_target(LOG_TARGET_SAFE); + log_parse_environment(); + log_open(); + + umask(0022); + + /* Don't even consider resuming outside of initramfs. */ + if (!in_initrd()) + return EXIT_SUCCESS; + + if (parse_proc_cmdline(parse_proc_cmdline_item) < 0) + return EXIT_FAILURE; + + if (arg_resume_dev != NULL) + r = process_resume(); + + free(arg_resume_dev); + + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} -- 2.1.0 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel