1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include "string-util.h"
14 static const char *arg_dest
= "/tmp";
16 /* So you are reading this, and might wonder: why is this implemented as a generator rather than as a plain, statically
17 * enabled service that carries appropriate ConditionFileIsExecutable= lines? The answer is this: conditions bypass
18 * execution of a service's binary, but they have no influence on unit dependencies. Thus, a service that is
19 * conditioned out will still act as synchronization point in the dependency tree, and we'd rather not have that for
20 * these two legacy scripts. */
22 static int add_symlink(const char *service
, const char *where
) {
23 const char *from
, *to
;
28 from
= strjoina(SYSTEM_DATA_UNIT_PATH
"/", service
);
29 to
= strjoina(arg_dest
, "/", where
, ".wants/", service
);
31 (void) mkdir_parents_label(to
, 0755);
33 if (symlink(from
, to
) < 0) {
37 return log_error_errno(errno
, "Failed to create symlink %s: %m", to
);
43 static int check_executable(const char *path
) {
46 if (access(path
, X_OK
) < 0) {
48 return log_debug_errno(errno
, "%s does not exist, skipping.", path
);
50 return log_info_errno(errno
, "%s is not marked executable, skipping.", path
);
52 return log_warning_errno(errno
, "Couldn't determine if %s exists and is executable, skipping: %m", path
);
58 static int run(int argc
, char *argv
[]) {
61 log_setup_generator();
63 if (argc
> 1 && argc
!= 4)
64 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "This program takes three or no arguments.");
69 if (check_executable(RC_LOCAL_SCRIPT_PATH_START
) >= 0) {
70 log_debug("Automatically adding rc-local.service.");
72 r
= add_symlink("rc-local.service", "multi-user.target");
75 if (check_executable(RC_LOCAL_SCRIPT_PATH_STOP
) >= 0) {
76 log_debug("Automatically adding halt-local.service.");
78 k
= add_symlink("halt-local.service", "final.target");
84 DEFINE_MAIN_FUNCTION(run
);