]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/system-update-generator/system-update-generator.c
treewide: use log_*_errno whenever %m is in the format string
[thirdparty/systemd.git] / src / system-update-generator / system-update-generator.c
CommitLineData
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"
26#include "util.h"
27#include "unit-name.h"
28#include "path-util.h"
29
399c5f96
LP
30/*
31 * Implements the logic described in
32 * http://freedesktop.org/wiki/Software/systemd/SystemUpdates
33 */
34
d360705f
LP
35static const char *arg_dest = "/tmp";
36
37static int generate_symlink(void) {
9194c8e4 38 const char *p = NULL;
d360705f 39
9194c8e4 40 if (access("/system-update", F_OK) < 0) {
d360705f
LP
41 if (errno == ENOENT)
42 return 0;
43
56f64d95 44 log_error_errno(errno, "Failed to check for system update: %m");
d360705f
LP
45 return -EINVAL;
46 }
47
9194c8e4 48 p = strappenda(arg_dest, "/default.target");
d360705f 49 if (symlink(SYSTEM_DATA_UNIT_PATH "/system-update.target", p) < 0) {
56f64d95 50 log_error_errno(errno, "Failed to create symlink %s: %m", p);
d360705f
LP
51 return -errno;
52 }
53
d360705f
LP
54 return 0;
55}
56
57int main(int argc, char *argv[]) {
58 int r;
59
07719a21
LP
60 if (argc > 1 && argc != 4) {
61 log_error("This program takes three or no arguments.");
d360705f
LP
62 return EXIT_FAILURE;
63 }
64
65 if (argc > 1)
07719a21 66 arg_dest = argv[2];
d360705f 67
a6903061 68 log_set_target(LOG_TARGET_SAFE);
d360705f
LP
69 log_parse_environment();
70 log_open();
71
72 umask(0022);
73
74 r = generate_symlink();
75
76 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
77}