From 69d7da4945448f4a6901b085e746e977359f465c Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 29 Aug 2022 21:58:15 +0200 Subject: user/termcook: make C-c kill the running process --- src/user/app/init/driver/termcook.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/user/app/init/driver/termcook.c') diff --git a/src/user/app/init/driver/termcook.c b/src/user/app/init/driver/termcook.c index c23d76f..818f8f9 100644 --- a/src/user/app/init/driver/termcook.c +++ b/src/user/app/init/driver/termcook.c @@ -29,6 +29,8 @@ static void line_editor(handle_t input, handle_t output) { linepos--; } break; + case 3: /* C-c */ + _syscall_exit(1); case 4: /* EOT, C-d */ if (linepos > 0) { w_output(output, linebuf, linepos); @@ -61,13 +63,18 @@ void termcook(void) { if (_syscall_pipe(stdin_pipe, 0) < 0) return; + if (!fork()) { + /* the caller continues in a child process, + * so it can be killed when the line editor quits */ + _syscall_dup(stdin_pipe[0], 0, 0); + close(stdin_pipe[0]); + close(stdin_pipe[1]); + return; + } if (!fork()) { close(stdin_pipe[0]); line_editor(0, stdin_pipe[1]); exit(0); } - /* 0 is stdin, like in unix */ - _syscall_dup(stdin_pipe[0], 0, 0); - close(stdin_pipe[0]); - close(stdin_pipe[1]); + exit(_syscall_await()); } -- cgit v1.2.3