From a4c117c36c0b8d6289a5c7dcd15d07ef3e0e0e22 Mon Sep 17 00:00:00 2001 From: Matheus Date: Wed, 1 May 2024 21:36:42 -0300 Subject: [PATCH] main: set controlling tty --- tools/init/main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/init/main.c b/tools/init/main.c index 62898203..3e9d8f64 100644 --- a/tools/init/main.c +++ b/tools/init/main.c @@ -3,6 +3,7 @@ #include #include #include +#include int main() { printf("init: Welcome to Astral!\n"); @@ -50,6 +51,21 @@ int main() { return EXIT_FAILURE; } + // open /dev/console but as the controlling terminal + printf("init: reopening /dev/console as the controlling terminal\n"); + int rfd = open("/dev/console", O_RDONLY); + int wfd = open("/dev/console", O_WRONLY); + close(0); + close(1); + close(2); + + dup2(rfd, 0); + dup2(wfd, 1); + dup2(wfd, 2); + + close(rfd); + close(wfd); + // start user shell printf("init: running /usr/bin/bash\n"); pid = fork();