Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/exec: Check if the syscall exists and bail if not

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>

authored by

Michael Ellerman and committed by
Shuah Khan
9a0b5745 9eccca08

+9 -1
+9 -1
tools/testing/selftests/exec/execveat.c
··· 30 30 #ifdef __NR_execveat 31 31 return syscall(__NR_execveat, fd, path, argv, envp, flags); 32 32 #else 33 - errno = -ENOSYS; 33 + errno = ENOSYS; 34 34 return -1; 35 35 #endif 36 36 } ··· 233 233 int fd_script_ephemeral = open_or_die("script.ephemeral", O_RDONLY); 234 234 int fd_cloexec = open_or_die("execveat", O_RDONLY|O_CLOEXEC); 235 235 int fd_script_cloexec = open_or_die("script", O_RDONLY|O_CLOEXEC); 236 + 237 + /* Check if we have execveat at all, and bail early if not */ 238 + errno = 0; 239 + execveat_(-1, NULL, NULL, NULL, 0); 240 + if (errno == ENOSYS) { 241 + printf("[FAIL] ENOSYS calling execveat - no kernel support?\n"); 242 + return 1; 243 + } 236 244 237 245 /* Change file position to confirm it doesn't affect anything */ 238 246 lseek(fd, 10, SEEK_SET);