mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
main: set controlling tty
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <pwd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user