1 /* SPDX-License-Identifier: LGPL-2.1+ */
10 #include "string-util.h"
13 static const char *arg_dest
= NULL
;
15 /* So you are reading this, and might wonder: why is this implemented as a generator rather than as a plain, statically
16 * enabled service that carries appropriate ConditionFileIsExecutable= lines? The answer is this: conditions bypass
17 * execution of a service's binary, but they have no influence on unit dependencies. Thus, a service that is
18 * conditioned out will still act as synchronization point in the dependency tree, and we'd rather not have that for
19 * these two legacy scripts. */
21 static int add_symlink(const char *service
, const char *where
) {
22 const char *from
, *to
;
27 from
= strjoina(SYSTEM_DATA_UNIT_PATH
"/", service
);
28 to
= strjoina(arg_dest
, "/", where
, ".wants/", service
);
30 (void) mkdir_parents_label(to
, 0755);
32 if (symlink(from
, to
) < 0) {
36 return log_error_errno(errno
, "Failed to create symlink %s: %m", to
);
42 static int check_executable(const char *path
) {
45 if (access(path
, X_OK
) < 0) {
47 return log_debug_errno(errno
, "%s does not exist, skipping.", path
);
49 return log_info_errno(errno
, "%s is not marked executable, skipping.", path
);
51 return log_warning_errno(errno
, "Couldn't determine if %s exists and is executable, skipping: %m", path
);
57 static int run(const char *dest
, const char *dest_early
, const char *dest_late
) {
60 assert_se(arg_dest
= dest
);
62 if (check_executable(RC_LOCAL_SCRIPT_PATH_START
) >= 0) {
63 log_debug("Automatically adding rc-local.service.");
65 r
= add_symlink("rc-local.service", "multi-user.target");
68 if (check_executable(RC_LOCAL_SCRIPT_PATH_STOP
) >= 0) {
69 log_debug("Automatically adding halt-local.service.");
71 k
= add_symlink("halt-local.service", "final.target");
77 DEFINE_MAIN_GENERATOR_FUNCTION(run
);