main-func: Reduce transitive includes
Let's move some logic from _DEFINE_MAIN_FUNCTION() and other places in main-func.h into functions that we implement in main-func.c to allow moving some included headers from the header to the .c file.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "pretty-print.h"
|
||||
#include "string-util.h"
|
||||
|
||||
static bool arg_verbose = false;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "device-util.h"
|
||||
#include "escape.h"
|
||||
#include "fileio.h"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <getopt.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "missing_magic.h"
|
||||
#include "pager.h"
|
||||
#include "parse-argument.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "pretty-print.h"
|
||||
#include "process-util.h"
|
||||
#include "stat-util.h"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "sd-messages.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "ask-password-api.h"
|
||||
#include "build.h"
|
||||
#include "cryptsetup-fido2.h"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "architecture.h"
|
||||
#include "argv-util.h"
|
||||
#include "blockdev-util.h"
|
||||
#include "build.h"
|
||||
#include "chase.h"
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-locator.h"
|
||||
#include "bus-unit-util.h"
|
||||
#include "bus-util.h"
|
||||
#include "chase.h"
|
||||
#include "creds-util.h"
|
||||
#include "efi-loader.h"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "blockdev-util.h"
|
||||
#include "dissect-image.h"
|
||||
#include "fd-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "mkfs-util.h"
|
||||
#include "path-util.h"
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <stddef.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "blockdev-util.h"
|
||||
#include "bus-unit-util.h"
|
||||
#include "chown-recursive.h"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "bus-get-properties.h"
|
||||
#include "bus-log-control-api.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "bus-util.h"
|
||||
#include "constants.h"
|
||||
#include "daemon-util.h"
|
||||
#include "device-private.h"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "bus-get-properties.h"
|
||||
#include "bus-log-control-api.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "bus-util.h"
|
||||
#include "common-signal.h"
|
||||
#include "constants.h"
|
||||
#include "daemon-util.h"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "cryptsetup-util.h"
|
||||
#include "fileio.h"
|
||||
#include "hexdecoct.h"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "boot-entry.h"
|
||||
#include "build.h"
|
||||
#include "chase.h"
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "bus-message.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "bus-unit-util.h"
|
||||
#include "bus-util.h"
|
||||
#include "constants.h"
|
||||
#include "daemon-util.h"
|
||||
#include "kbd-util.h"
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "pager.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "pretty-print.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "fs-util.h"
|
||||
#include "label-util.h"
|
||||
#include "limits-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "missing_magic.h"
|
||||
#include "missing_syscall.h"
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "hostname-util.h"
|
||||
#include "import-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "label-util.h"
|
||||
#include "locale-util.h"
|
||||
#include "log.h"
|
||||
#include "logs-show.h"
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "bus-locator.h"
|
||||
#include "bus-log-control-api.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "bus-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "common-signal.h"
|
||||
#include "daemon-util.h"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "main-func.h"
|
||||
#include "memstream-util.h"
|
||||
#include "openssl-util.h"
|
||||
#include "pager.h"
|
||||
#include "parse-argument.h"
|
||||
#include "parse-util.h"
|
||||
#include "pe-binary.h"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "build.h"
|
||||
#include "conf-files.h"
|
||||
#include "constants.h"
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "sd-bus.h"
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "build.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-locator.h"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "parse-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if HAVE_SELINUX
|
||||
#include <selinux/selinux.h>
|
||||
#endif
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-id128.h"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "sd-netlink.h"
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "env-util.h"
|
||||
#include "fd-util.h"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "bus-message-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "pager.h"
|
||||
#include "pretty-print.h"
|
||||
#include "terminal-util.h"
|
||||
#include "verbs.h"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
#include "errno-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "main-func.h"
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "bus-log-control-api.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "bus-util.h"
|
||||
#include "common-signal.h"
|
||||
#include "constants.h"
|
||||
#include "daemon-util.h"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "pretty-print.h"
|
||||
#include "process-util.h"
|
||||
#include "ptyfwd.h"
|
||||
#include "signal-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
static bool arg_quiet = false;
|
||||
|
||||
@@ -5,18 +5,21 @@
|
||||
#include <net/if.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-json.h"
|
||||
#include "sd-netlink.h"
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "af-list.h"
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "build.h"
|
||||
#include "bus-common-errors.h"
|
||||
#include "bus-error.h"
|
||||
#include "bus-locator.h"
|
||||
#include "bus-map-properties.h"
|
||||
#include "bus-message-util.h"
|
||||
#include "bus-util.h"
|
||||
#include "dns-domain.h"
|
||||
#include "errno-list.h"
|
||||
#include "escape.h"
|
||||
@@ -31,6 +34,7 @@
|
||||
#include "pager.h"
|
||||
#include "parse-argument.h"
|
||||
#include "parse-util.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "pretty-print.h"
|
||||
#include "process-util.h"
|
||||
#include "resolvconf-compat.h"
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "device-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "escape.h"
|
||||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
|
||||
@@ -7,10 +7,12 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "sd-bus.h"
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-event.h"
|
||||
#include "sd-json.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "ask-password-agent.h"
|
||||
#include "build.h"
|
||||
#include "bus-error.h"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "cgroup-util.h"
|
||||
#include "dropin.h"
|
||||
#include "escape.h"
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#if HAVE_VALGRIND_VALGRIND_H
|
||||
# include <valgrind/valgrind.h>
|
||||
#endif
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "ask-password-agent.h"
|
||||
#include "hashmap.h"
|
||||
#include "main-func.h"
|
||||
#include "pager.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "selinux-util.h"
|
||||
#include "signal-util.h"
|
||||
|
||||
void main_prepare(int argc, char *argv[]) {
|
||||
assert_se(argc > 0 && !isempty(argv[0]));
|
||||
save_argc_argv(argc, argv);
|
||||
}
|
||||
|
||||
void main_finalize(int r, int exit_status) {
|
||||
if (r < 0)
|
||||
(void) sd_notifyf(0, "ERRNO=%i", -r);
|
||||
(void) sd_notifyf(0, "EXIT_STATUS=%i", exit_status);
|
||||
ask_password_agent_close();
|
||||
polkit_agent_close();
|
||||
pager_close();
|
||||
mac_selinux_finish();
|
||||
}
|
||||
|
||||
int raise_or_exit_status(int ret) {
|
||||
if (ret < 0)
|
||||
return EXIT_FAILURE;
|
||||
if (ret == 0)
|
||||
return EXIT_SUCCESS;
|
||||
if (!SIGNAL_VALID(ret))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
#if HAVE_VALGRIND_VALGRIND_H
|
||||
/* If raise() below succeeds, the destructor cleanup_pools() in hashmap.c will never called. */
|
||||
if (RUNNING_ON_VALGRIND)
|
||||
hashmap_trim_pools();
|
||||
#endif
|
||||
|
||||
(void) raise(ret);
|
||||
/* exit with failure if raise() does not immediately abort the program. */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
+7
-41
@@ -3,36 +3,19 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_VALGRIND_VALGRIND_H
|
||||
# include <valgrind/valgrind.h>
|
||||
#endif
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "ask-password-agent.h"
|
||||
#include "hashmap.h"
|
||||
#include "pager.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "selinux-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "static-destruct.h"
|
||||
|
||||
void main_prepare(int argc, char *argv[]);
|
||||
|
||||
void main_finalize(int r, int exit_status);
|
||||
|
||||
#define _DEFINE_MAIN_FUNCTION(intro, impl, result_to_exit_status, result_to_return_value) \
|
||||
int main(int argc, char *argv[]) { \
|
||||
int r; \
|
||||
assert_se(argc > 0 && !isempty(argv[0])); \
|
||||
save_argc_argv(argc, argv); \
|
||||
main_prepare(argc, argv); \
|
||||
intro; \
|
||||
r = impl; \
|
||||
if (r < 0) \
|
||||
(void) sd_notifyf(0, "ERRNO=%i", -r); \
|
||||
(void) sd_notifyf(0, "EXIT_STATUS=%i", \
|
||||
result_to_exit_status(r)); \
|
||||
ask_password_agent_close(); \
|
||||
polkit_agent_close(); \
|
||||
pager_close(); \
|
||||
mac_selinux_finish(); \
|
||||
main_finalize(r, result_to_exit_status(r)); \
|
||||
static_destruct(); \
|
||||
return result_to_return_value(r); \
|
||||
}
|
||||
@@ -56,24 +39,7 @@ static inline int exit_failure_if_nonzero(int result) {
|
||||
#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
|
||||
_DEFINE_MAIN_FUNCTION(,impl(argc, argv), exit_failure_if_nonzero, exit_failure_if_nonzero)
|
||||
|
||||
static inline int raise_or_exit_status(int ret) {
|
||||
if (ret < 0)
|
||||
return EXIT_FAILURE;
|
||||
if (ret == 0)
|
||||
return EXIT_SUCCESS;
|
||||
if (!SIGNAL_VALID(ret))
|
||||
return EXIT_FAILURE;
|
||||
|
||||
#if HAVE_VALGRIND_VALGRIND_H
|
||||
/* If raise() below succeeds, the destructor cleanup_pools() in hashmap.c will never called. */
|
||||
if (RUNNING_ON_VALGRIND)
|
||||
hashmap_trim_pools();
|
||||
#endif
|
||||
|
||||
(void) raise(ret);
|
||||
/* exit with failure if raise() does not immediately abort the program. */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int raise_or_exit_status(int ret);
|
||||
|
||||
/* Negative return values from impl are mapped to EXIT_FAILURE, zero is mapped to EXIT_SUCCESS,
|
||||
* and raise if a positive signal is returned from impl. */
|
||||
|
||||
@@ -119,6 +119,7 @@ shared_sources = files(
|
||||
'machine-id-setup.c',
|
||||
'machine-pool.c',
|
||||
'macvlan-util.c',
|
||||
'main-func.c',
|
||||
'mkdir-label.c',
|
||||
'mkfs-util.c',
|
||||
'module-util.c',
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "sd-bus.h"
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "blockdev-util.h"
|
||||
#include "build.h"
|
||||
#include "bus-error.h"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "build.h"
|
||||
#include "bus-util.h"
|
||||
#include "capsule-util.h"
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "sd-daemon.h"
|
||||
|
||||
#include "build.h"
|
||||
#include "chase.h"
|
||||
#include "conf-files.h"
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "os-util.h"
|
||||
#include "pager.h"
|
||||
#include "path-util.h"
|
||||
#include "polkit-agent.h"
|
||||
#include "pretty-print.h"
|
||||
#include "strv.h"
|
||||
#include "sysupdate-update-set-flags.h"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "bitfield.h"
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "bus-message-util.h"
|
||||
#include "bus-polkit.h"
|
||||
#include "bus-unit-util.h"
|
||||
#include "bus-util.h"
|
||||
#include "clock-util.h"
|
||||
#include "conf-files.h"
|
||||
#include "constants.h"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "sd-event.h"
|
||||
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "inotify-util.h"
|
||||
#include "main-func.h"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "main-func.h"
|
||||
#include "pretty-print.h"
|
||||
#include "process-util.h"
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "argv-util.h"
|
||||
#include "env-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "group-record.h"
|
||||
#include "io-util.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "sd-daemon.h"
|
||||
#include "sd-varlink.h"
|
||||
|
||||
#include "build.h"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "sd-device.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "argv-util.h"
|
||||
#include "cryptsetup-util.h"
|
||||
#include "fileio.h"
|
||||
#include "fstab-util.h"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "build.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-locator.h"
|
||||
#include "bus-util.h"
|
||||
#include "bus-wait-for-jobs.h"
|
||||
#include "capability-util.h"
|
||||
#include "chase.h"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "chase.h"
|
||||
#include "devnum-util.h"
|
||||
#include "escape.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "mkdir.h"
|
||||
#include "mount-util.h"
|
||||
|
||||
Reference in New Issue
Block a user