]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/hibernate-resume/hibernate-resume-generator.c
01222db5167efca4e1d118e7dcab4a86eebb3bdc
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2014 Ivan Shapovalov
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "alloc-util.h"
25 #include "fstab-util.h"
28 #include "proc-cmdline.h"
30 #include "string-util.h"
31 #include "unit-name.h"
34 static const char *arg_dest
= "/tmp";
35 static char *arg_resume_device
= NULL
;
37 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
39 if (streq(key
, "resume")) {
42 if (proc_cmdline_value_missing(key
, value
))
45 s
= fstab_node_to_udev_node(value
);
49 free(arg_resume_device
);
50 arg_resume_device
= s
;
56 static int process_resume(void) {
57 _cleanup_free_
char *name
= NULL
, *lnk
= NULL
;
60 if (!arg_resume_device
)
63 r
= unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_device
, ".service", &name
);
65 return log_error_errno(r
, "Failed to generate unit name: %m");
67 lnk
= strjoin(arg_dest
, "/" SPECIAL_SYSINIT_TARGET
".wants/", name
);
71 mkdir_parents_label(lnk
, 0755);
72 if (symlink(SYSTEM_DATA_UNIT_PATH
"/systemd-hibernate-resume@.service", lnk
) < 0)
73 return log_error_errno(errno
, "Failed to create symlink %s: %m", lnk
);
78 int main(int argc
, char *argv
[]) {
81 if (argc
> 1 && argc
!= 4) {
82 log_error("This program takes three or no arguments.");
89 log_set_target(LOG_TARGET_SAFE
);
90 log_parse_environment();
95 /* Don't even consider resuming outside of initramfs. */
99 r
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
101 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
103 r
= process_resume();
104 free(arg_resume_device
);
106 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;