From e222dcd354475e41eb93e4d976db821821c8aa5f Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 17 Jan 2013 20:25:32 +0000 Subject: [PATCH] Misc bug fixes related to NSH file execution git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5530 42af7a65-404d-4744-a932-0658087f49c3 --- configs/sim/README.txt | 31 ++++++++++++++++++++++++------- libc/spawn/lib_ps.c | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/configs/sim/README.txt b/configs/sim/README.txt index 67ff730197..963a46e083 100644 --- a/configs/sim/README.txt +++ b/configs/sim/README.txt @@ -291,14 +291,31 @@ nsh apps/examples/hello. 3. This configuration has BINFS enabled so that the builtin applications - can be made visible in the file system. For example: + can be made visible in the file system. Because of that, the + build in applications do not work as other examples. - NuttShell (NSH) NuttX-6.24 - nsh> mount -t binfs /bin - nsh> ls /bin - /bin: - hello - nsh> + For example trying to execute the hello builtin application will + fail: + + nsh> hello + nsh: hello: command not found + nsh> + + Unless you first mount the BINFS file system: + + nsh> mount -t binfs /bin + nsh> ls /bin + /bin: + hello + nsh> echo $PATH + /bin + nsh> hello + Hello, World!! + nsh> + + Notice that the executable 'hello' is found using the value in the PATH + variable (which was preset to "/bin"). If the PATH variable were not set + then you would have to use /bin/hello on the command line. nsh2 diff --git a/libc/spawn/lib_ps.c b/libc/spawn/lib_ps.c index 000f711a3f..1bf7c21133 100644 --- a/libc/spawn/lib_ps.c +++ b/libc/spawn/lib_ps.c @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -75,7 +76,9 @@ struct spawn_parms_s ****************************************************************************/ static sem_t g_ps_parmsem = SEM_INITIALIZER(1); +#ifndef CONFIG_SCHED_WAITPID static sem_t g_ps_execsem = SEM_INITIALIZER(0); +#endif static struct spawn_parms_s g_ps_parms; /**************************************************************************** @@ -425,7 +428,9 @@ static int spawn_proxy(int argc, char *argv[]) */ g_ps_parms.result = ret; +#ifndef CONFIG_SCHED_WAITPID ps_semgive(&g_ps_execsem); +#endif return 0; } @@ -540,6 +545,9 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, { struct sched_param param; pid_t proxy; +#ifdef CONFIG_SCHED_WAITPID + int status; +#endif int ret; DEBUGASSERT(path); @@ -613,7 +621,15 @@ int posix_spawn(FAR pid_t *pid, FAR const char *path, /* Wait for the proxy to complete its job */ +#ifdef CONFIG_SCHED_WAITPID + ret = waitpid(proxy, &status, 0); + if (ret < 0) + { + sdbg("ERROR: waitpid() failed: %d\n", errno); + } +#else ps_semtake(&g_ps_execsem); +#endif /* Get the result and relinquish our access to the parameter structure */