]>
Commit | Line | Data |
---|---|---|
5e332028 LP |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | #pragma once | |
3 | ||
4 | #include <stdlib.h> | |
5 | ||
a34c79d0 | 6 | #include "pager.h" |
8d38b8ad | 7 | #include "selinux-util.h" |
d1405af3 | 8 | #include "spawn-ask-password-agent.h" |
a6db3163 | 9 | #include "spawn-polkit-agent.h" |
8a4fdaf2 | 10 | #include "static-destruct.h" |
60ffa37a | 11 | #include "util.h" |
8a4fdaf2 | 12 | |
7a44c7e3 | 13 | #define _DEFINE_MAIN_FUNCTION(intro, impl, ret) \ |
5e332028 LP |
14 | int main(int argc, char *argv[]) { \ |
15 | int r; \ | |
60ffa37a | 16 | save_argc_argv(argc, argv); \ |
7a44c7e3 ZJS |
17 | intro; \ |
18 | r = impl; \ | |
d1405af3 | 19 | ask_password_agent_close(); \ |
a6db3163 | 20 | polkit_agent_close(); \ |
a34c79d0 | 21 | pager_close(); \ |
a0c6f3cb LP |
22 | mac_selinux_finish(); \ |
23 | static_destruct(); \ | |
ec5e5948 | 24 | return ret; \ |
5e332028 LP |
25 | } |
26 | ||
ec5e5948 ZJS |
27 | /* Negative return values from impl are mapped to EXIT_FAILURE, and |
28 | * everything else means success! */ | |
29 | #define DEFINE_MAIN_FUNCTION(impl) \ | |
7a44c7e3 | 30 | _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : EXIT_SUCCESS) |
ec5e5948 | 31 | |
cac0b957 ZJS |
32 | /* Zero is mapped to EXIT_SUCCESS, negative values are mapped to EXIT_FAILURE, |
33 | * and postive values are propagated. | |
34 | * Note: "true" means failure! */ | |
5e332028 | 35 | #define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \ |
7a44c7e3 | 36 | _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : r) |