summaryrefslogtreecommitdiff
path: root/src/sleep
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-20 23:40:44 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-22 10:54:38 +0100
commitbaaa35ad706419ae5aacc11d2bece5bd8b73ee42 (patch)
treebb4b9c576fc56b3237d59e959ded7c245917fcd7 /src/sleep
parent52d86690d68779b120a4380f7cc740825827fb0d (diff)
downloadsystemd-baaa35ad706419ae5aacc11d2bece5bd8b73ee42.tar.gz
coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any option in coccinelle for this, so instead, I edited the patch text using search&replace to remove the braces. Unfortunately this is not fully automatic, in particular it didn't deal well with if-else-if-else blocks and ifdefs, so there is an increased likelikehood be some bugs in such spots. I also removed part of the patch that coccinelle generated for udev, where we returns -1 for failure. This should be fixed independently.
Diffstat (limited to 'src/sleep')
-rw-r--r--src/sleep/sleep.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 9e4831e35f..5b7984a6f2 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -49,10 +49,9 @@ static int write_hibernate_location_info(void) {
return r;
}
- if (!streq(type, "file")) {
- log_debug("Invalid hibernate type: %s", type);
- return -EINVAL;
- }
+ if (!streq(type, "file"))
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Invalid hibernate type: %s", type);
/* Only available in 4.17+ */
if (access("/sys/power/resume_offset", W_OK) < 0) {
@@ -74,10 +73,9 @@ static int write_hibernate_location_info(void) {
r = read_fiemap(fd, &fiemap);
if (r < 0)
return log_debug_errno(r, "Unable to read extent map for '%s': %m", device);
- if (fiemap->fm_mapped_extents == 0) {
- log_debug("No extents found in '%s'", device);
- return -EINVAL;
- }
+ if (fiemap->fm_mapped_extents == 0)
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+ "No extents found in '%s'", device);
offset = fiemap->fm_extents[0].fe_physical / page_size();
xsprintf(offset_str, "%" PRIu64, offset);
@@ -336,18 +334,16 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (argc - optind != 1) {
- log_error("Usage: %s COMMAND",
- program_invocation_short_name);
- return -EINVAL;
- }
+ if (argc - optind != 1)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Usage: %s COMMAND",
+ program_invocation_short_name);
arg_verb = argv[optind];
- if (!STR_IN_SET(arg_verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate")) {
- log_error("Unknown command '%s'.", arg_verb);
- return -EINVAL;
- }
+ if (!STR_IN_SET(arg_verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate"))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Unknown command '%s'.", arg_verb);
return 1 /* work to do */;
}
@@ -368,10 +364,10 @@ static int run(int argc, char *argv[]) {
if (r < 0)
return r;
- if (!allow) {
- log_error("Sleep mode \"%s\" is disabled by configuration, refusing.", arg_verb);
- return -EACCES;
- }
+ if (!allow)
+ return log_error_errno(SYNTHETIC_ERRNO(EACCES),
+ "Sleep mode \"%s\" is disabled by configuration, refusing.",
+ arg_verb);
if (streq(arg_verb, "suspend-then-hibernate"))
return execute_s2h(delay);