2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2012-05-22 19:48:51 +02:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2015-10-26 21:16:26 +01:00
|
|
|
#include "fs-util.h"
|
2018-11-19 21:32:11 +01:00
|
|
|
#include "generator.h"
|
2012-05-22 19:48:51 +02:00
|
|
|
#include "log.h"
|
2017-02-01 21:50:03 +01:00
|
|
|
#include "proc-cmdline.h"
|
2016-12-16 21:55:27 +01:00
|
|
|
#include "special.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
2019-08-01 14:25:14 +02:00
|
|
|
#include "unit-file.h"
|
2012-05-22 19:48:51 +02:00
|
|
|
#include "util.h"
|
|
|
|
|
2012-05-22 19:50:10 +02:00
|
|
|
/*
|
2016-12-16 21:55:27 +01:00
|
|
|
* Implements the logic described in systemd.offline-updates(7).
|
2012-05-22 19:50:10 +02:00
|
|
|
*/
|
|
|
|
|
2018-12-04 11:51:06 +01:00
|
|
|
static const char *arg_dest = NULL;
|
2012-05-22 19:48:51 +02:00
|
|
|
|
|
|
|
static int generate_symlink(void) {
|
2014-06-13 12:21:45 +02:00
|
|
|
const char *p = NULL;
|
2012-05-22 19:48:51 +02:00
|
|
|
|
2015-01-26 07:34:32 +01:00
|
|
|
if (laccess("/system-update", F_OK) < 0) {
|
2012-05-22 19:48:51 +02:00
|
|
|
if (errno == ENOENT)
|
|
|
|
return 0;
|
|
|
|
|
2014-11-28 19:29:59 +01:00
|
|
|
log_error_errno(errno, "Failed to check for system update: %m");
|
2012-05-22 19:48:51 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-12-16 21:55:27 +01:00
|
|
|
p = strjoina(arg_dest, "/" SPECIAL_DEFAULT_TARGET);
|
2014-11-28 19:57:32 +01:00
|
|
|
if (symlink(SYSTEM_DATA_UNIT_PATH "/system-update.target", p) < 0)
|
|
|
|
return log_error_errno(errno, "Failed to create symlink %s: %m", p);
|
2012-05-22 19:48:51 +02:00
|
|
|
|
2017-02-01 21:50:03 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
|
|
|
|
assert(key);
|
|
|
|
|
|
|
|
/* Check if a run level is specified on the kernel command line. The
|
|
|
|
* command line has higher priority than any on-disk configuration, so
|
|
|
|
* it'll make any symlink we create moot.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (streq(key, "systemd.unit") && !proc_cmdline_value_missing(key, value))
|
2018-06-18 22:43:12 +02:00
|
|
|
log_warning("Offline system update overridden by kernel command line systemd.unit= setting");
|
2017-02-01 21:50:03 +01:00
|
|
|
else if (!value && runlevel_to_target(key))
|
2018-06-18 22:43:12 +02:00
|
|
|
log_warning("Offline system update overridden by runlevel \"%s\" on the kernel command line", key);
|
2017-02-01 21:50:03 +01:00
|
|
|
|
2012-05-22 19:48:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-04 11:51:06 +01:00
|
|
|
static int run(const char *dest, const char *dest_early, const char *dest_late) {
|
|
|
|
int r;
|
2012-05-22 19:48:51 +02:00
|
|
|
|
2018-12-04 11:51:06 +01:00
|
|
|
assert_se(arg_dest = dest_early);
|
2012-05-22 19:48:51 +02:00
|
|
|
|
|
|
|
r = generate_symlink();
|
2019-06-07 11:49:03 +02:00
|
|
|
if (r <= 0)
|
2018-12-04 11:51:06 +01:00
|
|
|
return r;
|
2012-05-22 19:48:51 +02:00
|
|
|
|
2019-06-07 11:49:03 +02:00
|
|
|
/* We parse the command line only to emit warnings. */
|
2018-12-04 11:51:06 +01:00
|
|
|
r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
|
|
|
|
if (r < 0)
|
|
|
|
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
|
2017-02-01 21:50:03 +01:00
|
|
|
|
2018-12-04 11:51:06 +01:00
|
|
|
return 0;
|
2012-05-22 19:48:51 +02:00
|
|
|
}
|
2018-12-04 11:51:06 +01:00
|
|
|
|
|
|
|
DEFINE_MAIN_GENERATOR_FUNCTION(run);
|