]>
Commit | Line | Data |
---|---|---|
d360705f LP |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2012 Lennart Poettering | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
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 | |
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 | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #include <errno.h> | |
23 | #include <unistd.h> | |
24 | ||
25 | #include "log.h" | |
07630cea | 26 | #include "string-util.h" |
d360705f | 27 | #include "util.h" |
d360705f | 28 | |
399c5f96 LP |
29 | /* |
30 | * Implements the logic described in | |
31 | * http://freedesktop.org/wiki/Software/systemd/SystemUpdates | |
32 | */ | |
33 | ||
d360705f LP |
34 | static const char *arg_dest = "/tmp"; |
35 | ||
36 | static int generate_symlink(void) { | |
9194c8e4 | 37 | const char *p = NULL; |
d360705f | 38 | |
6b321a79 | 39 | if (laccess("/system-update", F_OK) < 0) { |
d360705f LP |
40 | if (errno == ENOENT) |
41 | return 0; | |
42 | ||
56f64d95 | 43 | log_error_errno(errno, "Failed to check for system update: %m"); |
d360705f LP |
44 | return -EINVAL; |
45 | } | |
46 | ||
63c372cb | 47 | p = strjoina(arg_dest, "/default.target"); |
4a62c710 MS |
48 | if (symlink(SYSTEM_DATA_UNIT_PATH "/system-update.target", p) < 0) |
49 | return log_error_errno(errno, "Failed to create symlink %s: %m", p); | |
d360705f | 50 | |
d360705f LP |
51 | return 0; |
52 | } | |
53 | ||
54 | int main(int argc, char *argv[]) { | |
55 | int r; | |
56 | ||
07719a21 LP |
57 | if (argc > 1 && argc != 4) { |
58 | log_error("This program takes three or no arguments."); | |
d360705f LP |
59 | return EXIT_FAILURE; |
60 | } | |
61 | ||
62 | if (argc > 1) | |
07719a21 | 63 | arg_dest = argv[2]; |
d360705f | 64 | |
a6903061 | 65 | log_set_target(LOG_TARGET_SAFE); |
d360705f LP |
66 | log_parse_environment(); |
67 | log_open(); | |
68 | ||
69 | umask(0022); | |
70 | ||
71 | r = generate_symlink(); | |
72 | ||
73 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
74 | } |