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

View File

@ -22,6 +22,9 @@ int main()
{ {
initialize_stdio(); initialize_stdio();
if (signal(SIGINT, [](int) {}) == SIG_ERR)
perror("signal");
bool first = true; bool first = true;
while (true) while (true)
@ -85,9 +88,15 @@ int main()
perror("fork"); perror("fork");
break; break;
} }
if (tcsetpgrp(0, pid) == -1)
perror("tcsetpgrp");
int status; int status;
waitpid(pid, &status, 0); waitpid(pid, &status, 0);
if (tcsetpgrp(0, getpid()) == -1)
perror("tcsetpgrp");
} }
} }