From b72571e04dd6e63adcd4a03ef0b83d995623d476 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 25 Oct 2019 17:10:47 +0200 Subject: [PATCH] shared/sleep-config: two more error handling fixes, use structured initialization CID#1406472. --- src/shared/sleep-config.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 3ead397979b..e8f61b36e9c 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -234,7 +234,7 @@ static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offse btrfs = btrfs_is_filesystem(fd); if (btrfs < 0) - return log_error_errno(r, "Error checking %s for Btrfs filesystem: %m", swap->device); + return log_error_errno(btrfs, "Error checking %s for Btrfs filesystem: %m", swap->device); else if (btrfs > 0) { log_debug("Detection of swap file offset on Btrfs is not supported: %s; skipping", swap->device); *ret_offset = 0; @@ -260,15 +260,14 @@ static int read_resume_files(char **ret_resume, uint64_t *ret_resume_offset) { return log_debug_errno(r, "Error reading from /sys/power/resume: %m"); r = read_one_line_file("/sys/power/resume_offset", &resume_offset_str); - if (r < 0) { - if (r == -ENOENT) - log_debug("Kernel does not support resume_offset; swap file offset detection will be skipped."); - else - return log_debug_errno(r, "Error reading from /sys/power/resume_offset: %m"); - } else { + if (r == -ENOENT) + log_debug("Kernel does not support resume_offset; swap file offset detection will be skipped."); + else if (r < 0) + return log_debug_errno(r, "Error reading from /sys/power/resume_offset: %m"); + else { r = safe_atou64(resume_offset_str, &resume_offset); if (r < 0) - return log_error_errno(r, "Failed to parse 'resume_offset' from string: %s", resume_offset_str); + return log_error_errno(r, "Failed to parse value in /sys/power/resume_offset \"%s\": %m", resume_offset_str); } if (resume_offset > 0 && streq(*ret_resume, "0:0")) { @@ -300,7 +299,7 @@ static bool location_is_resume_device(const HibernateLocation *location, const c * negative value in the case of error */ int find_hibernate_location(HibernateLocation **ret_hibernate_location) { - _cleanup_fclose_ FILE *f; + _cleanup_fclose_ FILE *f = NULL; _cleanup_(hibernate_location_freep) HibernateLocation *hibernate_location = NULL; _cleanup_free_ char *sys_resume = NULL; uint64_t sys_offset = 0; @@ -376,13 +375,15 @@ int find_hibernate_location(HibernateLocation **ret_hibernate_location) { return r; hibernate_location = hibernate_location_free(hibernate_location); - hibernate_location = new0(HibernateLocation, 1); + hibernate_location = new(HibernateLocation, 1); if (!hibernate_location) return log_oom(); - hibernate_location->resume = TAKE_PTR(swap_device_id); - hibernate_location->resume_offset = swap_offset; - hibernate_location->swap = TAKE_PTR(swap); + *hibernate_location = (HibernateLocation) { + .resume = TAKE_PTR(swap_device_id), + .resume_offset = swap_offset, + .swap = TAKE_PTR(swap), + }; /* if the swap is the resume device, stop looping swaps */ if (location_is_resume_device(hibernate_location, sys_resume, sys_offset)) -- 2.39.2