X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Frc-local-generator%2Frc-local-generator.c;h=92655012502cd2a4ebba6b872f3302ff5701244d;hp=a5987f977e0527a4dcdd54f29468129d1f06fceb;hb=cac914e643a50c72893c5478f6886e0978f8fa18;hpb=04b6f7c1a7ba7e7baef99b2b0db9842864c0ff82 diff --git a/src/rc-local-generator/rc-local-generator.c b/src/rc-local-generator/rc-local-generator.c index a5987f977..926550125 100644 --- a/src/rc-local-generator/rc-local-generator.c +++ b/src/rc-local-generator/rc-local-generator.c @@ -28,13 +28,13 @@ #include "util.h" #include "mkdir.h" -#if defined(TARGET_FEDORA) || defined(TARGET_MANDRIVA) || defined(TARGET_MAGEIA) -#define SCRIPT_PATH_START "/etc/rc.d/rc.local" -#elif defined(TARGET_SUSE) -#define SCRIPT_PATH_START "/etc/init.d/boot.local" +#ifndef RC_LOCAL_SCRIPT_PATH_START +#define RC_LOCAL_SCRIPT_PATH_START "/etc/rc.d/rc.local" #endif -#define SCRIPT_PATH_STOP "/sbin/halt.local" +#ifndef RC_LOCAL_SCRIPT_PATH_STOP +#define RC_LOCAL_SCRIPT_PATH_STOP "/sbin/halt.local" +#endif const char *arg_dest = "/tmp"; @@ -48,25 +48,23 @@ static int add_symlink(const char *service, const char *where) { asprintf(&to, "%s/%s.wants/%s", arg_dest, where, service); if (!from || !to) { - log_error("Out of memory"); - r = -ENOMEM; + r = log_oom(); goto finish; } - mkdir_parents(to, 0755); + mkdir_parents_label(to, 0755); r = symlink(from, to); if (r < 0) { if (errno == EEXIST) r = 0; else { - log_error("Failed to create symlink from %s to %s: %m", from, to); + log_error("Failed to create symlink %s: %m", to); r = -errno; } } finish: - free(from); free(to); @@ -83,29 +81,30 @@ static bool file_is_executable(const char *f) { } int main(int argc, char *argv[]) { - int r = EXIT_SUCCESS; - if (argc > 2) { - log_error("This program takes one or no arguments."); + if (argc > 1 && argc != 4) { + log_error("This program takes three or no arguments."); return EXIT_FAILURE; } - log_set_target(LOG_TARGET_AUTO); + if (argc > 1) + arg_dest = argv[1]; + + log_set_target(LOG_TARGET_SAFE); log_parse_environment(); log_open(); - if (argc > 1) - arg_dest = argv[1]; + umask(0022); - if (file_is_executable(SCRIPT_PATH_START)) { + if (file_is_executable(RC_LOCAL_SCRIPT_PATH_START)) { log_debug("Automatically adding rc-local.service."); if (add_symlink("rc-local.service", "multi-user.target") < 0) r = EXIT_FAILURE; } - if (file_is_executable(SCRIPT_PATH_STOP)) { + if (file_is_executable(RC_LOCAL_SCRIPT_PATH_STOP)) { log_debug("Automatically adding halt-local.service."); if (add_symlink("halt-local.service", "final.target") < 0)