]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2012 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include <errno.h> | |
21 | #include <unistd.h> | |
22 | ||
db2df898 | 23 | #include "fs-util.h" |
663996b3 | 24 | #include "log.h" |
db2df898 | 25 | #include "string-util.h" |
663996b3 | 26 | #include "util.h" |
663996b3 MS |
27 | |
28 | /* | |
29 | * Implements the logic described in | |
30 | * http://freedesktop.org/wiki/Software/systemd/SystemUpdates | |
31 | */ | |
32 | ||
33 | static const char *arg_dest = "/tmp"; | |
34 | ||
35 | static int generate_symlink(void) { | |
e842803a | 36 | const char *p = NULL; |
663996b3 | 37 | |
e735f4d4 | 38 | if (laccess("/system-update", F_OK) < 0) { |
663996b3 MS |
39 | if (errno == ENOENT) |
40 | return 0; | |
41 | ||
f47781d8 | 42 | log_error_errno(errno, "Failed to check for system update: %m"); |
663996b3 MS |
43 | return -EINVAL; |
44 | } | |
45 | ||
e735f4d4 | 46 | p = strjoina(arg_dest, "/default.target"); |
f47781d8 MP |
47 | if (symlink(SYSTEM_DATA_UNIT_PATH "/system-update.target", p) < 0) |
48 | return log_error_errno(errno, "Failed to create symlink %s: %m", p); | |
663996b3 MS |
49 | |
50 | return 0; | |
51 | } | |
52 | ||
53 | int main(int argc, char *argv[]) { | |
54 | int r; | |
55 | ||
56 | if (argc > 1 && argc != 4) { | |
57 | log_error("This program takes three or no arguments."); | |
58 | return EXIT_FAILURE; | |
59 | } | |
60 | ||
61 | if (argc > 1) | |
62 | arg_dest = argv[2]; | |
63 | ||
64 | log_set_target(LOG_TARGET_SAFE); | |
65 | log_parse_environment(); | |
66 | log_open(); | |
67 | ||
68 | umask(0022); | |
69 | ||
70 | r = generate_symlink(); | |
71 | ||
72 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
73 | } |