mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:57:45 +00:00
sh: Discard the current line on interrupt.
This commit is contained in:
parent
c6fdde37e7
commit
6e5db34b2e
1 changed files with 11 additions and 2 deletions
|
@ -20,6 +20,7 @@ struct GlobalState {
|
||||||
pid_t sid;
|
pid_t sid;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
termios termios;
|
termios termios;
|
||||||
|
bool was_interrupted { false };
|
||||||
};
|
};
|
||||||
static GlobalState* g;
|
static GlobalState* g;
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ void did_receive_signal(int signum)
|
||||||
|
|
||||||
void handle_sigint(int)
|
void handle_sigint(int)
|
||||||
{
|
{
|
||||||
printf("Interrupt received by sh\n");
|
g->was_interrupted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sh_busy(int, char**)
|
static int sh_busy(int, char**)
|
||||||
|
@ -409,7 +410,15 @@ int main(int, char**)
|
||||||
ssize_t nread = read(0, keybuf, sizeof(keybuf));
|
ssize_t nread = read(0, keybuf, sizeof(keybuf));
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
// Ignore. :^)
|
ASSERT(g->was_interrupted);
|
||||||
|
if (linedx != 0)
|
||||||
|
printf("^C");
|
||||||
|
g->was_interrupted = false;
|
||||||
|
linebuf[0] = '\0';
|
||||||
|
linedx = 0;
|
||||||
|
putchar('\n');
|
||||||
|
prompt();
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
perror("read failed");
|
perror("read failed");
|
||||||
return 2;
|
return 2;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue