diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-28 15:18:26 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-07-28 15:18:26 +0000 |
commit | 51f1a88cb89e90f522a94c1dfe5ae16f17465121 (patch) | |
tree | 52871679f64d7f67529f037fadfeb242b5f2f1ad /apps/nshlib/nsh_parse.c | |
parent | e6785c7ef7a6d7eee0c8b6c2d8bd27e47d9b0d6a (diff) | |
download | nuttx-51f1a88cb89e90f522a94c1dfe5ae16f17465121.tar.gz nuttx-51f1a88cb89e90f522a94c1dfe5ae16f17465121.tar.bz2 nuttx-51f1a88cb89e90f522a94c1dfe5ae16f17465121.zip |
PM update; NSH extension to catch return values
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4987 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/nshlib/nsh_parse.c')
-rw-r--r-- | apps/nshlib/nsh_parse.c | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c index 76cd4664e..64850eb62 100644 --- a/apps/nshlib/nsh_parse.c +++ b/apps/nshlib/nsh_parse.c @@ -67,7 +67,7 @@ #include "nsh_console.h" /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /* Argument list size @@ -487,6 +487,16 @@ static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) /**************************************************************************** * Name: nsh_execute + * + * Description: + * Exectue the command in argv[0] + * + * Returned Value: + * -1 (ERRROR) if the command was unsuccessful + * 0 (OK) if the command was successful + * 1 if an application task was spawned successfully, but + * returned failure exit status. + * ****************************************************************************/ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) @@ -506,18 +516,20 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) cmd = argv[0]; - /* Try to find a command in the application library. - */ + /* Try to find a command in the application library. */ #ifdef CONFIG_NSH_BUILTIN_APPS - if (nsh_execapp(vtbl, cmd, argv) == OK) - { - /* The pre-built application was successfully started -- return OK. */ + ret = nsh_execapp(vtbl, cmd, argv); - return OK; - } -#endif + /* The pre-built application was successfully started -- return OK + * or 1 if it returned a non-zero exit status. + */ + if (ret >= 0) + { + return ret; + } +#endif /* See if the command is one that we understand */ @@ -1123,6 +1135,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) break; } } + argv[argc] = NULL; /* Check if the command should run in background */ @@ -1136,7 +1149,6 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) } #endif - /* Check if the output was re-directed using > or >> */ if (argc > 2) @@ -1285,6 +1297,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) nsh_release(bkgvtbl); goto errout; } + nsh_output(vtbl, "%s [%d:%d]\n", cmd, thread, param.sched_priority); } else @@ -1300,7 +1313,12 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) } /* Then execute the command in "foreground" -- i.e., while the user waits - * for the next prompt. + * for the next prompt. nsh_execute will return: + * + * -1 (ERRROR) if the command was unsuccessful + * 0 (OK) if the command was successful + * 1 if an application task was spawned successfully, but + * returned failure exit status. */ ret = nsh_execute(vtbl, argc, argv); @@ -1314,7 +1332,11 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) nsh_undirect(vtbl, save); } - if (ret < 0) + /* Treat both errors and non-zero return codes as "errors" so that + * it is possible to test for non-zero returns in nsh scripts. + */ + + if (ret != OK) { goto errout; } |