summaryrefslogtreecommitdiff
path: root/src/systemctl
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-03-13 17:57:06 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-03-17 12:11:09 +0100
commit12877da21508c6e55e3421930ad1781b982e1155 (patch)
tree430c2076c1b9ed962c1206fd886d92c8d09ff809 /src/systemctl
parent5e59431c53645a6f506fa4270fdc0063ee27c927 (diff)
downloadsystemd-12877da21508c6e55e3421930ad1781b982e1155.tar.gz
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.
Diffstat (limited to 'src/systemctl')
-rw-r--r--src/systemctl/systemctl.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 2cefcac693..ba3fe9ec2f 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -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);
+
+ 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;
- if (path)
- printf("%s\n", path);
+ 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);