Introduce posix_spawn_file_actions_addchdir_np()

This commit is contained in:
Justine Tunney 2023-10-11 20:26:28 -07:00
parent f92ad74e6b
commit 3a1f887928
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
25 changed files with 446 additions and 748 deletions

View file

@ -127,6 +127,12 @@ void *Enclave(void *arg) {
return 0; // exit
}
TEST(pledge, tester) {
SPAWN(fork);
ASSERT_EQ(0, pledge("stdio rpath wpath cpath proc exec", NULL));
EXITS(0);
}
TEST(pledge, withThreadMemory) {
if (IsOpenbsd()) return; // openbsd doesn't allow it, wisely
pthread_t worker;

View file

@ -53,6 +53,7 @@
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
#include "libc/x/x.h"
#include "third_party/nsync/mu.h"
const char kTinyLinuxExit[128] = {
@ -161,6 +162,29 @@ TEST(posix_spawn, pipe) {
ASSERT_EQ(0, posix_spawn_file_actions_destroy(&fa));
}
TEST(posix_spawn, chdir) {
int ws, pid, p[2];
char buf[16] = {0};
char *args[] = {"cocmd.com", "-c", "cat hello.txt", 0};
char *envs[] = {0};
posix_spawn_file_actions_t fa;
testlib_extract("/zip/cocmd.com", "cocmd.com", 0755);
ASSERT_SYS(0, 0, mkdir("subdir", 0777));
ASSERT_SYS(0, 0, xbarf("subdir/hello.txt", "hello\n", -1));
ASSERT_SYS(0, 0, pipe2(p, O_CLOEXEC));
ASSERT_EQ(0, posix_spawn_file_actions_init(&fa));
ASSERT_EQ(0, posix_spawn_file_actions_adddup2(&fa, p[1], 1));
ASSERT_EQ(0, posix_spawn_file_actions_addchdir_np(&fa, "subdir"));
ASSERT_EQ(0, posix_spawn(&pid, "../cocmd.com", &fa, 0, args, envs));
ASSERT_EQ(0, posix_spawn_file_actions_destroy(&fa));
ASSERT_SYS(0, 0, close(p[1]));
ASSERT_NE(-1, waitpid(pid, &ws, 0));
ASSERT_EQ(0, ws);
ASSERT_SYS(0, 6, read(p[0], buf, sizeof(buf)));
ASSERT_STREQ("hello\n", buf);
ASSERT_SYS(0, 0, close(p[0]));
}
_Thread_local atomic_int gotsome;
void OhMyGoth(int sig) {

View file

@ -64,6 +64,7 @@ o/$(MODE)/test/libc/proc/posix_spawn_test.com.dbg: \
o/$(MODE)/test/libc/proc/posix_spawn_test.o \
o/$(MODE)/test/libc/proc/proc.pkg \
o/$(MODE)/tool/build/echo.com.zip.o \
o/$(MODE)/tool/build/cocmd.com.zip.o \
o/$(MODE)/test/libc/mem/prog/life.com.zip.o \
o/$(MODE)/test/libc/mem/prog/life.elf.zip.o \
o/$(MODE)/test/libc/proc/life-pe.com.zip.o \