summaryrefslogtreecommitdiff
path: root/src/shared/generator.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-12-04 11:49:42 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-12-12 21:58:00 +0100
commit7a44c7e31fdeebce82189b134221297919104e7d (patch)
tree2b12fa18720523a3cace0a238ea78b719c1f7356 /src/shared/generator.h
parentaba311f7ffb1370156f48061a5fdc2da9551e57f (diff)
downloadsystemd-7a44c7e31fdeebce82189b134221297919104e7d.tar.gz
generators: define custom main func definer and use it where applicable
There should be no functional difference, except that the error message is changd from "three or no arguments" to "zero or three arguments". Somehow the inverted form always seemed strange. umask() call is also dropped from run-generator. I think it wasn't dropped in 053254e3cb215df3b8c905bc39b920f8817e1c7d because the run generator was merged around the same time.
Diffstat (limited to 'src/shared/generator.h')
-rw-r--r--src/shared/generator.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/shared/generator.h b/src/shared/generator.h
index f1a055401a..5a1c1e32f7 100644
--- a/src/shared/generator.h
+++ b/src/shared/generator.h
@@ -3,6 +3,8 @@
#include <stdio.h>
+#include "main-func.h"
+
int generator_open_unit_file(
const char *dest,
const char *source,
@@ -49,3 +51,17 @@ int generator_hook_up_growfs(
const char *target);
void log_setup_generator(void);
+
+/* Similar to DEFINE_MAIN_FUNCTION, but initializes logging and assigns positional arguments. */
+#define DEFINE_MAIN_GENERATOR_FUNCTION(impl) \
+ _DEFINE_MAIN_FUNCTION( \
+ ({ \
+ log_setup_generator(); \
+ if (argc > 1 && argc != 4) \
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), \
+ "This program takes zero or three arguments."); \
+ }), \
+ impl(argc > 1 ? argv[1] : "/tmp", \
+ argc > 1 ? argv[2] : "/tmp", \
+ argc > 1 ? argv[3] : "/tmp"), \
+ r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)