File: execveat.c

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (51 lines) | stat: -rw-r--r-- 1,628 bytes parent folder | download | duplicates (3)
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
/* COVERAGE: execveat */
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <fcntl.h>
#if !defined(SYS_execveat) && defined(__NR_execveat)
#define SYS_execveat __NR_execveat
#endif
#include <sys/mman.h>

#ifdef SYS_execveat
static inline int
__execveat(int dirfd, const char *filename, char *const argv[],
	   char *const envp[], int flags)
{
    return syscall(SYS_execveat, dirfd, filename, argv, envp, flags);
}
#endif

int main()
{
#ifdef SYS_execveat
    mlockall(MCL_CURRENT);

    char *newargv[] = { "/bin/true", "a", "b", "cde", NULL };
    char *newenv[] = { "FOO=10", "BAR=20", NULL };

    /* Limit testing */
    __execveat(-1, (char *)-1, NULL, NULL, 0);
    //staptest// [[[[execveat (-1, 0x[f]+, \[\], \[\], 0x0)!!!!ni_syscall ()]]]] = -NNNN

    __execveat(-1, "/bin/true", (char **)-1, NULL, 0);
    //staptest// [[[[execveat (-1, "/bin/true", \[0x[f]+\], \[\], 0x0)!!!!ni_syscall ()]]]] = -NNNN

    __execveat(-1, "/bin/true", NULL, (char **)-1, 0);
    //staptest// [[[[execveat (-1, "/bin/true", \[\], \[0x[f]+\], 0x0)!!!!ni_syscall ()]]]] = -NNNN

    __execveat(-1, "/bin/true", NULL, NULL, -1);
    //staptest// [[[[execveat (-1, "/bin/true", \[\], \[\], AT_[^ ]+|XXXX)!!!!ni_syscall ()]]]] = -NNNN

    __execveat(AT_FDCWD, "", NULL, NULL, 0);
    //staptest// [[[[execveat (AT_FDCWD, "", \[\], \[\], 0x0)!!!!ni_syscall ()]]]] = -NNNN

    /* Regular testing. */
    __execveat(-1, newargv[0], newargv, newenv, 0);
    //staptest// [[[[execveat (-1, "/bin/true", \["/bin/true", "a", "b", "cde"\], \["FOO=10", "BAR=20"\], 0x0)!!!!ni_syscall ()]]]] = NNNN
#endif

    return 0;
}