]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
15673083 MS |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
6 | Copyright 2011 Michal Schmidt | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
9 | under the terms of the GNU Lesser General Public License as published by |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
15673083 MS |
11 | (at your option) any later version. |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 16 | Lesser General Public License for more details. |
15673083 | 17 | |
5430f7f2 | 18 | You should have received a copy of the GNU Lesser General Public License |
15673083 MS |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
20 | ***/ | |
21 | ||
22 | #include <errno.h> | |
23 | #include <stdio.h> | |
24 | #include <unistd.h> | |
25 | ||
b5efdb8a | 26 | #include "alloc-util.h" |
15673083 | 27 | #include "log.h" |
49e942b2 | 28 | #include "mkdir.h" |
07630cea LP |
29 | #include "string-util.h" |
30 | #include "util.h" | |
15673083 | 31 | |
dd422d1e | 32 | static const char *arg_dest = "/tmp"; |
15673083 | 33 | |
04b6f7c1 | 34 | static int add_symlink(const char *service, const char *where) { |
7b1132f6 | 35 | _cleanup_free_ char *from = NULL, *to = NULL; |
15673083 MS |
36 | int r; |
37 | ||
38 | assert(service); | |
7b1132f6 | 39 | assert(where); |
15673083 | 40 | |
605405c6 | 41 | from = strjoin(SYSTEM_DATA_UNIT_PATH, "/", service); |
7b1132f6 LP |
42 | if (!from) |
43 | return log_oom(); | |
15673083 | 44 | |
605405c6 | 45 | to = strjoin(arg_dest, "/", where, ".wants/", service); |
7b1132f6 LP |
46 | if (!to) |
47 | return log_oom(); | |
15673083 | 48 | |
d2e54fae | 49 | mkdir_parents_label(to, 0755); |
15673083 MS |
50 | |
51 | r = symlink(from, to); | |
52 | if (r < 0) { | |
53 | if (errno == EEXIST) | |
7b1132f6 | 54 | return 0; |
15673083 | 55 | |
e1427b13 | 56 | return log_error_errno(errno, "Failed to create symlink %s: %m", to); |
7b1132f6 | 57 | } |
15673083 | 58 | |
7b1132f6 | 59 | return 1; |
15673083 MS |
60 | } |
61 | ||
62 | int main(int argc, char *argv[]) { | |
15673083 MS |
63 | int r = EXIT_SUCCESS; |
64 | ||
07719a21 LP |
65 | if (argc > 1 && argc != 4) { |
66 | log_error("This program takes three or no arguments."); | |
15673083 MS |
67 | return EXIT_FAILURE; |
68 | } | |
69 | ||
07719a21 LP |
70 | if (argc > 1) |
71 | arg_dest = argv[1]; | |
72 | ||
a6903061 | 73 | log_set_target(LOG_TARGET_SAFE); |
15673083 MS |
74 | log_parse_environment(); |
75 | log_open(); | |
76 | ||
07719a21 | 77 | umask(0022); |
15673083 | 78 | |
7b1132f6 | 79 | if (access(RC_LOCAL_SCRIPT_PATH_START, X_OK) >= 0) { |
15673083 MS |
80 | log_debug("Automatically adding rc-local.service."); |
81 | ||
04b6f7c1 | 82 | if (add_symlink("rc-local.service", "multi-user.target") < 0) |
15673083 | 83 | r = EXIT_FAILURE; |
04b6f7c1 | 84 | } |
15673083 | 85 | |
7b1132f6 | 86 | if (access(RC_LOCAL_SCRIPT_PATH_STOP, X_OK) >= 0) { |
04b6f7c1 LP |
87 | log_debug("Automatically adding halt-local.service."); |
88 | ||
89 | if (add_symlink("halt-local.service", "final.target") < 0) | |
90 | r = EXIT_FAILURE; | |
15673083 MS |
91 | } |
92 | ||
93 | return r; | |
94 | } |