cac0b95790
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 b453c447e0
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.
28 lines
1.2 KiB
C
28 lines
1.2 KiB
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
#pragma once
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "pager.h"
|
|
#include "static-destruct.h"
|
|
|
|
#define _DEFINE_MAIN_FUNCTION(impl, ret) \
|
|
int main(int argc, char *argv[]) { \
|
|
int r; \
|
|
r = impl(argc, argv); \
|
|
static_destruct(); \
|
|
pager_close(); \
|
|
return ret; \
|
|
}
|
|
|
|
/* Negative return values from impl are mapped to EXIT_FAILURE, and
|
|
* everything else means success! */
|
|
#define DEFINE_MAIN_FUNCTION(impl) \
|
|
_DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
|
|
|
|
/* 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 : r)
|