]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/system-update-generator/system-update-generator.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2012 Lennart Poettering
13 #include "proc-cmdline.h"
15 #include "string-util.h"
19 * Implements the logic described in systemd.offline-updates(7).
22 static const char *arg_dest
= "/tmp";
24 static int generate_symlink(void) {
27 if (laccess("/system-update", F_OK
) < 0) {
31 log_error_errno(errno
, "Failed to check for system update: %m");
35 p
= strjoina(arg_dest
, "/" SPECIAL_DEFAULT_TARGET
);
36 if (symlink(SYSTEM_DATA_UNIT_PATH
"/system-update.target", p
) < 0)
37 return log_error_errno(errno
, "Failed to create symlink %s: %m", p
);
42 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
45 /* Check if a run level is specified on the kernel command line. The
46 * command line has higher priority than any on-disk configuration, so
47 * it'll make any symlink we create moot.
50 if (streq(key
, "systemd.unit") && !proc_cmdline_value_missing(key
, value
))
51 log_warning("Offline system update overriden by kernel command line systemd.unit= setting");
52 else if (!value
&& runlevel_to_target(key
))
53 log_warning("Offline system update overriden by runlevel \"%s\" on the kernel command line", key
);
58 int main(int argc
, char *argv
[]) {
61 if (argc
> 1 && argc
!= 4) {
62 log_error("This program takes three or no arguments.");
69 log_set_prohibit_ipc(true);
70 log_set_target(LOG_TARGET_AUTO
);
71 log_parse_environment();
76 r
= generate_symlink();
79 k
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
81 log_warning_errno(k
, "Failed to parse kernel command line, ignoring: %m");
84 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;