1/* Test that an error from posix_spawn() is correctly propagated to the 2 parent. */ 3 4#include <errno.h> 5#include <stdio.h> 6#include <stdlib.h> 7#include <unistd.h> 8#include <spawn.h> 9 10int main(void) 11{ 12 int res = 1; 13 int err; 14 posix_spawn_file_actions_t file_actions; 15 char *argv_exe[] = {"true", NULL}; 16 char *envv_exe[] = {NULL}; 17 18 err = posix_spawn_file_actions_init(&file_actions); 19 if (err != 0) { 20 errno = err; 21 perror("posix_spawn_file_actions_init"); 22 return 1; 23 } 24 25 err = posix_spawn_file_actions_adddup2(&file_actions, 3, 4); 26 if (err != 0) { 27 errno = err; 28 perror("posix_spawn_file_actions_adddup2"); 29 goto out; 30 } 31 32 /* The following call to posix_spawn() should fail because the requested 33 dup2 action cannot be performed. */ 34 err = posix_spawn(NULL, "/bin/true", &file_actions, NULL, argv_exe, 35 envv_exe); 36 if (err != 0) { 37 errno = err; 38 perror("posix_spawn"); 39 goto out; 40 } 41 42 res = 0; 43 44out: 45 err = posix_spawn_file_actions_destroy(&file_actions); 46 if (err != 0) { 47 errno = err; 48 perror("posix_spawn_file_actions_destroy"); 49 res = 1; 50 } 51 52 return res; 53} 54 55