#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
-#include <linux/fiemap.h>
#include <poll.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <sys/timerfd.h>
+#include <sys/types.h>
#include <sys/utsname.h>
#include <unistd.h>
#include "battery-capacity.h"
#include "battery-util.h"
-#include "btrfs-util.h"
#include "build.h"
#include "bus-error.h"
#include "bus-locator.h"
static SleepOperation arg_operation = _SLEEP_OPERATION_INVALID;
-static int write_efi_hibernate_location(const HibernateLocation *hibernate_location, bool required) {
+static int write_efi_hibernate_location(const HibernationDevice *hibernation_device, bool required) {
int log_level = required ? LOG_ERR : LOG_DEBUG;
#if ENABLE_EFI
struct utsname uts = {};
int r, log_level_ignore = required ? LOG_WARNING : LOG_DEBUG;
- assert(hibernate_location);
- assert(hibernate_location->swap);
+ assert(hibernation_device);
if (!is_efi_boot())
return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
"Not an EFI boot, passing HibernateLocation via EFI variable is not possible.");
- r = sd_device_new_from_devnum(&device, 'b', hibernate_location->devno);
+ r = sd_device_new_from_devnum(&device, 'b', hibernation_device->devno);
if (r < 0)
return log_full_errno(log_level, r, "Failed to create sd-device object for '%s': %m",
- hibernate_location->swap->path);
+ hibernation_device->path);
r = sd_device_get_property_value(device, "ID_FS_UUID", &uuid_str);
if (r < 0)
return log_full_errno(log_level, r, "Failed to get filesystem UUID for device '%s': %m",
- hibernate_location->swap->path);
+ hibernation_device->path);
r = sd_id128_from_string(uuid_str, &uuid);
if (r < 0)
return log_full_errno(log_level, r, "Failed to parse ID_FS_UUID '%s' for device '%s': %m",
- uuid_str, hibernate_location->swap->path);
+ uuid_str, hibernation_device->path);
if (uname(&uts) < 0)
log_full_errno(log_level_ignore, errno, "Failed to get kernel info, ignoring: %m");
r = json_build(&v, JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_UUID("uuid", uuid),
- JSON_BUILD_PAIR_UNSIGNED("offset", hibernate_location->offset),
+ JSON_BUILD_PAIR_UNSIGNED("offset", hibernation_device->offset),
JSON_BUILD_PAIR_CONDITION(!isempty(uts.release), "kernelVersion", JSON_BUILD_STRING(uts.release)),
JSON_BUILD_PAIR_CONDITION(id, "osReleaseId", JSON_BUILD_STRING(id)),
JSON_BUILD_PAIR_CONDITION(image_id, "osReleaseImageId", JSON_BUILD_STRING(image_id)),
#endif
}
-static int write_kernel_hibernate_location(const HibernateLocation *hibernate_location) {
- assert(hibernate_location);
- assert(hibernate_location->swap);
- assert(IN_SET(hibernate_location->swap->type, SWAP_BLOCK, SWAP_FILE));
-
- return write_resume_config(hibernate_location->devno, hibernate_location->offset, hibernate_location->swap->path);
-}
-
static int write_mode(char **modes) {
int r = 0;
NULL
};
- _cleanup_(hibernate_location_freep) HibernateLocation *hibernate_location = NULL;
+ _cleanup_(hibernation_device_done) HibernationDevice hibernation_device = {};
_cleanup_fclose_ FILE *f = NULL;
char **modes, **states;
int r;
setvbuf(f, NULL, _IONBF, 0);
/* Configure hibernation settings if we are supposed to hibernate */
- if (!strv_isempty(modes)) {
+ if (sleep_operation_is_hibernation(operation)) {
bool resume_set;
- r = find_hibernate_location(&hibernate_location);
+ r = find_suitable_hibernation_device(&hibernation_device);
if (r < 0)
return log_error_errno(r, "Failed to find location to hibernate to: %m");
resume_set = r > 0;
- r = write_efi_hibernate_location(hibernate_location, !resume_set);
+ r = write_efi_hibernate_location(&hibernation_device, !resume_set);
if (!resume_set) {
if (r == -EOPNOTSUPP)
return log_error_errno(r, "No valid 'resume=' option found, refusing to hibernate.");
if (r < 0)
return r;
- r = write_kernel_hibernate_location(hibernate_location);
+ r = write_resume_config(hibernation_device.devno, hibernation_device.offset, hibernation_device.path);
if (r < 0) {
if (is_efi_boot())
(void) efi_set_variable(EFI_SYSTEMD_VARIABLE(HibernateLocation), NULL, 0);
}
static int parse_argv(int argc, char *argv[]) {
+
enum {
ARG_VERSION = 0x100,
};
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
switch (c) {
+
case 'h':
return help();
default:
assert_not_reached();
+
}
if (argc - optind != 1)
default:
r = execute(sleep_config, arg_operation, NULL);
break;
+
}
return r;