1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
7 Copyright 2011 Michal Schmidt
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
31 #ifndef RC_LOCAL_SCRIPT_PATH_START
32 #define RC_LOCAL_SCRIPT_PATH_START "/etc/rc.d/rc.local"
35 #ifndef RC_LOCAL_SCRIPT_PATH_STOP
36 #define RC_LOCAL_SCRIPT_PATH_STOP "/sbin/halt.local"
39 const char *arg_dest = "/tmp";
41 static int add_symlink(const char *service, const char *where) {
42 char *from = NULL, *to = NULL;
47 asprintf(&from, SYSTEM_DATA_UNIT_PATH "/%s", service);
48 asprintf(&to, "%s/%s.wants/%s", arg_dest, where, service);
55 mkdir_parents_label(to, 0755);
57 r = symlink(from, to);
62 log_error("Failed to create symlink from %s to %s: %m", from, to);
74 static bool file_is_executable(const char *f) {
80 return S_ISREG(st.st_mode) && (st.st_mode & 0111);
83 int main(int argc, char *argv[]) {
86 if (argc > 1 && argc != 4) {
87 log_error("This program takes three or no arguments.");
94 log_set_target(LOG_TARGET_SAFE);
95 log_parse_environment();
100 if (file_is_executable(RC_LOCAL_SCRIPT_PATH_START)) {
101 log_debug("Automatically adding rc-local.service.");
103 if (add_symlink("rc-local.service", "multi-user.target") < 0)
107 if (file_is_executable(RC_LOCAL_SCRIPT_PATH_STOP)) {
108 log_debug("Automatically adding halt-local.service.");
110 if (add_symlink("halt-local.service", "final.target") < 0)