]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/system-update-generator/system-update-generator.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
9 #include "proc-cmdline.h"
11 #include "string-util.h"
15 * Implements the logic described in systemd.offline-updates(7).
18 static const char *arg_dest
= NULL
;
20 static int generate_symlink(void) {
23 if (laccess("/system-update", F_OK
) < 0) {
27 log_error_errno(errno
, "Failed to check for system update: %m");
31 p
= strjoina(arg_dest
, "/" SPECIAL_DEFAULT_TARGET
);
32 if (symlink(SYSTEM_DATA_UNIT_PATH
"/system-update.target", p
) < 0)
33 return log_error_errno(errno
, "Failed to create symlink %s: %m", p
);
38 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
41 /* Check if a run level is specified on the kernel command line. The
42 * command line has higher priority than any on-disk configuration, so
43 * it'll make any symlink we create moot.
46 if (streq(key
, "systemd.unit") && !proc_cmdline_value_missing(key
, value
))
47 log_warning("Offline system update overridden by kernel command line systemd.unit= setting");
48 else if (!value
&& runlevel_to_target(key
))
49 log_warning("Offline system update overridden by runlevel \"%s\" on the kernel command line", key
);
54 static int run(const char *dest
, const char *dest_early
, const char *dest_late
) {
57 assert_se(arg_dest
= dest_early
);
59 r
= generate_symlink();
63 /* We parse the command line only to emit warnings. */
64 r
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
66 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
71 DEFINE_MAIN_GENERATOR_FUNCTION(run
);