1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "alloc-util.h"
8 #include "devnum-util.h"
13 int main(int argc
, char *argv
[]) {
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 r
= write_string_file("/sys/power/resume", FORMAT_DEVNUM(st
.st_rdev
), WRITE_STRING_FILE_DISABLE_BUFFER
);
45 log_error_errno(r
, "Failed to write '" DEVNUM_FORMAT_STR
"' to /sys/power/resume: %m", DEVNUM_FORMAT_VAL(st
.st_rdev
));
50 * The write above shall not return.
52 * However, failed resume is a normal condition (may mean that there is
53 * no hibernation image).
56 log_info("Could not resume from '%s' (" DEVNUM_FORMAT_STR
").", device
, DEVNUM_FORMAT_VAL(st
.st_rdev
));