From cac0b957906f282b4a54e28187f24d4789aa2bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 20 Nov 2018 09:49:42 +0100 Subject: [PATCH] basic/main-func: propagate all positive return values This changes DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE() to propagate positive return values as they were, i.e. stops mapping them all to EXIT_FAILURE. This was suggested in review, but I thought that we only ever return EXIT_FAILURE, so we don't need to propagate multiple return values. I was wrong. Turns out that we already *do* have multiple positive return values, when we call external binaries and propagate the result. systemd-inhibit is one example, and b453c447e0fb4a1e9eccd42120731c1700220b21 actually broke this propagation. This commit fixes it. In systemd-fsck we have the opposite case: we have only one failure value, and the code needs to be adjusted, so that it keeps returning EXIT_FAILURE. All other users of DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE() return <= 1, and are unaffected by this change. --- src/basic/main-func.h | 8 ++++---- src/fsck/fsck.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/basic/main-func.h b/src/basic/main-func.h index 6417cc822aa..24bf6c99bfa 100644 --- a/src/basic/main-func.h +++ b/src/basic/main-func.h @@ -20,8 +20,8 @@ #define DEFINE_MAIN_FUNCTION(impl) \ _DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : EXIT_SUCCESS) -/* Zero is mapped to EXIT_SUCCESS, and both negative and positive values - * are mapped to EXIT_FAILURE. - * Note: this means "true" maps to EXIT_FAILURE. */ +/* Zero is mapped to EXIT_SUCCESS, negative values are mapped to EXIT_FAILURE, + * and postive values are propagated. + * Note: "true" means failure! */ #define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \ - _DEFINE_MAIN_FUNCTION(impl, r != 0 ? EXIT_FAILURE : EXIT_SUCCESS) + _DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : r) diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index b1ce210fcc7..995cf92ef12 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -428,7 +428,7 @@ static int run(int argc, char *argv[]) { if (exit_status & FSCK_ERROR_CORRECTED) (void) touch("/run/systemd/quotacheck"); - return exit_status & (FSCK_SYSTEM_SHOULD_REBOOT | FSCK_ERRORS_LEFT_UNCORRECTED); + return !!(exit_status & (FSCK_SYSTEM_SHOULD_REBOOT | FSCK_ERRORS_LEFT_UNCORRECTED)); } DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);