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