]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/hibernate-resume/hibernate-resume-generator.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "alloc-util.h"
7 #include "fstab-util.h"
10 #include "proc-cmdline.h"
12 #include "string-util.h"
13 #include "unit-name.h"
16 static const char *arg_dest
= "/tmp";
17 static char *arg_resume_device
= NULL
;
18 static bool arg_noresume
= false;
20 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
22 if (streq(key
, "resume")) {
25 if (proc_cmdline_value_missing(key
, value
))
28 s
= fstab_node_to_udev_node(value
);
32 free_and_replace(arg_resume_device
, s
);
34 } else if (streq(key
, "noresume")) {
36 log_warning("\"noresume\" kernel command line switch specified with an argument, ignoring.");
46 static int process_resume(void) {
47 _cleanup_free_
char *name
= NULL
, *lnk
= NULL
;
50 if (!arg_resume_device
)
53 r
= unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_device
, ".service", &name
);
55 return log_error_errno(r
, "Failed to generate unit name: %m");
57 lnk
= strjoin(arg_dest
, "/" SPECIAL_SYSINIT_TARGET
".wants/", name
);
61 mkdir_parents_label(lnk
, 0755);
62 if (symlink(SYSTEM_DATA_UNIT_PATH
"/systemd-hibernate-resume@.service", lnk
) < 0)
63 return log_error_errno(errno
, "Failed to create symlink %s: %m", lnk
);
68 int main(int argc
, char *argv
[]) {
71 log_set_prohibit_ipc(true);
72 log_set_target(LOG_TARGET_AUTO
);
73 log_parse_environment();
78 if (argc
> 1 && argc
!= 4) {
79 log_error("This program takes three or no arguments.");
86 /* Don't even consider resuming outside of initramfs. */
88 log_debug("Not running in an initrd, quitting.");
92 r
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
94 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
97 log_notice("Found \"noresume\" on the kernel command line, quitting.");
101 r
= process_resume();
102 free(arg_resume_device
);
104 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;