util-lib: move main() definition macros to its own header file
This way, we can extend the macro a bit with stuff pulled in from other headers without this affecting everything which pulls in macro.h, which is one of our most basic headers. This is just refactoring, no change in behaviour, in prepartion for later changes.
This commit is contained in:
parent
2a44bf5099
commit
5e332028f2
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <getopt.h>
|
||||
|
||||
#include "main-func.h"
|
||||
#include "util.h"
|
||||
|
||||
static bool arg_verbose = false;
|
||||
|
|
|
@ -506,23 +506,4 @@ static inline int __coverity_check__(int condition) {
|
|||
DEFINE_PUBLIC_TRIVIAL_REF_FUNC(type, name); \
|
||||
DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC(type, name, free_func);
|
||||
|
||||
/* Negative return values from impl are mapped to EXIT_FAILURE, and
|
||||
* everything else means success! */
|
||||
#define DEFINE_MAIN_FUNCTION(impl) \
|
||||
int main(int argc, char *argv[]) { \
|
||||
int r; \
|
||||
r = impl(argc, argv); \
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; \
|
||||
}
|
||||
|
||||
/* Zero is mapped to EXIT_SUCCESS, and both negative and positive values
|
||||
* are mapped to EXIT_FAILURE.
|
||||
* Note: this means "true" maps to EXIT_FAILURE. */
|
||||
#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
|
||||
int main(int argc, char *argv[]) { \
|
||||
int r; \
|
||||
r = impl(argc, argv); \
|
||||
return r != 0 ? EXIT_FAILURE : EXIT_SUCCESS; \
|
||||
}
|
||||
|
||||
#include "log.h"
|
||||
|
|
23
src/basic/main-func.h
Normal file
23
src/basic/main-func.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Negative return values from impl are mapped to EXIT_FAILURE, and
|
||||
* everything else means success! */
|
||||
#define DEFINE_MAIN_FUNCTION(impl) \
|
||||
int main(int argc, char *argv[]) { \
|
||||
int r; \
|
||||
r = impl(argc, argv); \
|
||||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; \
|
||||
}
|
||||
|
||||
/* Zero is mapped to EXIT_SUCCESS, and both negative and positive values
|
||||
* are mapped to EXIT_FAILURE.
|
||||
* Note: this means "true" maps to EXIT_FAILURE. */
|
||||
#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
|
||||
int main(int argc, char *argv[]) { \
|
||||
int r; \
|
||||
r = impl(argc, argv); \
|
||||
return r != 0 ? EXIT_FAILURE : EXIT_SUCCESS; \
|
||||
}
|
|
@ -9,6 +9,7 @@
|
|||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "alloc-util.h"
|
||||
#include "bus-error.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "util.h"
|
||||
|
||||
static int help(void) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "hashmap.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "journal-importer.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "main-func.h"
|
||||
#include "missing.h"
|
||||
#include "mkdir.h"
|
||||
#include "parse-util.h"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "main-func.h"
|
||||
#include "mkdir.h"
|
||||
#include "parse-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "main-func.h"
|
||||
#include "string-table.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "alloc-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "terminal-util.h"
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "device-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "proc-cmdline.h"
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "bus-error.h"
|
||||
#include "bus-util.h"
|
||||
#include "hostname-util.h"
|
||||
#include "main-func.h"
|
||||
#include "spawn-polkit-agent.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "alloc-util.h"
|
||||
#include "hwdb-util.h"
|
||||
#include "main-func.h"
|
||||
#include "selinux-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "alloc-util.h"
|
||||
#include "id128-print.h"
|
||||
#include "main-func.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
#include "verbs.h"
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "hostname-util.h"
|
||||
#include "import-util.h"
|
||||
#include "machine-image.h"
|
||||
#include "main-func.h"
|
||||
#include "signal-util.h"
|
||||
#include "string-util.h"
|
||||
#include "verbs.h"
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "import-tar.h"
|
||||
#include "import-util.h"
|
||||
#include "machine-image.h"
|
||||
#include "main-func.h"
|
||||
#include "signal-util.h"
|
||||
#include "string-util.h"
|
||||
#include "verbs.h"
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "hostname-util.h"
|
||||
#include "import-util.h"
|
||||
#include "machine-pool.h"
|
||||
#include "main-func.h"
|
||||
#include "missing.h"
|
||||
#include "mkdir.h"
|
||||
#include "parse-util.h"
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "hostname-util.h"
|
||||
#include "import-util.h"
|
||||
#include "machine-image.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "pull-raw.h"
|
||||
#include "pull-tar.h"
|
||||
|
|
|
@ -11,11 +11,12 @@
|
|||
|
||||
#include "alloc-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-util.h"
|
||||
#include "syslog-util.h"
|
||||
#include "util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static const char *arg_identifier = NULL;
|
||||
static int arg_priority = LOG_INFO;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "fd-util.h"
|
||||
#include "format-table.h"
|
||||
#include "format-util.h"
|
||||
#include "main-func.h"
|
||||
#include "pager.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "logind.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "process-util.h"
|
||||
#include "selinux-util.h"
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "bus-error.h"
|
||||
#include "fs-util.h"
|
||||
#include "label.h"
|
||||
#include "main-func.h"
|
||||
#include "mkdir.h"
|
||||
#include "mount-util.h"
|
||||
#include "path-util.h"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "label.h"
|
||||
#include "machine-image.h"
|
||||
#include "machined.h"
|
||||
#include "main-func.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "special.h"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "env-util.h"
|
||||
#include "format-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "alloc-util.h"
|
||||
#include "dissect-image.h"
|
||||
#include "main-func.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
#include "string-util.h"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "alloc-util.h"
|
||||
#include "log.h"
|
||||
#include "macro.h"
|
||||
#include "main-func.h"
|
||||
#include "string-util.h"
|
||||
#include "terminal-util.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "alloc-util.h"
|
||||
#include "bus-util.h"
|
||||
#include "def.h"
|
||||
#include "main-func.h"
|
||||
#include "portabled-bus.h"
|
||||
#include "portabled-image-bus.h"
|
||||
#include "portabled.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <sys/prctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "main-func.h"
|
||||
#include "proc-cmdline.h"
|
||||
#include "process-util.h"
|
||||
#include "signal-util.h"
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "fd-util.h"
|
||||
#include "io-util.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "mkdir.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "exit-status.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "mount-setup.h"
|
||||
#include "mount-util.h"
|
||||
#include "path-util.h"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "fd-util.h"
|
||||
#include "fileio.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "parse-util.h"
|
||||
#include "sleep-config.h"
|
||||
#include "stdio-util.h"
|
||||
|
|
|
@ -11,10 +11,11 @@
|
|||
#include "sd-daemon.h"
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "build.h"
|
||||
#include "bus-internal.h"
|
||||
#include "bus-util.h"
|
||||
#include "build.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "util.h"
|
||||
|
||||
#define DEFAULT_BUS_PATH "unix:path=/run/dbus/system_bus_socket"
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "hexdecoct.h"
|
||||
#include "install.h"
|
||||
#include "log.h"
|
||||
#include "main-func.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-lookup.h"
|
||||
#include "path-util.h"
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "hashmap.h"
|
||||
#include "io-util.h"
|
||||
#include "macro.h"
|
||||
#include "main-func.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
#include "alloc-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "main-func.h"
|
||||
#include "mkdir.h"
|
||||
#include "mount-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "volatile-util.h"
|
||||
#include "string-util.h"
|
||||
#include "path-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-util.h"
|
||||
#include "volatile-util.h"
|
||||
|
||||
static int make_volatile(const char *path) {
|
||||
_cleanup_free_ char *old_usr = NULL;
|
||||
|
|
Loading…
Reference in a new issue