You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2021/06/16 18:07:37 UTC
[incubator-nuttx-apps] branch master updated: example/posix_spawn:
Ensure argv has filename and NULL terminator
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 7847c1f example/posix_spawn: Ensure argv has filename and NULL terminator
7847c1f is described below
commit 7847c1f974f1098cfd4feaa200b72f139ddd66a1
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Wed Jun 16 02:55:57 2021 +0800
example/posix_spawn: Ensure argv has filename and NULL terminator
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
examples/elf/elf_main.c | 5 +++--
examples/nxflat/nxflat_main.c | 5 +++--
examples/posix_spawn/spawn_main.c | 27 ++++++++++++++++-----------
3 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/examples/elf/elf_main.c b/examples/elf/elf_main.c
index 94e3454..aa10e01 100644
--- a/examples/elf/elf_main.c
+++ b/examples/elf/elf_main.c
@@ -206,7 +206,7 @@ int main(int argc, FAR char *argv[])
#ifdef CONFIG_EXAMPLES_ELF_ROMFS
struct boardioc_romdisk_s desc;
#endif
- FAR char *args[1];
+ FAR char *args[2];
int ret;
int i;
@@ -357,7 +357,8 @@ int main(int argc, FAR char *argv[])
* table information is available within the OS.
*/
- args[0] = NULL;
+ args[0] = (FAR char *)dirlist[i];
+ args[1] = NULL;
ret = exec(filename, args, g_elf_exports, g_elf_nexports);
mm_update(&g_mmstep, "after exec");
diff --git a/examples/nxflat/nxflat_main.c b/examples/nxflat/nxflat_main.c
index 568aa32..e951ca0 100644
--- a/examples/nxflat/nxflat_main.c
+++ b/examples/nxflat/nxflat_main.c
@@ -135,7 +135,7 @@ static inline void testheader(FAR const char *progname)
int main(int argc, FAR char *argv[])
{
- FAR char *args[1];
+ FAR char *args[2];
int ret;
int i;
struct boardioc_romdisk_s desc;
@@ -211,7 +211,8 @@ int main(int argc, FAR char *argv[])
* table information is available within the OS.
*/
- args[0] = NULL;
+ args[0] = (FAR char *)dirlist[i];
+ args[1] = NULL;
ret = exec(filename, args, g_nxflat_exports, g_nxflat_nexports);
if (ret < 0)
{
diff --git a/examples/posix_spawn/spawn_main.c b/examples/posix_spawn/spawn_main.c
index 4d5e88c..0ef77ed 100644
--- a/examples/posix_spawn/spawn_main.c
+++ b/examples/posix_spawn/spawn_main.c
@@ -117,16 +117,20 @@ static unsigned int g_mmstep; /* Memory Usage at beginning of test step */
static const char delimiter[] =
"**************************************"
"**************************************";
-static const char g_redirect[] = "redirect";
static const char g_data[] = "testdata.txt";
static char fullpath[128];
-static char * const g_argv[5] =
+static char * const g_hello_argv[5] =
{
"hello", "Argument 1", "Argument 2", "Argument 3", NULL
};
+static char * const g_redirect_argv[2] =
+{
+ "redirect", NULL
+};
+
/****************************************************************************
* Symbols from Auto-Generated Code
****************************************************************************/
@@ -270,7 +274,7 @@ int main(int argc, FAR char *argv[])
* this program from the others.
*/
- testheader(g_argv[0]);
+ testheader(g_hello_argv[0]);
/* Initialize the attributes file actions structure */
@@ -299,9 +303,9 @@ int main(int argc, FAR char *argv[])
*/
#ifdef CONFIG_LIB_ENVPATH
- filepath = g_argv[0];
+ filepath = g_hello_argv[0];
#else
- snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_argv[0]);
+ snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello_argv[0]);
filepath = fullpath;
#endif
@@ -309,8 +313,8 @@ int main(int argc, FAR char *argv[])
mm_update(&g_mmstep, "before posix_spawn");
- ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL,
- (FAR char * const *)&g_argv);
+ ret = posix_spawn(&pid, filepath, &file_actions,
+ &attr, g_hello_argv, NULL);
if (ret != 0)
{
errmsg("ERROR: posix_spawn failed: %d\n", ret);
@@ -347,7 +351,7 @@ int main(int argc, FAR char *argv[])
* this program from the others.
*/
- testheader(g_redirect);
+ testheader(g_redirect_argv[0]);
/* Initialize the attributes file actions structure */
@@ -398,9 +402,9 @@ int main(int argc, FAR char *argv[])
*/
#ifdef CONFIG_LIB_ENVPATH
- filepath = g_redirect;
+ filepath = g_redirect_argv[0];
#else
- snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect);
+ snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_redirect_argv[0]);
filepath = fullpath;
#endif
@@ -408,7 +412,8 @@ int main(int argc, FAR char *argv[])
mm_update(&g_mmstep, "before posix_spawn");
- ret = posix_spawn(&pid, filepath, &file_actions, &attr, NULL, NULL);
+ ret = posix_spawn(&pid, filepath, &file_actions,
+ &attr, g_redirect_argv, NULL);
if (ret != 0)
{
errmsg("ERROR: posix_spawn failed: %d\n", ret);