1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 #include "initrd-util.h"
10 #include "path-util.h"
11 #include "proc-cmdline.h"
13 #include "string-util.h"
14 #include "unit-file.h"
17 * Implements the logic described in systemd.offline-updates(7).
20 static const char *arg_dest
= NULL
;
22 static int generate_symlink(void) {
23 FOREACH_STRING(p
, "/system-update", "/etc/system-update") {
24 if (laccess(p
, F_OK
) >= 0) {
25 _cleanup_free_
char *j
= NULL
;
27 j
= path_join(arg_dest
, SPECIAL_DEFAULT_TARGET
);
31 if (symlink(SYSTEM_DATA_UNIT_DIR
"/system-update.target", j
) < 0)
32 return log_error_errno(errno
, "Failed to create symlink %s: %m", j
);
38 log_warning_errno(errno
, "Failed to check if %s symlink exists, ignoring: %m", p
);
44 static int parse_proc_cmdline_item(const char *key
, const char *value
, void *data
) {
47 /* Check if a run level is specified on the kernel command line. The
48 * command line has higher priority than any on-disk configuration, so
49 * it'll make any symlink we create moot.
52 if (streq(key
, "systemd.unit") && !proc_cmdline_value_missing(key
, value
))
53 log_warning("Offline system update overridden by kernel command line systemd.unit= setting");
54 else if (!value
&& runlevel_to_target(key
))
55 log_warning("Offline system update overridden by runlevel \"%s\" on the kernel command line", key
);
60 static int run(const char *dest
, const char *dest_early
, const char *dest_late
) {
63 assert_se(arg_dest
= dest_early
);
66 log_debug("Skipping generator, running in the initrd.");
70 r
= generate_symlink();
74 /* We parse the command line only to emit warnings. */
75 r
= proc_cmdline_parse(parse_proc_cmdline_item
, NULL
, 0);
77 log_warning_errno(r
, "Failed to parse kernel command line, ignoring: %m");
82 DEFINE_MAIN_GENERATOR_FUNCTION(run
);