Changeset View
Changeset View
Standalone View
Standalone View
contrib/netbsd-tests/lib/libc/gen/posix_spawn/t_fileactions.c
Show First 20 Lines • Show All 295 Lines • ▼ Show 20 Lines | ATF_TC_HEAD(t_spawn_fileactions, tc) | ||||
atf_tc_set_md_var(tc, "descr", | atf_tc_set_md_var(tc, "descr", | ||||
"Tests various complex fileactions"); | "Tests various complex fileactions"); | ||||
} | } | ||||
ATF_TC_BODY(t_spawn_fileactions, tc) | ATF_TC_BODY(t_spawn_fileactions, tc) | ||||
{ | { | ||||
int fd1, fd2, fd3, status, err; | int fd1, fd2, fd3, status, err; | ||||
pid_t pid; | pid_t pid; | ||||
char * const args[2] = { __UNCONST("h_fileactions"), NULL }; | char *args[3] = { __UNCONST("h_fileactions"), NULL, NULL }; | ||||
int lowfd; | |||||
char lowfdstr[32]; | |||||
char helper[FILENAME_MAX]; | char helper[FILENAME_MAX]; | ||||
posix_spawn_file_actions_t fa; | posix_spawn_file_actions_t fa; | ||||
posix_spawn_file_actions_init(&fa); | posix_spawn_file_actions_init(&fa); | ||||
closefrom(fileno(stderr)+1); | /* Note: this assumes no gaps in the fd table */ | ||||
lowfd = open("/", O_RDONLY); | |||||
ATF_REQUIRE(lowfd > 0); | |||||
ATF_REQUIRE_EQ(0, close(lowfd)); | |||||
snprintf(lowfdstr, sizeof(lowfdstr), "%d", lowfd); | |||||
args[1] = lowfdstr; | |||||
fd1 = open("/dev/null", O_RDONLY); | fd1 = open("/dev/null", O_RDONLY); | ||||
ATF_REQUIRE(fd1 == 3); | ATF_REQUIRE_EQ(fd1, lowfd); | ||||
fd2 = open("/dev/null", O_WRONLY, O_CLOEXEC); | fd2 = open("/dev/null", O_WRONLY, O_CLOEXEC); | ||||
ATF_REQUIRE(fd2 == 4); | ATF_REQUIRE_EQ(fd2, lowfd + 1); | ||||
fd3 = open("/dev/null", O_WRONLY); | fd3 = open("/dev/null", O_WRONLY); | ||||
ATF_REQUIRE(fd3 == 5); | ATF_REQUIRE_EQ(fd3, lowfd + 2); | ||||
posix_spawn_file_actions_addclose(&fa, fd1); | posix_spawn_file_actions_addclose(&fa, fd1); | ||||
posix_spawn_file_actions_addopen(&fa, 6, "/dev/null", O_RDWR, 0); | posix_spawn_file_actions_addopen(&fa, lowfd + 3, "/dev/null", O_RDWR, | ||||
posix_spawn_file_actions_adddup2(&fa, 1, 7); | 0); | ||||
posix_spawn_file_actions_adddup2(&fa, 1, lowfd + 4); | |||||
snprintf(helper, sizeof helper, "%s/h_fileactions", | snprintf(helper, sizeof helper, "%s/h_fileactions", | ||||
atf_tc_get_config_var(tc, "srcdir")); | atf_tc_get_config_var(tc, "srcdir")); | ||||
err = posix_spawn(&pid, helper, &fa, NULL, args, NULL); | err = posix_spawn(&pid, helper, &fa, NULL, args, NULL); | ||||
posix_spawn_file_actions_destroy(&fa); | posix_spawn_file_actions_destroy(&fa); | ||||
ATF_REQUIRE(err == 0); | ATF_REQUIRE(err == 0); | ||||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |