Kernel: Userspace sets the foreground process and Shell handles ^C

This commit is contained in:
Bananymous
2023-07-28 18:10:36 +03:00
parent 9279bbbd19
commit 925df39107
2 changed files with 25 additions and 1 deletions

View File

@@ -380,10 +380,16 @@ int execute_command(BAN::Vector<BAN::String>& args)
if (pid == -1)
ERROR_RETURN("fork", 1);
if (tcsetpgrp(0, pid) == -1)
ERROR_RETURN("tcsetpgrp", 1);
int status;
if (waitpid(pid, &status, 0) == -1)
ERROR_RETURN("waitpid", 1);
if (tcsetpgrp(0, getpid()) == -1)
ERROR_RETURN("tcsetpgrp", 1);
return status;
}
@@ -489,6 +495,9 @@ int main(int argc, char** argv)
{
argv0 = argv[0];
if (signal(SIGINT, [](int) {}) == SIG_ERR)
perror("signal");
if (argc >= 2)
{
if (strcmp(argv[1], "-c") == 0)
@@ -599,6 +608,12 @@ int main(int argc, char** argv)
fflush(stdout);
}
break;
case '\x03': // ^C
fputc('\n', stdout);
print_prompt();
buffers[index].clear();
col = 0;
break;
case '\n':
fputc('\n', stdout);
if (!buffers[index].empty())