libc: initialize the environ pointer before Libc::construct

Setting the global environ pointer to NULL prevents getenv surprises
when using libc without the POSIX wrapper.

Fix #2312
This commit is contained in:
Emery Hemingway 2017-03-09 15:22:55 -06:00 committed by Christian Helmuth
parent ec007c0f27
commit 10ed7b38d4

View File

@ -37,6 +37,7 @@
#include "libc_init.h"
#include "task.h"
extern char **environ;
namespace Libc {
class Env_implementation;
@ -844,6 +845,10 @@ Genode::size_t Component::stack_size() { return Libc::Component::stack_size(); }
void Component::construct(Genode::Env &env)
{
/* initialize the global pointer to environment variables */
static char *null_env = nullptr;
if (!environ) environ = &null_env;
/* pass Genode::Env to libc subsystems that depend on it */
Libc::init_mem_alloc(env);
Libc::init_dl(env);