From d36e1c87fe458a9b6ebb3c5897ef9de57c855394 Mon Sep 17 00:00:00 2001 From: ligd Date: Sun, 26 Aug 2018 07:48:38 -0600 Subject: [PATCH] apps/nshlib: Add control-C support for terminating built-in and exec'ed file tasks. --- nshlib/nsh_builtin.c | 10 ++++++++++ nshlib/nsh_fileapps.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/nshlib/nsh_builtin.c b/nshlib/nsh_builtin.c index 128757b2e..4d8736644 100644 --- a/nshlib/nsh_builtin.c +++ b/nshlib/nsh_builtin.c @@ -47,6 +47,7 @@ #include #ifdef CONFIG_SCHED_WAITPID +# include # include #endif @@ -134,6 +135,13 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, { int rc = 0; + /* Setup up to receive SIGKILL if control-C entered. The return + * value is ignored because this console device may not support + * SIGKILL. + */ + + (void)ioctl(stdout->fs_fd, TIOCSCTTY, ret); + /* Wait for the application to exit. We did lock the scheduler * above, but that does not guarantee that the application did not * already run to completion in the case where I/O was redirected. @@ -187,6 +195,8 @@ int nsh_builtin(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, * the most recently executed task. */ } + + (void)ioctl(stdout->fs_fd, TIOCSCTTY, -1); } # ifndef CONFIG_NSH_DISABLEBG else diff --git a/nshlib/nsh_fileapps.c b/nshlib/nsh_fileapps.c index ca6cccbc8..868a26df2 100644 --- a/nshlib/nsh_fileapps.c +++ b/nshlib/nsh_fileapps.c @@ -40,6 +40,7 @@ #include #ifdef CONFIG_SCHED_WAITPID +# include # include #endif @@ -171,6 +172,13 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, { int rc = 0; + /* Setup up to receive SIGKILL if control-C entered. The return + * value is ignored because this console device may not support + * SIGKILL. + */ + + (void)ioctl(stdout->fs_fd, TIOCSCTTY, pid); + /* Wait for the application to exit. We did lock the scheduler * above, but that does not guarantee that the application did not * already run to completion in the case where I/O was redirected. @@ -219,6 +227,8 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, * the most recently executed task. */ } + + (void)ioctl(stdout->fs_fd, TIOCSCTTY, -1); } # ifndef CONFIG_NSH_DISABLEBG else