sched/posix_spawn: Don't insert name at the begin of argv
since the standard require the caller pass the name explicitly https://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html: The argument argv is an array of character pointers to null-terminated strings. The last member of this array shall be a null pointer and is not counted in argc. These strings constitute the argument list available to the new process image. The value in argv[0] should point to a filename that is associated with the process image being started by the posix_spawn() or posix_spawnp() function. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
90f71bd017
commit
bec68ad8ea
|
@ -168,8 +168,8 @@ int exec_module(FAR const struct binary_s *binp,
|
|||
|
||||
/* Initialize the task */
|
||||
|
||||
ret = nxtask_init(tcb, filename, binp->priority,
|
||||
NULL, binp->stacksize, binp->entrypt, argv);
|
||||
ret = nxtask_init(tcb, argv[0], binp->priority, NULL,
|
||||
binp->stacksize, binp->entrypt, &argv[1]);
|
||||
binfmt_freeargv(argv);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
|
|
@ -44,8 +44,8 @@ struct tcb_s; /* Forward reference */
|
|||
void nxtask_start(void);
|
||||
int nxtask_setup_scheduler(FAR struct task_tcb_s *tcb, int priority,
|
||||
start_t start, main_t main, uint8_t ttype);
|
||||
int nxtask_setup_arguments(FAR struct task_tcb_s *tcb, FAR const char *name,
|
||||
FAR char * const argv[]);
|
||||
int nxtask_setup_arguments(FAR struct task_tcb_s *tcb,
|
||||
FAR const char *name, FAR char * const argv[]);
|
||||
|
||||
/* Task exit */
|
||||
|
||||
|
|
|
@ -452,13 +452,6 @@ static int nxthread_setup_scheduler(FAR struct tcb_s *tcb, int priority,
|
|||
static void nxtask_setup_name(FAR struct task_tcb_s *tcb,
|
||||
FAR const char *name)
|
||||
{
|
||||
/* Give a name to the unnamed tasks */
|
||||
|
||||
if (!name)
|
||||
{
|
||||
name = (FAR char *)g_noname;
|
||||
}
|
||||
|
||||
/* Copy the name into the TCB */
|
||||
|
||||
strncpy(tcb->cmn.name, name, CONFIG_TASK_NAME_SIZE);
|
||||
|
@ -489,11 +482,11 @@ static void nxtask_setup_name(FAR struct task_tcb_s *tcb,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
|
||||
FAR char * const argv[])
|
||||
static int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
|
||||
FAR const char *name,
|
||||
FAR char * const argv[])
|
||||
{
|
||||
FAR char **stackargv;
|
||||
FAR const char *name;
|
||||
FAR char *str;
|
||||
size_t strtablen;
|
||||
size_t argvlen;
|
||||
|
@ -501,14 +494,6 @@ static inline int nxtask_setup_stackargs(FAR struct task_tcb_s *tcb,
|
|||
int argc;
|
||||
int i;
|
||||
|
||||
/* Get the name string that we will use as the first argument */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
name = tcb->cmn.name;
|
||||
#else
|
||||
name = (FAR const char *)g_noname;
|
||||
#endif /* CONFIG_TASK_NAME_SIZE */
|
||||
|
||||
/* Get the size of the task name (including the NUL terminator) */
|
||||
|
||||
strtablen = (strlen(name) + 1);
|
||||
|
@ -707,9 +692,16 @@ int pthread_setup_scheduler(FAR struct pthread_tcb_s *tcb, int priority,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxtask_setup_arguments(FAR struct task_tcb_s *tcb, FAR const char *name,
|
||||
FAR char * const argv[])
|
||||
int nxtask_setup_arguments(FAR struct task_tcb_s *tcb,
|
||||
FAR const char *name, FAR char * const argv[])
|
||||
{
|
||||
/* Give a name to the unnamed tasks */
|
||||
|
||||
if (!name)
|
||||
{
|
||||
name = (FAR char *)g_noname;
|
||||
}
|
||||
|
||||
/* Setup the task name */
|
||||
|
||||
nxtask_setup_name(tcb, name);
|
||||
|
@ -719,5 +711,5 @@ int nxtask_setup_arguments(FAR struct task_tcb_s *tcb, FAR const char *name,
|
|||
* privilege mode the task runs in.
|
||||
*/
|
||||
|
||||
return nxtask_setup_stackargs(tcb, argv);
|
||||
return nxtask_setup_stackargs(tcb, name, argv);
|
||||
}
|
||||
|
|
|
@ -97,7 +97,6 @@ FAR struct task_tcb_s *nxtask_setup_vfork(start_t retaddr)
|
|||
FAR struct task_tcb_s *parent;
|
||||
FAR struct task_tcb_s *child;
|
||||
FAR struct task_info_s *info;
|
||||
FAR const char *name = NULL;
|
||||
size_t stack_size;
|
||||
uint8_t ttype;
|
||||
int priority;
|
||||
|
@ -204,11 +203,7 @@ FAR struct task_tcb_s *nxtask_setup_vfork(start_t retaddr)
|
|||
|
||||
/* Setup to pass parameters to the new task */
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
name = parent->cmn.name;
|
||||
#endif
|
||||
|
||||
nxtask_setup_arguments(child, name, parent->argv);
|
||||
nxtask_setup_arguments(child, parent->argv[0], &parent->argv[1]);
|
||||
|
||||
/* Now we have enough in place that we can join the group */
|
||||
|
||||
|
|
Loading…
Reference in New Issue