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 <ip-address> argument
...
nsh: /bin/ping: command not found
This commit is contained in:
Xiang Xiao 2019-12-10 10:05:51 -06:00 committed by Gregory Nutt
parent 77a3b08302
commit 5ec8fc9427

View File

@ -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_spawn_file_actions_t file_actions;
posix_spawnattr_t attr; posix_spawnattr_t attr;
pid_t pid; pid_t pid;
int rc = 0;
int ret; int ret;
/* Initialize the attributes file actions structure */ /* 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 #ifdef CONFIG_SCHED_WAITPID
/* CONFIG_SCHED_WAITPID is selected, so we may run the command in /* CONFIG_SCHED_WAITPID is selected, so we may run the command in
* foreground unless we were specifically requested to run the command * foreground unless we were specifically requested to run the command
* in background (and running commands in background is enabled). * 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) if (vtbl->np.np_bg == false)
# endif /* CONFIG_NSH_DISABLEBG */ # endif /* CONFIG_NSH_DISABLEBG */
{ {
int rc = 0;
/* Setup up to receive SIGINT if control-C entered. The return /* Setup up to receive SIGINT if control-C entered. The return
* value is ignored because this console device may not support * value is ignored because this console device may not support
* SIGINT. * SIGINT.
@ -220,17 +218,14 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
else else
{ {
/* We can't return the exact status (nsh has nowhere to put it) /* Ignore the returned child pid */
* so just pass back zero/nonzero in a fashion that doesn't look
* like an error. 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); (void)ioctl(stdout->fs_fd, TIOCSCTTY, -1);
@ -298,6 +293,15 @@ errout:
ret = ERROR; 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; return ret;
} }