mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 16:22:29 +00:00
Keep argv[0], add COSMOPOLITAN_PROGRAM_EXECUTABLE (#980)
* Introduce env.com Handy tool for debugging environment issues. * Inject path as COSMOPOLITAN_PROGRAM_EXECUTABLE `argv[0]` was previously being used as a communication channel between the loader and the binary, giving the binary its full path for use e.g. in `GetProgramExecutableName`. But `argv[0]` is not a good channel for this; much of what made2a3813c6
so gross is due to that. This change fixes the issue by preserving `argv[0]` and establishing a new communication channel: `COSMOPOLITAN_PROGRAM_EXECUTABLE`. The M1 loader will always set this as the first variable. Linux should soon follow. On the other side, `GetProgramExecutableName` checks that variable first. If it sees it, it trusts it as-is. A lot of the churn in `ape/ape-m1.c` in this change is actually backing out hacks introduced in2a3813c6
; the best comparison is: git diff 2a3813c6^..
This commit is contained in:
parent
2a3813c6cf
commit
ed8fadea37
4 changed files with 168 additions and 38 deletions
10
examples/env.c
Normal file
10
examples/env.c
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
printf("%s\n", argv[0]);
|
||||
for (char **p = environ; *p; ++p) {
|
||||
printf(" %s\n", *p);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue