/* SPDX-License-Identifier: LGPL-2.1+ */
-/***
- This file is part of systemd.
-
- Copyright 2014 Lennart Poettering
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
#include "alloc-util.h"
+#include "generator.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;
+STATIC_DESTRUCTOR_REGISTER(arg_default_unit, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_mask, strv_freep);
+STATIC_DESTRUCTOR_REGISTER(arg_wants, strv_freep);
+
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
int r;
if (proc_cmdline_value_missing(key, value))
return 0;
- r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
+ r = unit_name_mangle(value, UNIT_NAME_MANGLE_WARN, &n);
if (r < 0)
return log_error_errno(r, "Failed to glob unit name: %m");
if (proc_cmdline_value_missing(key, value))
return 0;
- r = unit_name_mangle(value, UNIT_NAME_NOGLOB, &n);
+ r = unit_name_mangle(value, UNIT_NAME_MANGLE_WARN, &n);
if (r < 0)
return log_error_errno(r, "Failed to glob unit name: %m");
return r;
}
-int main(int argc, char *argv[]) {
+static int run(const char *dest, const char *dest_early, const char *dest_late) {
int r, q;
- if (argc > 1 && argc != 4) {
- log_error("This program takes three or no arguments.");
- return EXIT_FAILURE;
- }
-
- if (argc > 1)
- arg_dest = argv[2];
-
- log_set_target(LOG_TARGET_SAFE);
- log_parse_environment();
- log_open();
+ assert_se(arg_dest = dest_early);
- umask(0022);
-
- r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
+ r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_RD_STRICT | PROC_CMDLINE_STRIP_RD_PREFIX);
if (r < 0)
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
if (arg_debug_shell) {
r = strv_extend(&arg_wants, "debug-shell.service");
- if (r < 0) {
- r = log_oom();
- goto finish;
- }
+ if (r < 0)
+ return log_oom();
}
r = generate_mask_symlinks();
-
q = generate_wants_symlinks();
- if (q < 0)
- r = q;
-
-finish:
- arg_default_unit = mfree(arg_default_unit);
- return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+ return r < 0 ? r : q;
}
+
+DEFINE_MAIN_GENERATOR_FUNCTION(run);