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/>.
24 #include <sys/types.h>
32 int main(int argc, char *argv[]) {
35 _cleanup_free_ char *major_minor = NULL;
39 log_error("This program expects one argument.");
43 log_set_target(LOG_TARGET_AUTO);
44 log_parse_environment();
49 /* Refuse to run unless we are in an initrd() */
55 if (stat(device, &st) < 0) {
56 log_error_errno(errno, "Failed to stat '%s': %m", device);
60 if (!S_ISBLK(st.st_mode)) {
61 log_error("Resume device '%s' is not a block device.", device);
65 if (asprintf(&major_minor, "%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0) {
70 r = write_string_file("/sys/power/resume", major_minor);
72 log_error_errno(r, "Failed to write '%s' to /sys/power/resume: %m", major_minor);
77 * The write above shall not return.
79 * However, failed resume is a normal condition (may mean that there is
80 * no hibernation image).
83 log_info("Could not resume from '%s' (%s).", device, major_minor);