Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion host/test/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@ describe("execve", () => {
argv: ["exec-caller"],
timeout: 15_000,
execPrograms,
useDefaultRootfs: false,
});

// exec-child exits with 42
expect(result.exitCode).toBe(42);

// exec-child prints its argv
expect(result.stdout).toContain("argc=3");
expect(result.stdout).toContain("argv[0]=exec-child");
expect(result.stdout).toContain("argv[0]=/opt/kandelo/bin/exec-child");
expect(result.stdout).toContain("argv[1]=hello");
expect(result.stdout).toContain("argv[2]=world");
expect(result.stdout).toContain(
"program_invocation_name=/opt/kandelo/bin/exec-child",
);
expect(result.stdout).toContain("program_invocation_short_name=exec-child");

// exec-child prints env vars passed by exec-caller
expect(result.stdout).toContain("FOO=bar");
Expand All @@ -45,6 +50,7 @@ describe("execve", () => {
argv: ["fork-exec"],
timeout: 15_000,
execPrograms,
useDefaultRootfs: false,
});

// Parent exits 0
Expand Down
2 changes: 2 additions & 0 deletions libc/musl-overlay/src/env/__libc_start_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int __init_tp(void *);

void __init_libc(char **envp, char *pn)
{
size_t i;
__environ = envp;

/* On Wasm, there is no auxv, TLS, or secure-execution mode.
Expand All @@ -46,6 +47,7 @@ void __init_libc(char **envp, char *pn)

if (!pn) pn = "";
__progname = __progname_full = pn;
for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;

/* Initialize the thread pointer for the main thread.
* Set __wasm_thread_pointer to point at __wasm_tp_storage,
Expand Down
2 changes: 1 addition & 1 deletion programs/exec-caller.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern char **environ;

int main(void) {
char *argv[] = {"exec-child", "hello", "world", NULL};
char *argv[] = {"/opt/kandelo/bin/exec-child", "hello", "world", NULL};
char *envp[] = {"FOO=bar", "TEST=exec", NULL};
execve("/bin/exec-child", argv, envp);
/* If we get here, exec failed */
Expand Down
4 changes: 4 additions & 0 deletions programs/exec-child.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
* exec-child.c — Target program for exec tests.
* Prints its argv and selected env vars to verify exec passed them correctly.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[]) {
printf("argc=%d\n", argc);
for (int i = 0; i < argc; i++)
printf("argv[%d]=%s\n", i, argv[i]);
printf("program_invocation_name=%s\n", program_invocation_name);
printf("program_invocation_short_name=%s\n", program_invocation_short_name);

const char *foo = getenv("FOO");
if (foo) printf("FOO=%s\n", foo);
Expand Down
Loading