]>
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 "main-func.h"
12 #include "proc-cmdline.h"
14 #include "string-util.h"
15 #include "unit-name.h"
18 static const char *arg_dest
= "/tmp";
19 static char *arg_resume_device
= NULL
;
20 static bool arg_noresume
= false;
22 STATIC_DESTRUCTOR_REGISTER(arg_resume_device
, freep
);
24 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
26 if (streq(key
, "resume")) {
29 if (proc_cmdline_value_missing(key
, value
))
32 s
= fstab_node_to_udev_node(value
);
36 free_and_replace(arg_resume_device
, s
);
38 } else if (streq(key
, "noresume")) {
40 log_warning("\"noresume\" kernel command line switch specified with an argument, ignoring.");
50 static int process_resume(void) {
51 _cleanup_free_
char *name
= NULL
, *lnk
= NULL
;
54 if (!arg_resume_device
)
57 r
= unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_device
, ".service", &name
);
59 return log_error_errno(r
, "Failed to generate unit name: %m");
61 lnk
= strjoin(arg_dest
, "/" SPECIAL_SYSINIT_TARGET
".wants/", name
);
65 mkdir_parents_label(lnk
, 0755);
66 if (symlink(SYSTEM_DATA_UNIT_PATH
"/systemd-hibernate-resume@.service", lnk
) < 0)
67 return log_error_errno(errno
, "Failed to create symlink %s: %m", lnk
);
72 static int run(int argc
, char *argv
[]) {
75 log_setup_generator();
79 if (argc
> 1 && argc
!= 4) {
80 log_error("This program takes three or no arguments.");
87 /* Don't even consider resuming outside of initramfs. */
89 log_debug("Not running in an initrd, quitting.");
93 r
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
95 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
98 log_notice("Found \"noresume\" on the kernel command line, quitting.");
102 return process_resume();
105 DEFINE_MAIN_FUNCTION(run
);