/*[SPN]*/ /* Test whether a basic posix_spawn_file_actions_addopen invocation works. */ #include #include #include #include #include #include #include #include #include "../basic.h" extern char** environ; int main(int argc, char* argv[]) { // fd0 tests that existing fds are overwritten. // fd3 tests that a fd can be opened on spawn. // fd4 tests that a fd opened with CLOEXEC on spawn is closed afterwards. int fd0 = 0; int fd3 = 3; int fd4 = 4; if ( argc == 2 ) { struct stat st0, st3, st4; if ( strcmp(argv[1], "success") != 0 ) err(1, "child invoked incorrectly"); if ( fstat(fd0, &st0) < 0 ) errx(1, "fd3 was not open in child"); if ( fstat(fd3, &st3) < 0 ) errx(1, "fd3 was not open in child"); if ( !fstat(fd4, &st4) ) errx(1, "fd4 was not closed in child"); else if ( errno != EBADF ) err(1, "child fstat"); if ( st0.st_dev != st3.st_dev || st0.st_ino != st3.st_ino ) errx(1, "fd0 and fd3 are not the sa