1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-02-15 05:57:26 +03:00

systemctl: print a notice when set-default is not effective

$ sudo ln -svf multi-user.target /run/systemd/generator.early/default.target
'/run/systemd/generator.early/default.target' -> 'multi-user.target'
$ sudo build/systemctl set-default --root=/ sysinit.target
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/sysinit.target.
Note: "multi-user.target" is the default unit (possibly a runtime override).

The output is not super informative, but it should be enough to point the user in
the right direction.

Fixes #3645.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-03-13 17:57:06 +01:00
parent 5e59431c53
commit 12877da215

View File

@ -2100,21 +2100,20 @@ static void emit_cmdline_warning(void) {
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;
const char *path;
static int determine_default(char **ret_name) {
int r;
if (install_client_side()) {
r = unit_file_get_default(arg_scope, arg_root, &_path);
r = unit_file_get_default(arg_scope, arg_root, ret_name);
if (r < 0)
return log_error_errno(r, "Failed to get default target: %m");
path = _path;
return 0;
} else {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus *bus;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
const char *name;
r = acquire_bus(BUS_MANAGER, &bus);
if (r < 0)
@ -2132,13 +2131,23 @@ static int get_default(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_error_errno(r, "Failed to get default target: %s", bus_error_message(&error, r));
r = sd_bus_message_read(reply, "s", &path);
r = sd_bus_message_read(reply, "s", &name);
if (r < 0)
return bus_log_parse_error(r);
}
if (path)
printf("%s\n", path);
return free_and_strdup_warn(ret_name, name);
}
}
static int get_default(int argc, char *argv[], void *userdata) {
_cleanup_free_ char *name = NULL;
int r;
r = determine_default(&name);
if (r < 0)
return r;
printf("%s\n", name);
emit_cmdline_warning();
@ -2202,6 +2211,17 @@ static int set_default(int argc, char *argv[], void *userdata) {
emit_cmdline_warning();
if (!arg_quiet) {
_cleanup_free_ char *final = NULL;
r = determine_default(&final);
if (r < 0)
return r;
if (!streq(final, unit))
log_notice("Note: \"%s\" is the default unit (possibly a runtime override).", final);
}
finish:
unit_file_changes_free(changes, n_changes);