Relaunch the debug shell after it exits. (#13379)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Ben Hillis committed
Aug 13, 2025 at 16:31 UTC
fd3b8580640b4269ad81e51849978e179cc3082d
1 file changed
+21
-3
src/linux/init/main.cpp
+21
-3
@@ -1194,9 +1194,27 @@ Return Value:
1194
--*/
1195
1196
{
1197
- UtilCreateChildProcess("agetty", []() {
1198
- execl("/usr/bin/setsid", "/usr/bin/setsid", "/sbin/agetty", "-w", "-L", LX_INIT_HVC_DEBUG_SHELL, "-a", "root", NULL);
1199
- LOG_ERROR("execl failed, {}", errno);
1197
+ // Spawn a child process to handle relaunching the debug shell if it exits.
1198
+ UtilCreateChildProcess("DebugShell", []() {
1199
+ for (;;)
1200
+ {
1201
+ const auto Pid = UtilCreateChildProcess("agetty", []() {
1202
+ execl("/usr/bin/setsid", "/usr/bin/setsid", "/sbin/agetty", "-w", "-L", LX_INIT_HVC_DEBUG_SHELL, "-a", "root", NULL);
1203
+ LOG_ERROR("execl failed, {}", errno);
1204
+ });
1205
+
1206
+ if (Pid < 0)
1207
+ {
1208
+ _exit(1);
1209
+ }
1210
+
1211
+ int Status = -1;
1212
+ if (TEMP_FAILURE_RETRY(waitpid(Pid, &Status, 0)) < 0)
1213
+ {
1214
+ LOG_ERROR("waitpid failed {}", errno);
1215
+ _exit(1);
1216
+ }
1217
+ }
1218
});
1219
}
1220