]>
git.proxmox.com Git - systemd.git/blob - src/hibernate-resume/hibernate-resume-generator.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Ivan Shapovalov
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
29 #include "unit-name.h"
31 static const char *arg_dest
= "/tmp";
32 static char *arg_resume_dev
= NULL
;
34 static int parse_proc_cmdline_item(const char *key
, const char *value
) {
35 if (streq(key
, "resume") && value
) {
37 arg_resume_dev
= fstab_node_to_udev_node(value
);
45 static int process_resume(void) {
46 _cleanup_free_
char *name
= NULL
, *lnk
= NULL
;
51 name
= unit_name_from_path_instance("systemd-hibernate-resume", arg_resume_dev
, ".service");
55 lnk
= strjoin(arg_dest
, "/" SPECIAL_SYSINIT_TARGET
".wants/", name
, NULL
);
59 mkdir_parents_label(lnk
, 0755);
60 if (symlink(SYSTEM_DATA_UNIT_PATH
"/systemd-hibernate-resume@.service", lnk
) < 0)
61 return log_error_errno(errno
, "Failed to create symlink %s: %m", lnk
);
66 int main(int argc
, char *argv
[]) {
69 if (argc
> 1 && argc
!= 4) {
70 log_error("This program takes three or no arguments.");
77 log_set_target(LOG_TARGET_SAFE
);
78 log_parse_environment();
83 /* Don't even consider resuming outside of initramfs. */
87 r
= parse_proc_cmdline(parse_proc_cmdline_item
);
89 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
94 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;