xref: /llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/posix_spawn.c (revision 869989dd713df68ed0f31b4c80262aed9c5cdc66)
1 // RUN: %clang %s -o %t && %run %t 2>&1 | FileCheck %s
2 //
3 // Older versions of Android do not have certain posix_spawn* functions.
4 // UNSUPPORTED: android
5 
6 #include <assert.h>
7 #include <spawn.h>
8 #include <stdio.h>
9 #include <sys/wait.h>
10 
main(int argc,char ** argv)11 int main(int argc, char **argv) {
12   if (argc > 1) {
13     // CHECK: SPAWNED
14     // CHECK: SPAWNED
15     printf("SPAWNED\n");
16     return 0;
17   }
18 
19   posix_spawnattr_t attr = {0};
20   posix_spawn_file_actions_t file_actions = {0};
21 
22   char *const args[] = {
23       argv[0], "2", "3", "4", "2", "3", "4", "2", "3", "4",
24       "2",     "3", "4", "2", "3", "4", "2", "3", "4", NULL,
25   };
26   char *const env[] = {
27       "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B",
28       "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", NULL,
29   };
30 
31   pid_t pid;
32   int s = posix_spawn(&pid, argv[0], &file_actions, &attr, args, env);
33   assert(!s);
34 
35   waitpid(pid, &s, WUNTRACED | WCONTINUED);
36 
37   s = posix_spawnp(&pid, argv[0], &file_actions, &attr, args, env);
38   assert(!s);
39 
40   waitpid(pid, &s, WUNTRACED | WCONTINUED);
41   return 0;
42 }
43