summaryrefslogtreecommitdiff
path: root/src/sulogin-shell
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-04-21 13:01:24 +0200
committerLennart Poettering <lennart@poettering.net>2023-04-21 16:46:06 +0200
commit750d9859c139e0fac9d29d3e3147a4367f0fc764 (patch)
tree67ce66642ab6a8bb4f4ba53ed6c291ea4e2657b9 /src/sulogin-shell
parentb676a9483731258359156703b031b3c7325ccd15 (diff)
downloadsystemd-750d9859c139e0fac9d29d3e3147a4367f0fc764.tar.gz
sulogin-shell: Start initrd.target on exit in the initrd
sulogin is documented to continue booting up on exit. To do that in the initrd, we need to start initrd.target and not default.target.
Diffstat (limited to 'src/sulogin-shell')
-rw-r--r--src/sulogin-shell/sulogin-shell.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/sulogin-shell/sulogin-shell.c b/src/sulogin-shell/sulogin-shell.c
index dd80d6f7c9..87eed541f0 100644
--- a/src/sulogin-shell/sulogin-shell.c
+++ b/src/sulogin-shell/sulogin-shell.c
@@ -13,6 +13,7 @@
#include "bus-error.h"
#include "constants.h"
#include "env-util.h"
+#include "initrd-util.h"
#include "log.h"
#include "main-func.h"
#include "process-util.h"
@@ -43,12 +44,12 @@ static int reload_manager(sd_bus *bus) {
return 0;
}
-static int default_target_is_inactive(sd_bus *bus) {
+static int target_is_inactive(sd_bus *bus, const char *target) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ char *path = NULL, *state = NULL;
int r;
- path = unit_dbus_path_from_name(SPECIAL_DEFAULT_TARGET);
+ path = unit_dbus_path_from_name(target);
if (!path)
return log_oom();
@@ -65,11 +66,11 @@ static int default_target_is_inactive(sd_bus *bus) {
return streq_ptr(state, "inactive");
}
-static int start_default_target(sd_bus *bus) {
+static int start_target(sd_bus *bus, const char *target) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
- log_info("Starting "SPECIAL_DEFAULT_TARGET);
+ log_info("Starting %s", target);
/* Start this unit only if we can replace basic.target with it */
r = bus_call_method(
@@ -78,10 +79,10 @@ static int start_default_target(sd_bus *bus) {
"StartUnit",
&error,
NULL,
- "ss", SPECIAL_DEFAULT_TARGET, "isolate");
+ "ss", target, "isolate");
if (r < 0)
- return log_error_errno(r, "Failed to start "SPECIAL_DEFAULT_TARGET": %s", bus_error_message(&error, r));
+ return log_error_errno(r, "Failed to start %s: %s", target, bus_error_message(&error, r));
return 0;
}
@@ -105,8 +106,7 @@ static int fork_wait(const char* const cmdline[]) {
static void print_mode(const char* mode) {
printf("You are in %s mode. After logging in, type \"journalctl -xb\" to view\n"
- "system logs, \"systemctl reboot\" to reboot, \"systemctl default\" or \"exit\"\n"
- "to boot into default mode.\n", mode);
+ "system logs, \"systemctl reboot\" to reboot, or \"exit\"\n" "to continue bootup.\n", mode);
fflush(stdout);
}
@@ -140,15 +140,17 @@ static int run(int argc, char *argv[]) {
if (reload_manager(bus) < 0)
goto fallback;
- r = default_target_is_inactive(bus);
+ const char *target = in_initrd() ? SPECIAL_INITRD_TARGET : SPECIAL_DEFAULT_TARGET;
+
+ r = target_is_inactive(bus, target);
if (r < 0)
goto fallback;
if (!r) {
- log_warning(SPECIAL_DEFAULT_TARGET" is not inactive. Please review the "SPECIAL_DEFAULT_TARGET" setting.\n");
+ log_warning("%s is not inactive. Please review the %s setting.\n", target, target);
goto fallback;
}
- if (start_default_target(bus) >= 0)
+ if (start_target(bus, target) >= 0)
break;
fallback: