Skip to content

Commit

Permalink
selftests/exec: Check if the syscall exists and bail if not
Browse files Browse the repository at this point in the history
On systems which don't implement sys_execveat(), this test produces a
lot of output.

Add a check at the beginning to see if the syscall is present, and if
not just note one error and return.

When we run on a system that doesn't implement the syscall we will get
ENOSYS back from the kernel, so change the logic that handles
__NR_execveat not being defined to also use ENOSYS rather than -ENOSYS.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: David Drysdale <drysdale@google.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
  • Loading branch information
Michael Ellerman authored and Shuah Khan committed Mar 11, 2015
1 parent 9eccca0 commit 9a0b574
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tools/testing/selftests/exec/execveat.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static int execveat_(int fd, const char *path, char **argv, char **envp,
#ifdef __NR_execveat
return syscall(__NR_execveat, fd, path, argv, envp, flags);
#else
errno = -ENOSYS;
errno = ENOSYS;
return -1;
#endif
}
Expand Down Expand Up @@ -234,6 +234,14 @@ static int run_tests(void)
int fd_cloexec = open_or_die("execveat", O_RDONLY|O_CLOEXEC);
int fd_script_cloexec = open_or_die("script", O_RDONLY|O_CLOEXEC);

/* Check if we have execveat at all, and bail early if not */
errno = 0;
execveat_(-1, NULL, NULL, NULL, 0);
if (errno == ENOSYS) {
printf("[FAIL] ENOSYS calling execveat - no kernel support?\n");
return 1;
}

/* Change file position to confirm it doesn't affect anything */
lseek(fd, 10, SEEK_SET);

Expand Down

0 comments on commit 9a0b574

Please sign in to comment.