]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/main-func.h
logind: when we cannot attach a passed fd to a device, close it
[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 #include "util.h"
12
13 #define _DEFINE_MAIN_FUNCTION(intro, impl, ret) \
14 int main(int argc, char *argv[]) { \
15 int r; \
16 save_argc_argv(argc, argv); \
17 intro; \
18 r = impl; \
19 ask_password_agent_close(); \
20 polkit_agent_close(); \
21 pager_close(); \
22 mac_selinux_finish(); \
23 static_destruct(); \
24 return ret; \
25 }
26
27 /* Negative return values from impl are mapped to EXIT_FAILURE, and
28 * everything else means success! */
29 #define DEFINE_MAIN_FUNCTION(impl) \
30 _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
31
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! */
35 #define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
36 _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : r)