summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-11-19 20:26:37 +0100
committerLennart Poettering <lennart@poettering.net>2018-11-19 21:14:34 +0100
commit5e332028f20566d8b9aa0d01c60aff8b9f43bcb7 (patch)
tree3d17977a29f551a36dc2d86b28e0bfd9e6b7a182 /src
parent2a44bf5099d4b13d90d4a6c93b404894960487ee (diff)
downloadsystemd-5e332028f20566d8b9aa0d01c60aff8b9f43bcb7.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/ac-power/ac-power.c1
-rw-r--r--src/basic/macro.h19
-rw-r--r--src/basic/main-func.h23
-rw-r--r--src/boot/bless-boot.c1
-rw-r--r--src/boot/boot-check-no-failures.c1
-rw-r--r--src/cgtop/cgtop.c1
-rw-r--r--src/coredump/coredump.c1
-rw-r--r--src/debug-generator/debug-generator.c1
-rw-r--r--src/detect-virt/detect-virt.c1
-rw-r--r--src/escape/escape.c1
-rw-r--r--src/fsck/fsck.c1
-rw-r--r--src/hostname/hostnamectl.c1
-rw-r--r--src/hwdb/hwdb.c1
-rw-r--r--src/id128/id128.c1
-rw-r--r--src/import/export.c1
-rw-r--r--src/import/import.c1
-rw-r--r--src/import/importd.c1
-rw-r--r--src/import/pull.c1
-rw-r--r--src/journal/cat.c3
-rw-r--r--src/login/inhibit.c1
-rw-r--r--src/login/logind.c1
-rw-r--r--src/login/user-runtime-dir.c1
-rw-r--r--src/machine/machined.c1
-rw-r--r--src/notify/notify.c1
-rw-r--r--src/partition/makefs.c1
-rw-r--r--src/path/path.c1
-rw-r--r--src/portable/portabled.c1
-rw-r--r--src/quotacheck/quotacheck.c1
-rw-r--r--src/random-seed/random-seed.c1
-rw-r--r--src/remount-fs/remount-fs.c1
-rw-r--r--src/sleep/sleep.c1
-rw-r--r--src/stdio-bridge/stdio-bridge.c3
-rw-r--r--src/sysv-generator/sysv-generator.c1
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c1
-rw-r--r--src/volatile-root/volatile-root.c5
35 files changed, 60 insertions, 23 deletions
diff --git a/src/ac-power/ac-power.c b/src/ac-power/ac-power.c
index 2d8cbb985f..090b6b1783 100644
--- a/src/ac-power/ac-power.c
+++ b/src/ac-power/ac-power.c
@@ -2,6 +2,7 @@
#include <getopt.h>
+#include "main-func.h"
#include "util.h"
static bool arg_verbose = false;
diff --git a/src/basic/macro.h b/src/basic/macro.h
index c52d8e4e3f..00fb3212db 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -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"
diff --git a/src/basic/main-func.h b/src/basic/main-func.h
new file mode 100644
index 0000000000..9ebe0ab882
--- /dev/null
+++ b/src/basic/main-func.h
@@ -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; \
+ }
diff --git a/src/boot/bless-boot.c b/src/boot/bless-boot.c
index 84ac9e39e4..2455f3703f 100644
--- a/src/boot/bless-boot.c
+++ b/src/boot/bless-boot.c
@@ -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"
diff --git a/src/boot/boot-check-no-failures.c b/src/boot/boot-check-no-failures.c
index 1674517d48..3284a04793 100644
--- a/src/boot/boot-check-no-failures.c
+++ b/src/boot/boot-check-no-failures.c
@@ -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) {
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index 2cc869dcbd..cad274a633 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -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"
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index 764ee2a945..46536b7c84 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -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"
diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c
index a9497fe587..98fe574f8d 100644
--- a/src/debug-generator/debug-generator.c
+++ b/src/debug-generator/debug-generator.c
@@ -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"
diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c
index d1a2ab95a0..f1259fdcd5 100644
--- a/src/detect-virt/detect-virt.c
+++ b/src/detect-virt/detect-virt.c
@@ -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"
diff --git a/src/escape/escape.c b/src/escape/escape.c
index ed42ad65ad..b03c9e661d 100644
--- a/src/escape/escape.c
+++ b/src/escape/escape.c
@@ -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"
diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 54d6d26fb5..821ad15c5f 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -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"
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 8220741efa..0d40d17a55 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -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"
diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
index 87b84b70a9..89e3138542 100644
--- a/src/hwdb/hwdb.c
+++ b/src/hwdb/hwdb.c
@@ -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"
diff --git a/src/id128/id128.c b/src/id128/id128.c
index 6b7045b3e7..cbd7464d2c 100644
--- a/src/id128/id128.c
+++ b/src/id128/id128.c
@@ -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"
diff --git a/src/import/export.c b/src/import/export.c
index 317ac1bba7..e07aa5d6d5 100644
--- a/src/import/export.c
+++ b/src/import/export.c
@@ -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"
diff --git a/src/import/import.c b/src/import/import.c
index 69fe8a8a37..9dca2f3d41 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -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"
diff --git a/src/import/importd.c b/src/import/importd.c
index b5265a7ed3..f17cdf10d4 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -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"
diff --git a/src/import/pull.c b/src/import/pull.c
index 821c9772e4..810cab53ba 100644
--- a/src/import/pull.c
+++ b/src/import/pull.c
@@ -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"
diff --git a/src/journal/cat.c b/src/journal/cat.c
index 1576199deb..3198d3261b 100644
--- a/src/journal/cat.c
+++ b/src/journal/cat.c
@@ -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;
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index ca24aea5a7..508c539044 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -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"
diff --git a/src/login/logind.c b/src/login/logind.c
index e71ac0ee6d..5f2243a15d 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -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"
diff --git a/src/login/user-runtime-dir.c b/src/login/user-runtime-dir.c
index b3a6e5c740..8a1110491a 100644
--- a/src/login/user-runtime-dir.c
+++ b/src/login/user-runtime-dir.c
@@ -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"
diff --git a/src/machine/machined.c b/src/machine/machined.c
index 24850af5bc..a2e7a30240 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -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"
diff --git a/src/notify/notify.c b/src/notify/notify.c
index 149cd0d050..fdf4598941 100644
--- a/src/notify/notify.c
+++ b/src/notify/notify.c
@@ -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"
diff --git a/src/partition/makefs.c b/src/partition/makefs.c
index dcc69c6a20..b2702d20f7 100644
--- a/src/partition/makefs.c
+++ b/src/partition/makefs.c
@@ -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"
diff --git a/src/path/path.c b/src/path/path.c
index 1b7e0c547a..4a2e2ca3f6 100644
--- a/src/path/path.c
+++ b/src/path/path.c
@@ -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"
diff --git a/src/portable/portabled.c b/src/portable/portabled.c
index a853257bc0..313211a792 100644
--- a/src/portable/portabled.c
+++ b/src/portable/portabled.c
@@ -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"
diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c
index e3c50c366a..7b11f29507 100644
--- a/src/quotacheck/quotacheck.c
+++ b/src/quotacheck/quotacheck.c
@@ -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"
diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c
index f5a7eca93c..6162f8d6bf 100644
--- a/src/random-seed/random-seed.c
+++ b/src/random-seed/random-seed.c
@@ -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"
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index 9a0c39e16f..ece7f2955d 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -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"
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 6010611366..f1f4da8886 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -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"
diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c
index 9efd6c216f..9ceb3f8d13 100644
--- a/src/stdio-bridge/stdio-bridge.c
+++ b/src/stdio-bridge/stdio-bridge.c
@@ -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"
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index 255adeaa19..c92d7f841a 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -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"
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index 1c965217d9..609839c5a1 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -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"
diff --git a/src/volatile-root/volatile-root.c b/src/volatile-root/volatile-root.c
index ab7dca37b1..b08d42834f 100644
--- a/src/volatile-root/volatile-root.c
+++ b/src/volatile-root/volatile-root.c
@@ -4,12 +4,13 @@
#include "alloc-util.h"
#include "fs-util.h"
+#include "main-func.h"
#include "mkdir.h"
#include "mount-util.h"
+#include "path-util.h"
#include "stat-util.h"
-#include "volatile-util.h"
#include "string-util.h"
-#include "path-util.h"
+#include "volatile-util.h"
static int make_volatile(const char *path) {
_cleanup_free_ char *old_usr = NULL;