diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-05-09 17:06:46 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-05-09 17:07:37 +0900 |
commit | fb507898a3a697697173a3f6010f51166803489b (patch) | |
tree | 4f18b66d5a7910014426cc3b4a2aaa2943497e0e /src | |
parent | f7e29336778534b42f0a6bc57524c5b4c22e90fe (diff) | |
download | systemd-fb507898a3a697697173a3f6010f51166803489b.tar.gz |
bus-util: print a friendly message when PID1 is not systemd
Follow-up for 861f16d2679eeda79e8185057cef24653913e300.
Fixes #8913.
Diffstat (limited to 'src')
-rw-r--r-- | src/analyze/analyze.c | 6 | ||||
-rw-r--r-- | src/shared/bus-util.c | 20 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 6 |
3 files changed, 20 insertions, 12 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 43b0cc1ab8..30139dd5f5 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -120,10 +120,12 @@ struct host_info { static int acquire_bus(sd_bus **bus, bool *use_full_bus) { bool user = arg_scope != UNIT_FILE_SYSTEM; + int r; if (use_full_bus && *use_full_bus) { - if (bus_connect_transport(arg_transport, arg_host, user, bus) == 0) - return 0; + r = bus_connect_transport(arg_transport, arg_host, user, bus); + if (IN_SET(r, 0, -EHOSTDOWN)) + return r; *use_full_bus = false; } diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index a14e87d1ba..af18a674c1 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1300,9 +1300,15 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s case BUS_TRANSPORT_LOCAL: if (user) r = sd_bus_default_user(&bus); - else - r = sd_bus_default_system(&bus); + else { + if (sd_booted() <= 0) { + /* Print a friendly message when the local system is actually not running systemd as PID 1. */ + log_error("System has not been booted with systemd as init system (PID 1). Can't operate."); + return -EHOSTDOWN; + } + r = sd_bus_default_system(&bus); + } break; case BUS_TRANSPORT_REMOTE: @@ -1343,9 +1349,15 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, bool case BUS_TRANSPORT_LOCAL: if (user) r = bus_connect_user_systemd(bus); - else - r = bus_connect_system_systemd(bus); + else { + if (sd_booted() <= 0) { + /* Print a friendly message when the local system is actually not running systemd as PID 1. */ + log_error("System has not been booted with systemd as init system (PID 1). Can't operate."); + return -EHOSTDOWN; + } + r = bus_connect_system_systemd(bus); + } break; case BUS_TRANSPORT_REMOTE: diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index a9461aa391..a6646aa7f6 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -211,12 +211,6 @@ static int acquire_bus(BusFocus focus, sd_bus **ret) { user = arg_scope != UNIT_FILE_SYSTEM; - if (!user && sd_booted() <= 0) { - /* Print a friendly message when the local system is actually not running systemd as PID 1. */ - log_error("System has not been booted with systemd as init system (PID 1). Can't operate."); - return -EHOSTDOWN; - } - if (focus == BUS_MANAGER) r = bus_connect_transport_systemd(arg_transport, arg_host, user, &busses[focus]); else |