This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new d91ef511e nshlib: fix NSH_BUILTIN_AS_COMMAND compatibility issues.
d91ef511e is described below
commit d91ef511ed27a945d135bc664c0e3dca71e3748c
Author: yukangzhi <[email protected]>
AuthorDate: Mon Apr 20 15:39:43 2026 +0800
nshlib: fix NSH_BUILTIN_AS_COMMAND compatibility issues.
1. Hide NSH_DISABLEBG when NSH_BUILTIN_AS_COMMAND is enabled.
NSH_BUILTIN_AS_COMMAND runs builtin commands directly in the NSH
thread, bypassing nsh_fileapp()/task_spawn(). Background execution
is inherently unsupported in this mode, so NSH_DISABLEBG has no
meaning there; hide it with "depends on !NSH_BUILTIN_AS_COMMAND".
Also make NSH_PIPELINE depend on !NSH_DISABLEBG, since the pipeline
code uses np_bg to run the left-side command asynchronously and
np_bg does not exist when NSH_DISABLEBG is set.
2. Set the controlling terminal around the builtin->main() call.
When NSH_BUILTIN_AS_COMMAND is enabled, builtin commands run
directly in the NSH thread via builtin->main() without going
through nsh_builtin.c, so TIOCSCTTY is never issued. The serial
driver's dev->pid then stays INVALID_PROCESS_ID and Ctrl+C never
delivers SIGINT to the foreground application.
Fix by issuing TIOCSCTTY/TIOCNOTTY around the builtin->main() call
in nsh_command(), matching the pattern used in nsh_builtin.c.
Assisted-by: Kiro
Signed-off-by: yukangzhi <[email protected]>
---
nshlib/Kconfig | 6 +++++-
nshlib/nsh_command.c | 18 +++++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/nshlib/Kconfig b/nshlib/Kconfig
index a66379e4a..dba880a10 100644
--- a/nshlib/Kconfig
+++ b/nshlib/Kconfig
@@ -218,6 +218,7 @@ config NSH_NESTDEPTH
config NSH_DISABLEBG
bool "Disable background commands"
default DEFAULT_SMALL
+ depends on !NSH_BUILTIN_AS_COMMAND
---help---
This can be set to 'y' to suppress support for background
commands. This setting disables the 'nice' command prefix and
@@ -247,6 +248,7 @@ config NSH_PIPELINE
bool "Enable pipeline support"
default !DEFAULT_SMALL
depends on PIPES
+ depends on !NSH_DISABLEBG
---help---
Enable pipeline support for nsh.
@@ -268,7 +270,9 @@ config NSH_BUILTIN_AS_COMMAND
depends on BUILTIN
---help---
Enable to run builtin application directly without creating
- a separate thread.
+ a separate thread. This is incompatible with background
+ command execution (&) because builtin apps bypass the
+ nsh_fileapp/task_spawn path required for background jobs.
config NSH_FILE_APPS
bool "Enable execution of program files"
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index 22609c0cf..ef3c0abaa 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
+#include <termios.h>
#ifdef CONFIG_NSH_BUILTIN_APPS
# include <nuttx/lib/builtin.h>
@@ -1314,7 +1315,22 @@ int nsh_command(FAR struct nsh_vtbl_s *vtbl, int argc,
FAR char *argv[])
builtin = builtin_for_index(index);
if (builtin != NULL)
{
- return (builtin->main)(argc, (FAR char **)argv);
+ int tc = 0;
+ int ret;
+
+ if (vtbl->isctty)
+ {
+ tc = nsh_ioctl(vtbl, TIOCSCTTY, getpid());
+ }
+
+ ret = (builtin->main)(argc, (FAR char **)argv);
+
+ if (vtbl->isctty && tc == 0)
+ {
+ nsh_ioctl(vtbl, TIOCNOTTY, 0);
+ }
+
+ return ret;
}
}
#endif