]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/main-func: propagate all positive return values
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Nov 2018 08:49:42 +0000 (09:49 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Nov 2018 15:48:21 +0000 (16:48 +0100)
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
src/fsck/fsck.c

index 6417cc822aa0db13c67cc67b76e189a56ae5974e..24bf6c99bfad1a5878c449c6841cc7a1edba95ee 100644 (file)
@@ -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)
index b1ce210fcc7aaee2eb651fe8a8718faf147dfdf6..995cf92ef121cbd3ddfcfd75d1af26e68abf97a7 100644 (file)
@@ -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);