Call posix_spawn with filename as the first argv entry
pair with the kernel side change to follow the standard defintion: https://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
21562e8960
commit
99e1674912
@ -162,9 +162,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
|
||||
#ifdef CONFIG_LIBC_EXECFUNCS
|
||||
/* Load and execute the application. */
|
||||
|
||||
ret = posix_spawn(&pid, builtin->name, &file_actions, &attr,
|
||||
(argv) ? &argv[1] : (FAR char * const *)NULL, NULL);
|
||||
|
||||
ret = posix_spawn(&pid, builtin->name, &file_actions, &attr, argv, NULL);
|
||||
if (ret != 0 && builtin->main != NULL)
|
||||
#endif
|
||||
{
|
||||
|
@ -118,14 +118,13 @@ static const char delimiter[] =
|
||||
"**************************************"
|
||||
"**************************************";
|
||||
static const char g_redirect[] = "redirect";
|
||||
static const char g_hello[] = "hello";
|
||||
static const char g_data[] = "testdata.txt";
|
||||
|
||||
static char fullpath[128];
|
||||
|
||||
static char * const g_argv[4] =
|
||||
static char * const g_argv[5] =
|
||||
{
|
||||
"Argument 1", "Argument 2", "Argument 3", NULL
|
||||
"hello", "Argument 1", "Argument 2", "Argument 3", NULL
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -271,7 +270,7 @@ int main(int argc, FAR char *argv[])
|
||||
* this program from the others.
|
||||
*/
|
||||
|
||||
testheader(g_hello);
|
||||
testheader(g_argv[0]);
|
||||
|
||||
/* Initialize the attributes file actions structure */
|
||||
|
||||
@ -300,9 +299,9 @@ int main(int argc, FAR char *argv[])
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_LIB_ENVPATH
|
||||
filepath = g_hello;
|
||||
filepath = g_argv[0];
|
||||
#else
|
||||
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_hello);
|
||||
snprintf(fullpath, 128, "%s/%s", MOUNTPT, g_argv[0]);
|
||||
filepath = fullpath;
|
||||
#endif
|
||||
|
||||
|
@ -126,7 +126,7 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
* failure.
|
||||
*/
|
||||
|
||||
ret = posix_spawnp(&pid, cmd, &file_actions, &attr, &argv[1], NULL);
|
||||
ret = posix_spawnp(&pid, cmd, &file_actions, &attr, argv, NULL);
|
||||
if (ret == OK)
|
||||
{
|
||||
/* The application was successfully started with pre-emption disabled.
|
||||
|
@ -113,7 +113,7 @@ FILE *popen(FAR const char *command, FAR const char *mode)
|
||||
struct sched_param param;
|
||||
posix_spawnattr_t attr;
|
||||
posix_spawn_file_actions_t file_actions;
|
||||
FAR char *argv[3];
|
||||
FAR char *argv[4];
|
||||
int fd[2];
|
||||
int oldfd;
|
||||
int newfd;
|
||||
@ -244,17 +244,17 @@ FILE *popen(FAR const char *command, FAR const char *mode)
|
||||
* appropriately.
|
||||
*/
|
||||
|
||||
argv[0] = "-c";
|
||||
argv[1] = (FAR char *)command;
|
||||
argv[2] = NULL;
|
||||
argv[1] = "-c";
|
||||
argv[2] = (FAR char *)command;
|
||||
argv[3] = NULL;
|
||||
|
||||
#ifdef CONFIG_SYSTEM_POPEN_SHPATH
|
||||
errcode = posix_spawn(&container->shell, CONFIG_SYSTEM_POPEN_SHPATH,
|
||||
&file_actions, &attr, argv,
|
||||
(FAR char * const *)NULL);
|
||||
argv[0] = CONFIG_SYSTEM_POPEN_SHPATH;
|
||||
errcode = posix_spawn(&container->shell, argv[0], &file_actions,
|
||||
&attr, argv, (FAR char * const *)NULL);
|
||||
#else
|
||||
container->shell = task_spawn("popen", nsh_system, &file_actions,
|
||||
&attr, argv, (FAR char * const *)NULL);
|
||||
&attr, argv + 1, (FAR char * const *)NULL);
|
||||
if (container->shell < 0)
|
||||
{
|
||||
errcode = -container->shell;
|
||||
|
@ -60,7 +60,7 @@
|
||||
|
||||
int system(FAR const char *cmd)
|
||||
{
|
||||
FAR char *argv[3];
|
||||
FAR char *argv[4];
|
||||
struct sched_param param;
|
||||
posix_spawnattr_t attr;
|
||||
pid_t pid;
|
||||
@ -128,16 +128,17 @@ int system(FAR const char *cmd)
|
||||
|
||||
/* Spawn nsh_system() which will execute the command under the shell. */
|
||||
|
||||
argv[0] = "-c";
|
||||
argv[1] = (FAR char *)cmd;
|
||||
argv[2] = NULL;
|
||||
argv[1] = "-c";
|
||||
argv[2] = (FAR char *)cmd;
|
||||
argv[3] = NULL;
|
||||
|
||||
#ifdef CONFIG_SYSTEM_SYSTEM_SHPATH
|
||||
errcode = posix_spawn(&pid, CONFIG_SYSTEM_SYSTEM_SHPATH, NULL, &attr,
|
||||
argv[0] = CONFIG_SYSTEM_SYSTEM_SHPATH;
|
||||
errcode = posix_spawn(&pid, argv[0], NULL, &attr,
|
||||
argv, (FAR char * const *)NULL);
|
||||
#else
|
||||
pid = task_spawn("system", nsh_system, NULL, &attr,
|
||||
argv, (FAR char * const *)NULL);
|
||||
argv + 1, (FAR char * const *)NULL);
|
||||
if (pid < 0)
|
||||
{
|
||||
errcode = -pid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user