Open nazar-pc opened 7 years ago
The complication here is that putenv needs some level of fakery in HHVM - it can't directly back on to the libc call because HHVM is multithreaded.
A possible solution would be to warp certain libc calls (e.g. shell_exec() and mktime()) and propagate the environment before calling the actual libc function().
This could be realised by ld(2)'s --wrap
option [1]:
--wrap=symbol Use a wrapper function for symbol. Any undefined reference to symbol will be resolved to "wrap_ symbol ". Any undefined reference to "_real symbol " will be resolved to symbol. This can be used to provide a wrapper for a system function. The wrapper function should be called "wrap_ symbol ". If it wishes to call the system function, it should call "_real symbol ".
Here is a trivial example:
void * __wrap_malloc (size_t c) { printf ("malloc called with %zu\n", c); return __real_malloc (c); }
If you link other code with this file using --wrap malloc, then all calls to "malloc" will call the function "wrap_malloc" instead. The call to "__real_malloc" in "wrap_malloc" will call the real "malloc" function. You may wish to provide a "real_malloc" function as well, so that links without the --wrap option will succeed. If you do this, you should not put the definition of "__real_malloc" in the same file as "wrap_malloc"; if you do, the assembler may resolve the call before the linker has a chance to wrap it to "malloc".
That approach would be good enough for #7378 (this) and #7533.
Is this also the cause of PHP's putenv() not affecting the following passthru()? That's what's biting me. Environment variables are a commonly used method of passing values through to another command without having the bother of escaping them to become command-line arguments.
$ env -i FOO=foo PHP_BAR=bar php -r 'putenv("XYZZY=xyzzy"); passthru("env | sort");'
FOO=foo
GLIBCPP_FORCE_NEW=1
GLIBCXX_FORCE_NEW=1
PHP_BAR=bar
PWD=/home/ralph
UNW_RBP_ALWAYS_VALID=1
$
HHVM Version
PHP Version
Standalone code, or other way to reproduce the problem
Expected result
Actual result