vgdb: Handle EAGAIN in read_buf
[valgrind.git] / none / tests / execve.c
bloba1af72fd9e4924711ade0b48e59bb68d3f680cbc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 int main(int argc, char **argv)
7 if (argc == 1)
9 // This tests the case where argv and envp are NULL, which is easy to
10 // get wrong because it's an unusual case. It is also bad and only
11 // "worked" by accident with the linux kernel.
13 char *const argv_exe[] = {"true", NULL};
14 char *const v_null[] = { NULL };
15 char *const v_minus_one[] = { (char *const) -1, NULL };
17 #if defined(VGO_solaris)
18 const char *exe = "/bin/true";
19 #elif defined(VGO_darwin)
20 const char *exe = "/usr/bin/true";
21 #elif defined(VGO_freebsd)
22 const char *exe = "/usr/bin/true";
23 #else
24 const char *exe = "/bin/true";
25 #endif
27 /* Try some bad argv and envp arguments, make sure the executable
28 doesn't actually exists, so execve doesn't accidentally succeeds. */
29 if (execve("/%/", NULL, NULL) >= 0)
30 printf ("WHAT?");
31 if (execve("/%/", (void *)-1, NULL) >= 0)
32 printf ("WHAT?");
33 if (execve("/%/", v_null, NULL) >= 0)
34 printf ("WHAT?");
35 if (execve("/%/", v_null, v_null) >= 0)
36 printf ("WHAT?");
37 if (execve("/%/", v_minus_one, NULL) >= 0)
38 printf ("WHAT?");
39 if (execve("/%/", v_minus_one, v_null) >= 0)
40 printf ("WHAT?");
41 if (execve("/%/", v_minus_one, v_minus_one) >= 0)
42 printf ("WHAT?");
44 /* Finally a correct execve. */
45 if (execve(exe, argv_exe, NULL) < 0)
47 perror("execve");
48 exit(1);
52 exit(0);