summaryrefslogtreecommitdiffstats
path: root/src/systemctl
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-03-13 15:50:37 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-03-13 17:52:19 +0100
commit5e59431c53645a6f506fa4270fdc0063ee27c927 (patch)
treefb96b11778d0f85720558f229238970bffcdb6ce /src/systemctl
parentcore: consistently emit oom warning when parsing args (diff)
downloadsystemd-5e59431c53645a6f506fa4270fdc0063ee27c927.tar.xz
systemd-5e59431c53645a6f506fa4270fdc0063ee27c927.zip
systemctl: emit notice about some kernel commandline options
Things can be pretty confusing when there's a commandline option overrding the configured default... Let's be nice to the user and emit a warning.
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 07f060e953..2cefcac693 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2065,6 +2065,41 @@ static int list_machines(int argc, char *argv[], void *userdata) {
return rc;
}
+static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
+ char **ret = data;
+
+ if (streq(key, "systemd.unit")) {
+ if (proc_cmdline_value_missing(key, value))
+ return 0;
+ if (!unit_name_is_valid(value, UNIT_NAME_PLAIN|UNIT_NAME_INSTANCE))
+ return log_warning("Unit name specified on %s= is not valid, ignoring: %s", key, value);
+
+ return free_and_strdup_warn(ret, key);
+
+ } else if (!value) {
+ if (runlevel_to_target(key))
+ return free_and_strdup_warn(ret, key);
+ }
+
+ return 0;
+}
+
+static void emit_cmdline_warning(void) {
+ if (arg_quiet || arg_root)
+ /* don't bother checking the commandline if we're operating on a container */
+ return;
+
+ _cleanup_free_ char *override = NULL;
+ int r;
+
+ r = proc_cmdline_parse(parse_proc_cmdline_item, &override, 0);
+ if (r < 0)
+ log_debug_errno(r, "Failed to parse kernel command line, ignoring: %m");
+ if (override)
+ log_notice("Note: found \"%s\" on the kernel commandline, which overrides the default unit.",
+ override);
+}
+
static int get_default(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ char *_path = NULL;
@@ -2077,7 +2112,6 @@ static int get_default(int argc, char *argv[], void *userdata) {
return log_error_errno(r, "Failed to get default target: %m");
path = _path;
- r = 0;
} else {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus *bus;
@@ -2106,6 +2140,8 @@ static int get_default(int argc, char *argv[], void *userdata) {
if (path)
printf("%s\n", path);
+ emit_cmdline_warning();
+
return 0;
}
@@ -2164,6 +2200,8 @@ static int set_default(int argc, char *argv[], void *userdata) {
r = 0;
}
+ emit_cmdline_warning();
+
finish:
unit_file_changes_free(changes, n_changes);