Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755514AbbBCH7W (ORCPT ); Tue, 3 Feb 2015 02:59:22 -0500 Received: from mail-qc0-f175.google.com ([209.85.216.175]:60730 "EHLO mail-qc0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752561AbbBCH7V (ORCPT ); Tue, 3 Feb 2015 02:59:21 -0500 MIME-Version: 1.0 In-Reply-To: <1422935588-9973-1-git-send-email-mpe@ellerman.id.au> References: <1422935588-9973-1-git-send-email-mpe@ellerman.id.au> From: David Drysdale Date: Tue, 3 Feb 2015 07:58:59 +0000 Message-ID: Subject: Re: [PATCH v2] selftests/exec: Check if the syscall exists and bail if not To: Michael Ellerman Cc: "linux-kernel@vger.kernel.org" , Linux API , Geert Uytterhoeven , Shuah Khan , davej@codemonkey.org.uk Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2266 Lines: 62 On Tue, Feb 3, 2015 at 3:53 AM, Michael Ellerman wrote: > 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 Acked-by: David Drysdale > --- > > v2: Switch to positive ENOSYS. Confirmed this works as expected in the > case where the syscall is defined, but then is not present at runtime. Thanks! > > tools/testing/selftests/exec/execveat.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/exec/execveat.c b/tools/testing/selftests/exec/execveat.c > index e238c9559caf..8d5d1d2ee7c1 100644 > --- a/tools/testing/selftests/exec/execveat.c > +++ b/tools/testing/selftests/exec/execveat.c > @@ -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 > } > @@ -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); > > -- > 2.1.0 > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/