Prepend getcwd to exename early in init (#1048)

This commit is contained in:
Jōshin 2024-01-01 10:23:23 -05:00 committed by GitHub
parent 2f89c2482a
commit 68dbe5312f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 22 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/metalfile.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/limits.h"
#include "libc/runtime/runtime.h"
@ -57,6 +58,9 @@ void SetUpOnce(void) {
__attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
if (argc >= 2 && !strcmp(argv[1], "Child")) {
if (sys_chdir("/")) {
exit(122);
}
if (strcmp(argv[2], GetProgramExecutableName())) {
exit(123);
}
@ -138,4 +142,9 @@ TEST(GetProgramExecutableName, movedSelf) {
execve(buf, (char *[]){"hello", "Child", buf, "hello", 0}, (char *[]){0});
abort();
EXITS(0);
SPAWN(fork);
execve("./test", (char *[]){"hello", "Child", buf, "hello", 0},
(char *[]){0});
abort();
EXITS(0);
}