1 /* Functional tests for spawn() syscall invoked indirectly via posix_spawn()
13 #define EXE_NAME "../../../tests/true"
15 static volatile int sigchld_handled
= 0;
16 static void sigchld_handler(int sig
, siginfo_t
*sip
, void *ucontext
) {
17 assert(sig
== SIGCHLD
);
21 int main(int argc
, char *const argv
[], char *const envp
[]) {
22 int ret
= system(EXE_NAME
);
29 fprintf(stderr
, "system() succeeded");
31 /* posix_spawn(), no file actions, no attrs */
32 char *const argv_exe
[] = {"true", NULL
};
34 ret
= posix_spawn(&child
, EXE_NAME
, NULL
, NULL
, argv_exe
, envp
);
36 perror("posix_spawn");
37 waitpid(child
, NULL
, 0);
39 /* posix_spawn(), file actions, no attrs */
40 posix_spawn_file_actions_t fa
;
41 ret
= posix_spawn_file_actions_init(&fa
);
43 perror("posix_spawn_file_actions_init");
44 ret
= posix_spawn_file_actions_addopen(&fa
, 10, "/dev/null", O_RDONLY
, 0);
46 perror("posix_spawn_file_actions_addopen");
47 ret
= posix_spawn(&child
, EXE_NAME
, &fa
, NULL
, argv_exe
, envp
);
49 perror("posix_spawn");
50 waitpid(child
, NULL
, 0);
51 ret
= posix_spawn_file_actions_destroy(&fa
);
53 perror("posix_spawn_file_actions_destroy");
55 /* posix_spawn(), no file actions, attrs */
56 posix_spawnattr_t spa
;
57 ret
= posix_spawnattr_init(&spa
);
59 perror("posix_spawnattr_init");
60 ret
= posix_spawnattr_setflags(&spa
, POSIX_SPAWN_RESETIDS
);
62 perror("posix_spawnattr_setflags");
63 ret
= posix_spawn(&child
, EXE_NAME
, NULL
, &spa
, argv_exe
, envp
);
65 perror("posix_spawn");
66 waitpid(child
, NULL
, 0);
67 ret
= posix_spawnattr_destroy(&spa
);
69 perror("posix_spawnattr_destroy");
71 /* posix_spawn(), no file actions, no attrs, test SIGCHLD delivery */
73 bzero(&act
, sizeof(act
));
74 act
.sa_sigaction
= sigchld_handler
;
75 act
.sa_flags
= SA_SIGINFO
;
76 ret
= sigaction(SIGCHLD
, &act
, NULL
);
80 ret
= posix_spawn(&child
, EXE_NAME
, NULL
, NULL
, argv_exe
, envp
);
82 perror("posix_spawn");
83 waitpid(child
, NULL
, 0);
84 if (sigchld_handled
== 1) {
90 /* posix_spawn(), no file actions, attrs, test *no* SIGCHLD delivery */
91 ret
= posix_spawnattr_init(&spa
);
93 perror("posix_spawnattr_init");
94 ret
= posix_spawnattr_setflags(&spa
, POSIX_SPAWN_NOSIGCHLD_NP
);
96 perror("posix_spawnattr_setflags");
98 ret
= posix_spawn(&child
, EXE_NAME
, NULL
, &spa
, argv_exe
, envp
);
100 perror("posix_spawn");
101 waitpid(child
, NULL
, 0);
102 if (sigchld_handled
== 0) {
107 ret
= posix_spawnattr_destroy(&spa
);
109 perror("posix_spawnattr_destroy");