From 55944e5e40b1be2afc4855d8d2baf4b73d1876b5 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 22:49:52 +0200 Subject: Adding upstream version 255.4. Signed-off-by: Daniel Baumann --- src/rc-local-generator/meson.build | 9 ++++ src/rc-local-generator/rc-local-generator.c | 76 +++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 src/rc-local-generator/meson.build create mode 100644 src/rc-local-generator/rc-local-generator.c (limited to 'src/rc-local-generator') diff --git a/src/rc-local-generator/meson.build b/src/rc-local-generator/meson.build new file mode 100644 index 0000000..e74225c --- /dev/null +++ b/src/rc-local-generator/meson.build @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +executables += [ + generator_template + { + 'name' : 'systemd-rc-local-generator', + 'conditions' : ['HAVE_SYSV_COMPAT'], + 'sources' : files('rc-local-generator.c'), + }, +] diff --git a/src/rc-local-generator/rc-local-generator.c b/src/rc-local-generator/rc-local-generator.c new file mode 100644 index 0000000..89cc5fa --- /dev/null +++ b/src/rc-local-generator/rc-local-generator.c @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include +#include +#include + +#include "generator.h" +#include "initrd-util.h" +#include "log.h" +#include "mkdir-label.h" +#include "string-util.h" + +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 + * execution of a service's binary, but they have no influence on unit dependencies. Thus, a service that is + * conditioned out will still act as synchronization point in the dependency tree, and we'd rather not have that for + * these two legacy scripts. */ + +static int add_symlink(const char *service, const char *where) { + const char *from, *to; + + assert(service); + assert(where); + + from = strjoina(SYSTEM_DATA_UNIT_DIR "/", service); + to = strjoina(arg_dest, "/", where, ".wants/", service); + + (void) mkdir_parents_label(to, 0755); + + if (symlink(from, to) < 0) { + if (errno == EEXIST) + return 0; + + return log_error_errno(errno, "Failed to create symlink %s: %m", to); + } + + return 1; +} + +static int check_executable(const char *path) { + assert(path); + + if (access(path, X_OK) < 0) { + if (errno == ENOENT) + return log_debug_errno(errno, "%s does not exist, skipping.", path); + if (errno == EACCES) + return log_info_errno(errno, "%s is not marked executable, skipping.", path); + + return log_warning_errno(errno, "Couldn't determine if %s exists and is executable, skipping: %m", path); + } + + return 0; +} + +static int run(const char *dest, const char *dest_early, const char *dest_late) { + int r = 0, k = 0; + + assert_se(arg_dest = dest); + + if (in_initrd()) { + log_debug("Skipping generator, running in the initrd."); + return EXIT_SUCCESS; + } + + if (check_executable(RC_LOCAL_PATH) >= 0) { + log_debug("Automatically adding rc-local.service."); + + r = add_symlink("rc-local.service", "multi-user.target"); + } + + return r < 0 ? r : k; +} + +DEFINE_MAIN_GENERATOR_FUNCTION(run); -- cgit v1.2.3