]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/rc-local-generator/rc-local-generator.c
8b1b75f569262cb91b971ffe62b47385e7d07fa4
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
6 #include "initrd-util.h"
8 #include "mkdir-label.h"
9 #include "string-util.h"
11 static const char *arg_dest
= NULL
;
13 /* So you are reading this, and might wonder: why is this implemented as a generator rather than as a plain, statically
14 * enabled service that carries appropriate ConditionFileIsExecutable= lines? The answer is this: conditions bypass
15 * execution of a service's binary, but they have no influence on unit dependencies. Thus, a service that is
16 * conditioned out will still act as synchronization point in the dependency tree, and we'd rather not have that for
17 * these two legacy scripts. */
19 static int add_symlink(const char *service
, const char *where
) {
20 const char *from
, *to
;
25 from
= strjoina(SYSTEM_DATA_UNIT_DIR
"/", service
);
26 to
= strjoina(arg_dest
, "/", where
, ".wants/", service
);
28 (void) mkdir_parents_label(to
, 0755);
30 if (symlink(from
, to
) < 0) {
34 return log_error_errno(errno
, "Failed to create symlink %s: %m", to
);
40 static int check_executable(const char *path
) {
43 if (access(path
, X_OK
) < 0) {
45 return log_debug_errno(errno
, "%s does not exist, skipping.", path
);
47 return log_info_errno(errno
, "%s is not marked executable, skipping.", path
);
49 return log_warning_errno(errno
, "Couldn't determine if %s exists and is executable, skipping: %m", path
);
55 static int run(const char *dest
, const char *dest_early
, const char *dest_late
) {
58 assert_se(arg_dest
= dest
);
61 log_debug("Skipping generator, running in the initrd.");
65 if (check_executable(SYSTEM_SYSVRCLOCAL_PATH
) >= 0) {
66 log_debug("Automatically adding rc-local.service.");
68 r
= add_symlink("rc-local.service", "multi-user.target");
74 DEFINE_MAIN_GENERATOR_FUNCTION(run
);