1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "alloc-util.h"
12 int main(int argc
, char *argv
[]) {
15 _cleanup_free_
char *major_minor
= NULL
;
19 log_error("This program expects one argument.");
27 /* Refuse to run unless we are in an initrd() */
33 if (stat(device
, &st
) < 0) {
34 log_error_errno(errno
, "Failed to stat '%s': %m", device
);
38 if (!S_ISBLK(st
.st_mode
)) {
39 log_error("Resume device '%s' is not a block device.", device
);
43 if (asprintf(&major_minor
, "%d:%d", major(st
.st_rdev
), minor(st
.st_rdev
)) < 0) {
48 r
= write_string_file("/sys/power/resume", major_minor
, WRITE_STRING_FILE_DISABLE_BUFFER
);
50 log_error_errno(r
, "Failed to write '%s' to /sys/power/resume: %m", major_minor
);
55 * The write above shall not return.
57 * However, failed resume is a normal condition (may mean that there is
58 * no hibernation image).
61 log_info("Could not resume from '%s' (%s).", device
, major_minor
);