sched: Pass idle thread environment variables to the child task through copy

because if we pass predefined environment variables table explicitly,
the environment variables created by the board code will be lost.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2022-10-24 20:12:34 +08:00
committed by Masayuki Ishikawa
parent 0bf7afad25
commit 677a907dc8
+40 -22
View File
@@ -43,8 +43,10 @@
#ifdef CONFIG_PAGING
# include "paging/paging.h"
#endif
# include "wqueue/wqueue.h"
# include "init/init.h"
#include "sched/sched.h"
#include "wqueue/wqueue.h"
#include "init/init.h"
/****************************************************************************
* Pre-processor Definitions
@@ -229,20 +231,6 @@ static inline void nx_start_application(void)
{
# ifdef CONFIG_INIT_ARGS
CONFIG_INIT_ARGS,
# endif
NULL,
};
FAR char * const envp[] =
{
# ifdef CONFIG_LIBC_HOMEDIR
"PWD=" CONFIG_LIBC_HOMEDIR,
# endif
# ifdef CONFIG_PATH_INITIAL
"PATH=" CONFIG_PATH_INITIAL,
# endif
# ifdef CONFIG_LDPATH_INITIAL
"LD_LIBRARY_PATH=" CONFIG_LDPATH_INITIAL,
# endif
NULL,
};
@@ -275,11 +263,11 @@ static inline void nx_start_application(void)
DEBUGASSERT(USERSPACE->us_entrypoint != NULL);
ret = nxtask_create(CONFIG_INIT_ENTRYNAME, CONFIG_INIT_PRIORITY,
CONFIG_INIT_STACKSIZE,
USERSPACE->us_entrypoint, argv, envp);
USERSPACE->us_entrypoint, argv, NULL);
# else
ret = nxtask_create(CONFIG_INIT_ENTRYNAME, CONFIG_INIT_PRIORITY,
CONFIG_INIT_STACKSIZE,
CONFIG_INIT_ENTRYPOINT, argv, envp);
CONFIG_INIT_ENTRYPOINT, argv, NULL);
# endif
DEBUGASSERT(ret > 0);
@@ -307,7 +295,7 @@ static inline void nx_start_application(void)
# ifndef CONFIG_BUILD_KERNEL
attr.stacksize = CONFIG_INIT_STACKSIZE;
# endif
ret = exec_spawn(CONFIG_INIT_FILEPATH, argv, envp,
ret = exec_spawn(CONFIG_INIT_FILEPATH, argv, NULL,
CONFIG_INIT_SYMTAB, CONFIG_INIT_NEXPORTS, &attr);
DEBUGASSERT(ret >= 0);
#endif
@@ -367,9 +355,10 @@ static inline void nx_create_initthread(void)
* execution.
*/
pid = kthread_create("AppBringUp", CONFIG_BOARD_INITTHREAD_PRIORITY,
CONFIG_BOARD_INITTHREAD_STACKSIZE,
nx_start_task, NULL);
pid = nxthread_create("AppBringUp", TCB_FLAG_TTYPE_KERNEL,
CONFIG_BOARD_INITTHREAD_PRIORITY,
NULL, CONFIG_BOARD_INITTHREAD_STACKSIZE,
nx_start_task, NULL, environ);
DEBUGASSERT(pid > 0);
UNUSED(pid);
#else
@@ -419,6 +408,27 @@ static inline void nx_create_initthread(void)
int nx_bringup(void)
{
#ifndef CONFIG_DISABLE_ENVIRON
/* Setup up the initial environment for the idle task. At present, this
* may consist of only the initial PATH variable and/or and init library
* path variable. These path variables are not used by the IDLE task.
* However, the environment containing the PATH variable will be inherited
* by all of the threads created by the IDLE task.
*/
#ifdef CONFIG_LIBC_HOMEDIR
setenv("PWD", CONFIG_LIBC_HOMEDIR, 1);
#endif
#ifdef CONFIG_PATH_INITIAL
setenv("PATH", CONFIG_PATH_INITIAL, 1);
#endif
#ifdef CONFIG_LDPATH_INITIAL
setenv("LD_LIBRARY_PATH", CONFIG_LDPATH_INITIAL, 1);
#endif
#endif
/* Start the page fill worker kernel thread that will resolve page faults.
* This should always be the first thread started because it may have to
* resolve page faults in other threads
@@ -438,5 +448,13 @@ int nx_bringup(void)
*/
nx_create_initthread();
#if !defined(CONFIG_DISABLE_ENVIRON) && (defined(CONFIG_PATH_INITIAL) || \
defined(CONFIG_LDPATH_INITIAL))
/* We an save a few bytes by discarding the IDLE thread's environment. */
clearenv();
#endif
return OK;
}