]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/hibernate-resume/hibernate-resume.c
1cfd55c2cf2f0638f6089821781b4141f4f9affe
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2014 Ivan Shapovalov
10 #include "alloc-util.h"
15 int main(int argc
, char *argv
[]) {
18 _cleanup_free_
char *major_minor
= NULL
;
22 log_error("This program expects one argument.");
26 log_set_target(LOG_TARGET_AUTO
);
27 log_parse_environment();
32 /* Refuse to run unless we are in an initrd() */
38 if (stat(device
, &st
) < 0) {
39 log_error_errno(errno
, "Failed to stat '%s': %m", device
);
43 if (!S_ISBLK(st
.st_mode
)) {
44 log_error("Resume device '%s' is not a block device.", device
);
48 if (asprintf(&major_minor
, "%d:%d", major(st
.st_rdev
), minor(st
.st_rdev
)) < 0) {
53 r
= write_string_file("/sys/power/resume", major_minor
, WRITE_STRING_FILE_CREATE
);
55 log_error_errno(r
, "Failed to write '%s' to /sys/power/resume: %m", major_minor
);
60 * The write above shall not return.
62 * However, failed resume is a normal condition (may mean that there is
63 * no hibernation image).
66 log_info("Could not resume from '%s' (%s).", device
, major_minor
);