From 5ec8fc942792ce6470ff5b82aa8b334b0a2e6098 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 10 Dec 2019 10:05:51 -0600 Subject: [PATCH] apps/nshlib/nsh_fileapps.c: nsh_fileapp() should return 1 if the application task was spawned successfully but returned failure exit status. For example, nsh shouldn't output "/bin/ping: command not found": nsh> /bin/ping ERROR: Missing required argument ... nsh: /bin/ping: command not found --- nshlib/nsh_fileapps.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/nshlib/nsh_fileapps.c b/nshlib/nsh_fileapps.c index 1914a4ceb..ec8b796b8 100644 --- a/nshlib/nsh_fileapps.c +++ b/nshlib/nsh_fileapps.c @@ -85,6 +85,7 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, posix_spawn_file_actions_t file_actions; posix_spawnattr_t attr; pid_t pid; + int rc = 0; int ret; /* Initialize the attributes file actions structure */ @@ -160,7 +161,6 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, */ #ifdef CONFIG_SCHED_WAITPID - /* CONFIG_SCHED_WAITPID is selected, so we may run the command in * foreground unless we were specifically requested to run the command * in background (and running commands in background is enabled). @@ -170,8 +170,6 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, if (vtbl->np.np_bg == false) # endif /* CONFIG_NSH_DISABLEBG */ { - int rc = 0; - /* Setup up to receive SIGINT if control-C entered. The return * value is ignored because this console device may not support * SIGINT. @@ -220,17 +218,14 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, else { - /* We can't return the exact status (nsh has nowhere to put it) - * so just pass back zero/nonzero in a fashion that doesn't look - * like an error. + /* Ignore the returned child pid */ + + ret = OK; + + /* TODO: Set the environment variable '?' to a string corresponding + * to WEXITSTATUS(rc) so that $? will expand to the exit status of + * the most recently executed task. */ - - ret = (rc == 0) ? OK : 1; - - /* TODO: Set the environment variable '?' to a string corresponding - * to WEXITSTATUS(rc) so that $? will expand to the exit status of - * the most recently executed task. - */ } (void)ioctl(stdout->fs_fd, TIOCSCTTY, -1); @@ -298,6 +293,15 @@ errout: ret = ERROR; } + else if (rc != 0) + { + /* We can't return the exact status (nsh has nowhere to put it) + * so just pass back zero/nonzero in a fashion that doesn't look + * like an error. + */ + + ret = 1; + } return ret; }