forked from Bananymous/banan-os
Kernel: Userspace sets the foreground process and Shell handles ^C
This commit is contained in:
parent
a5813f9ba5
commit
00f1f30a08
|
@ -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())
|
||||
|
|
|
@ -22,6 +22,9 @@ int main()
|
|||
{
|
||||
initialize_stdio();
|
||||
|
||||
if (signal(SIGINT, [](int) {}) == SIG_ERR)
|
||||
perror("signal");
|
||||
|
||||
bool first = true;
|
||||
|
||||
while (true)
|
||||
|
@ -86,8 +89,14 @@ int main()
|
|||
break;
|
||||
}
|
||||
|
||||
if (tcsetpgrp(0, pid) == -1)
|
||||
perror("tcsetpgrp");
|
||||
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
|
||||
if (tcsetpgrp(0, getpid()) == -1)
|
||||
perror("tcsetpgrp");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue