#include "hashmap.h"
#include "id128-util.h"
#include "log.h"
-#include "main-func.h"
#include "mkdir.h"
#include "parse-util.h"
#include "path-util.h"
bool create;
} crypto_device;
-static const char *arg_dest = "/tmp";
+static const char *arg_dest = NULL;
static bool arg_enabled = true;
static bool arg_read_crypttab = true;
static bool arg_whitelist = false;
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(crypt_device_hash_ops, char, string_hash_func, string_compare_func,
crypto_device, crypt_device_free);
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r;
- log_setup_generator();
-
- if (argc > 1 && argc != 4)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes three or no arguments.");
-
- if (argc > 1)
- arg_dest = argv[1];
+ assert_se(arg_dest = dest);
arg_disks = hashmap_new(&crypt_device_hash_ops);
if (!arg_disks)
return 0;
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);
#include "alloc-util.h"
#include "generator.h"
-#include "main-func.h"
#include "mkdir.h"
#include "parse-util.h"
#include "proc-cmdline.h"
#include "unit-name.h"
#include "util.h"
+static const char *arg_dest = NULL;
static char *arg_default_unit = NULL;
-static const char *arg_dest = "/tmp";
static char **arg_mask = NULL;
static char **arg_wants = NULL;
static bool arg_debug_shell = false;
return r;
}
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r, q;
- log_setup_generator();
-
- if (argc > 1 && argc != 4)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "This program takes three or no arguments.");
-
- if (argc > 1)
- arg_dest = argv[2];
+ assert_se(arg_dest = dest_early);
r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_RD_STRICT | PROC_CMDLINE_STRIP_RD_PREFIX);
if (r < 0)
return r < 0 ? r : q;
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);
GROWFS = 1 << 4,
} MountpointFlags;
-static const char *arg_dest = "/tmp";
-static const char *arg_dest_late = "/tmp";
+static const char *arg_dest = NULL;
+static const char *arg_dest_late = NULL;
static bool arg_fstab_enabled = true;
static char *arg_root_what = NULL;
static char *arg_root_fstype = NULL;
return 1;
}
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r;
- log_setup_generator();
-
- if (argc > 1 && argc != 4)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
- "This program takes three or no arguments.");
-
- if (argc > 1)
- arg_dest = argv[1];
- if (argc > 3)
- arg_dest_late = argv[3];
+ assert_se(arg_dest = dest);
+ assert_se(arg_dest_late = dest_late);
r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
if (r < 0)
return r;
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);
#include "generator.h"
#include "log.h"
-#include "main-func.h"
#include "mkdir.h"
#include "string-util.h"
#include "util.h"
-static const char *arg_dest = "/tmp";
+static const char *arg_dest = NULL;
/* So you are reading this, and might wonder: why is this implemented as a generator rather than as a plain, statically
* enabled service that carries appropriate ConditionFileIsExecutable= lines? The answer is this: conditions bypass
return 0;
}
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r = 0, k = 0;
- log_setup_generator();
-
- if (argc > 1 && argc != 4)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes three or no arguments.");
-
- if (argc > 1)
- arg_dest = argv[1];
+ assert_se(arg_dest = dest);
if (check_executable(RC_LOCAL_SCRIPT_PATH_START) >= 0) {
log_debug("Automatically adding rc-local.service.");
return r < 0 ? r : k;
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);
#include "fd-util.h"
#include "fileio.h"
#include "generator.h"
-#include "main-func.h"
#include "mkdir.h"
#include "proc-cmdline.h"
#include "specifier.h"
#include "strv.h"
-static const char *arg_dest = "/tmp";
+static const char *arg_dest = NULL;
static char **arg_commands = NULL;
static char *arg_success_action = NULL;
static char *arg_failure_action = NULL;
return 0;
}
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r;
- log_setup_generator();
-
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return -EINVAL;
- }
-
- if (argc > 1)
- arg_dest = argv[1];
-
- umask(0022);
+ assert_se(arg_dest = dest);
r = proc_cmdline_parse(parse, NULL, PROC_CMDLINE_RD_STRICT|PROC_CMDLINE_STRIP_RD_PREFIX);
if (r < 0)
return generate();
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);
#include <stdio.h>
+#include "main-func.h"
+
int generator_open_unit_file(
const char *dest,
const char *source,
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)
#include "spawn-polkit-agent.h"
#include "static-destruct.h"
-#define _DEFINE_MAIN_FUNCTION(impl, ret) \
+#define _DEFINE_MAIN_FUNCTION(intro, impl, ret) \
int main(int argc, char *argv[]) { \
int r; \
- r = impl(argc, argv); \
+ intro; \
+ r = impl; \
static_destruct(); \
ask_password_agent_close(); \
polkit_agent_close(); \
/* Negative return values from impl are mapped to EXIT_FAILURE, and
* everything else means success! */
#define DEFINE_MAIN_FUNCTION(impl) \
- _DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
+ _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : EXIT_SUCCESS)
/* Zero is mapped to EXIT_SUCCESS, negative values are mapped to EXIT_FAILURE,
* and postive values are propagated.
* Note: "true" means failure! */
#define DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(impl) \
- _DEFINE_MAIN_FUNCTION(impl, r < 0 ? EXIT_FAILURE : r)
+ _DEFINE_MAIN_FUNCTION(,impl(argc, argv), r < 0 ? EXIT_FAILURE : r)
* means they are shut down anyway at system power off if running. */
};
-static const char *arg_dest = "/tmp";
+static const char *arg_dest = NULL;
typedef struct SysvStub {
char *name;
return r;
}
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
_cleanup_(free_sysvstub_hashmapp) Hashmap *all_services = NULL;
_cleanup_(lookup_paths_free) LookupPaths lp = {};
SysvStub *service;
Iterator j;
int r;
- log_setup_generator();
-
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return -EINVAL;
- }
-
- if (argc > 1)
- arg_dest = argv[3];
+ assert_se(arg_dest = dest_late);
r = lookup_paths_init(&lp, UNIT_FILE_SYSTEM, LOOKUP_PATHS_EXCLUDE_GENERATED, NULL);
if (r < 0)
return 0;
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);
return 1;
}
-static int run(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r;
- log_setup_generator();
-
- if (argc > 1 && argc != 4)
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes three or no arguments.");
-
- if (argc > 1)
- arg_dest = argv[1];
+ assert_se(arg_dest = dest);
r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
if (r < 0)
if (r < 0)
return r;
- r = create_device();
- if (r < 0)
- return r;
-
- return 0;
+ return create_device();
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_GENERATOR_FUNCTION(run);