mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
main: set controlling tty
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printf("init: Welcome to Astral!\n");
|
printf("init: Welcome to Astral!\n");
|
||||||
@@ -50,6 +51,21 @@ int main() {
|
|||||||
return EXIT_FAILURE;
|
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
|
// start user shell
|
||||||
printf("init: running /usr/bin/bash\n");
|
printf("init: running /usr/bin/bash\n");
|
||||||
pid = fork();
|
pid = fork();
|
||||||
|
|||||||
Reference in New Issue
Block a user