Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / memcheck / tests / linux / sys-execveat.c
blob921b8888ffd915057827c9fe90113624d08d3fa6
1 #include <sys/syscall.h>
2 #include <errno.h>
3 #include <dirent.h>
4 #include <unistd.h>
5 #include <stddef.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
11 static int sys_execveat (int dirfd, const char *pathname,
12 char *const argv[], char *const envp[],
13 int flags)
15 #if defined(__NR_execveat)
16 return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
17 #else
18 errno = ENOSYS;
19 return -1;
20 #endif
24 int main()
26 char *argv[] = { "foobar", "execveat exists", NULL };
27 char *envp[] = { NULL };
28 DIR *dirp;
29 int fd;
31 dirp = opendir("/bin");
32 if (dirp == NULL) {
33 perror("execveat");
34 exit(EXIT_FAILURE);
36 fd = dirfd(dirp);
38 /* Check valgrind will produce expected warnings for the
39 various wrong arguments. */
40 do {
41 char *mem = malloc(16);
42 void *t = (void *) &mem[0];
43 void *z = (void *) -1;
44 int flag = *((int *) &mem[8]);
46 sys_execveat(-1, "bin/xecho", argv, envp, 0);
47 sys_execveat(-1, "xecho", argv, envp, 0);
48 sys_execveat(fd, "xecho", argv, envp, flag);
49 sys_execveat(fd, "", argv, envp, 0);
50 sys_execveat(fd, NULL, argv, envp, 0);
51 sys_execveat(fd, "xecho", t, envp, 0);
52 sys_execveat(fd, "xecho", z, envp, 0);
53 } while (0);
55 /* Check execveat called with the correct arguments works. */
56 if (sys_execveat(fd, "echo", argv, envp, 0) == -1) {
57 perror("execveat");
58 exit(EXIT_FAILURE);
61 closedir(dirp);
62 exit(EXIT_SUCCESS);