summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-01-07 16:20:35 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-01-07 16:20:35 +0100
commite9f0c5d08c6590c37d92dbdcf402706613d6daeb (patch)
treee99cd4d2f2dd57cdbf7b8f37b03d6a4b73778d95 /src
parent52133271a7b3d76bed6d957f75371030193f5282 (diff)
downloadsystemd-e9f0c5d08c6590c37d92dbdcf402706613d6daeb.tar.gz
shared/sleep: use stat() instead of open()+fstat() in one place
No functional change.
Diffstat (limited to 'src')
-rw-r--r--src/shared/sleep-config.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index f92924bf73..f1f4d6dd00 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -186,36 +186,25 @@ HibernateLocation* hibernate_location_free(HibernateLocation *hl) {
}
static int swap_device_to_device_id(const SwapEntry *swap, dev_t *ret_dev) {
- _cleanup_close_ int fd = -1;
struct stat sb;
- dev_t swap_dev;
int r;
assert(swap);
assert(swap->device);
assert(swap->type);
- fd = open(swap->device, O_RDONLY | O_CLOEXEC | O_NONBLOCK);
- if (fd < 0)
- return log_debug_errno(errno, "Unable to open '%s': %m", swap->device);
-
- r = fstat(fd, &sb);
+ r = stat(swap->device, &sb);
if (r < 0)
return log_debug_errno(errno, "Unable to stat %s: %m", swap->device);
if (streq(swap->type, "partition")) {
- if(!S_ISBLK(sb.st_mode))
+ if (!S_ISBLK(sb.st_mode))
return -ENOTBLK;
- swap_dev = sb.st_rdev;
- } else {
- r = get_block_device(swap->device, &swap_dev);
- if (r < 0)
- return r;
- }
-
- *ret_dev = swap_dev;
+ *ret_dev = sb.st_rdev;
+ return 0;
- return 0;
+ } else
+ return get_block_device(swap->device, ret_dev);
}
/*