From: Zbigniew Jędrzejewski-Szmek Date: Fri, 13 Mar 2020 14:50:37 +0000 (+0100) Subject: systemctl: emit notice about some kernel commandline options X-Git-Tag: v246-rc1~737^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5e59431c53645a6f506fa4270fdc0063ee27c927;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 07f060e9534..2cefcac693e 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);