]>
git.ipfire.org Git - thirdparty/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_device
= NULL
;
36 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
38 if (streq(key
, "resume")) {
41 if (proc_cmdline_value_missing(key
, value
))
44 s
= fstab_node_to_udev_node(value
);
48 free(arg_resume_device
);
49 arg_resume_device
= s
;
55 static int process_resume(void) {
56 _cleanup_free_
char *name
= NULL
, *lnk
= NULL
;
59 if (!arg_resume_device
)
62 r
= unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_device
, ".service", &name
);
64 return log_error_errno(r
, "Failed to generate unit name: %m");
66 lnk
= strjoin(arg_dest
, "/" SPECIAL_SYSINIT_TARGET
".wants/", name
);
70 mkdir_parents_label(lnk
, 0755);
71 if (symlink(SYSTEM_DATA_UNIT_PATH
"/systemd-hibernate-resume@.service", lnk
) < 0)
72 return log_error_errno(errno
, "Failed to create symlink %s: %m", lnk
);
77 int main(int argc
, char *argv
[]) {
80 if (argc
> 1 && argc
!= 4) {
81 log_error("This program takes three or no arguments.");
88 log_set_target(LOG_TARGET_SAFE
);
89 log_parse_environment();
94 /* Don't even consider resuming outside of initramfs. */
98 r
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
100 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
102 r
= process_resume();
103 free(arg_resume_device
);
105 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;