]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/main-func.h
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / shared / main-func.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <stdlib.h>
5
6 #include "pager.h"
7 #include "selinux-util.h"
8 #include "spawn-ask-password-agent.h"
9 #include "spawn-polkit-agent.h"
10 #include "static-destruct.h"
11
12 #define _DEFINE_MAIN_FUNCTION(intro, impl, ret) \
13 int main(int argc, char *argv[]) { \
14 int r; \
15 intro; \
16 r = impl; \
17 static_destruct(); \
18 ask_password_agent_close(); \
19 polkit_agent_close(); \
20 mac_selinux_finish(); \
21 pager_close(); \
22 return ret; \
23 }
24
25 /* Negative return values from impl are mapped to EXIT_FAILURE, and
26 * everything else means success! */
27 #define DEFINE_MAIN_FUNCTION(impl) \
28 _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
29
30 /* Zero is mapped to EXIT_SUCCESS, negative values are mapped to EXIT_FAILURE,
31 * and postive values are propagated.
32 * Note: "true" means failure! */
33 #define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
34 _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : r)