2020-11-09 05:23:58 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
2018-11-19 20:26:37 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-05-17 10:17:06 +02:00
|
|
|
#include "sd-daemon.h"
|
|
|
|
|
2018-11-20 14:03:46 +01:00
|
|
|
#include "pager.h"
|
2018-11-20 16:40:49 +01:00
|
|
|
#include "selinux-util.h"
|
2018-11-20 10:22:26 +01:00
|
|
|
#include "spawn-ask-password-agent.h"
|
2018-11-20 15:52:40 +01:00
|
|
|
#include "spawn-polkit-agent.h"
|
2018-11-19 20:47:46 +01:00
|
|
|
#include "static-destruct.h"
|
2019-03-15 14:49:43 +01:00
|
|
|
#include "util.h"
|
2018-11-19 20:47:46 +01:00
|
|
|
|
2018-12-04 11:49:42 +01:00
|
|
|
#define _DEFINE_MAIN_FUNCTION(intro, impl, ret) \
|
2018-11-19 20:26:37 +01:00
|
|
|
int main(int argc, char *argv[]) { \
|
|
|
|
int r; \
|
2019-03-15 14:49:43 +01:00
|
|
|
save_argc_argv(argc, argv); \
|
2018-12-04 11:49:42 +01:00
|
|
|
intro; \
|
|
|
|
r = impl; \
|
2019-05-17 10:17:06 +02:00
|
|
|
if (r < 0) \
|
|
|
|
(void) sd_notifyf(0, "ERRNO=%i", -r); \
|
2018-11-20 10:22:26 +01:00
|
|
|
ask_password_agent_close(); \
|
2018-11-20 15:52:40 +01:00
|
|
|
polkit_agent_close(); \
|
2018-11-20 14:03:46 +01:00
|
|
|
pager_close(); \
|
2019-03-21 17:57:16 +01:00
|
|
|
mac_selinux_finish(); \
|
|
|
|
static_destruct(); \
|
2018-11-20 13:54:12 +01:00
|
|
|
return ret; \
|
2018-11-19 20:26:37 +01:00
|
|
|
}
|
|
|
|
|
2018-11-20 13:54:12 +01:00
|
|
|
/* Negative return values from impl are mapped to EXIT_FAILURE, and
|
|
|
|
* everything else means success! */
|
|
|
|
#define DEFINE_MAIN_FUNCTION(impl) \
|
2018-12-04 11:49:42 +01:00
|
|
|
_DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
|
2018-11-20 13:54:12 +01:00
|
|
|
|
2018-11-20 09:49:42 +01:00
|
|
|
/* Zero is mapped to EXIT_SUCCESS, negative values are mapped to EXIT_FAILURE,
|
2019-04-27 02:22:40 +02:00
|
|
|
* and positive values are propagated.
|
2018-11-20 09:49:42 +01:00
|
|
|
* Note: "true" means failure! */
|
2018-11-19 20:26:37 +01:00
|
|
|
#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
|
2018-12-04 11:49:42 +01:00
|
|
|
_DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : r)
|