From bab84272755aff9dca5ddef545bca9ee91517738 Mon Sep 17 00:00:00 2001 From: Matheus Date: Wed, 22 May 2024 09:48:35 -0300 Subject: [PATCH] init: create new process group for shell and make it the foreground --- tools/init/main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/init/main.c b/tools/init/main.c index 074f29b0..2b6cf090 100644 --- a/tools/init/main.c +++ b/tools/init/main.c @@ -81,6 +81,17 @@ int main(int argc, char *argv[]) { } if (pid == 0) { + // create its own process group and set is as the foreground group + if (setpgid(0, 0) == -1) { + perror("init: setpgrp failed"); + return EXIT_FAILURE; + } + + if (tcsetpgrp(0, getpid()) == -1) { + perror("init: tcsetpgrp failed"); + return EXIT_FAILURE; + } + execl("/usr/bin/bash", "/usr/bin/bash", "-l", NULL); perror("init: execl /usr/bin/bash failed"); return EXIT_FAILURE;