mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-27 00:09:04 +00:00
* 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 made 2a3813c6
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 in 2a3813c6; the best comparison is:
git diff 2a3813c6^..
10 lines
209 B
C
10 lines
209 B
C
#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;
|
|
}
|