]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/system-update-generator/system-update-generator.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
8 #include "proc-cmdline.h"
10 #include "string-util.h"
14 * Implements the logic described in systemd.offline-updates(7).
17 static const char *arg_dest
= "/tmp";
19 static int generate_symlink(void) {
22 if (laccess("/system-update", F_OK
) < 0) {
26 log_error_errno(errno
, "Failed to check for system update: %m");
30 p
= strjoina(arg_dest
, "/" SPECIAL_DEFAULT_TARGET
);
31 if (symlink(SYSTEM_DATA_UNIT_PATH
"/system-update.target", p
) < 0)
32 return log_error_errno(errno
, "Failed to create symlink %s: %m", p
);
37 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
40 /* Check if a run level is specified on the kernel command line. The
41 * command line has higher priority than any on-disk configuration, so
42 * it'll make any symlink we create moot.
45 if (streq(key
, "systemd.unit") && !proc_cmdline_value_missing(key
, value
))
46 log_warning("Offline system update overridden by kernel command line systemd.unit= setting");
47 else if (!value
&& runlevel_to_target(key
))
48 log_warning("Offline system update overridden by runlevel \"%s\" on the kernel command line", key
);
53 int main(int argc
, char *argv
[]) {
56 if (argc
> 1 && argc
!= 4) {
57 log_error("This program takes three or no arguments.");
64 log_set_prohibit_ipc(true);
65 log_set_target(LOG_TARGET_AUTO
);
66 log_parse_environment();
71 r
= generate_symlink();
74 k
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
76 log_warning_errno(k
, "Failed to parse kernel command line, ignoring: %m");
79 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;