]>
git.proxmox.com Git - systemd.git/blob - src/hibernate-resume/hibernate-resume-generator.c
2 This file is part of systemd.
4 Copyright 2014 Ivan Shapovalov
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include "alloc-util.h"
24 #include "fstab-util.h"
27 #include "proc-cmdline.h"
29 #include "string-util.h"
30 #include "unit-name.h"
33 static const char *arg_dest
= "/tmp";
34 static char *arg_resume_dev
= NULL
;
36 static int parse_proc_cmdline_item(const char *key
, const char *value
) {
38 if (streq(key
, "resume") && value
) {
40 arg_resume_dev
= fstab_node_to_udev_node(value
);
48 static int process_resume(void) {
49 _cleanup_free_
char *name
= NULL
, *lnk
= NULL
;
55 r
= unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_dev
, ".service", &name
);
57 return log_error_errno(r
, "Failed to generate unit name: %m");
59 lnk
= strjoin(arg_dest
, "/" SPECIAL_SYSINIT_TARGET
".wants/", name
, NULL
);
63 mkdir_parents_label(lnk
, 0755);
64 if (symlink(SYSTEM_DATA_UNIT_PATH
"/systemd-hibernate-resume@.service", lnk
) < 0)
65 return log_error_errno(errno
, "Failed to create symlink %s: %m", lnk
);
70 int main(int argc
, char *argv
[]) {
73 if (argc
> 1 && argc
!= 4) {
74 log_error("This program takes three or no arguments.");
81 log_set_target(LOG_TARGET_SAFE
);
82 log_parse_environment();
87 /* Don't even consider resuming outside of initramfs. */
91 r
= parse_proc_cmdline(parse_proc_cmdline_item
);
93 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
98 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;