linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] selftests/exec: Check if the syscall exists and bail if not
@ 2015-02-03  3:53 Michael Ellerman
  2015-02-03  7:58 ` David Drysdale
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Ellerman @ 2015-02-03  3:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-api, geert, drysdale, shuahkh, davej

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>
---

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.


 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] selftests/exec: Check if the syscall exists and bail if not
  2015-02-03  3:53 [PATCH v2] selftests/exec: Check if the syscall exists and bail if not Michael Ellerman
@ 2015-02-03  7:58 ` David Drysdale
  2015-02-03 15:32   ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: David Drysdale @ 2015-02-03  7:58 UTC (permalink / raw)
  To: Michael Ellerman
  Cc: linux-kernel, Linux API, Geert Uytterhoeven, Shuah Khan, davej

On Tue, Feb 3, 2015 at 3:53 AM, Michael Ellerman <mpe@ellerman.id.au> 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 <mpe@ellerman.id.au>

Acked-by: David Drysdale <drysdale@google.com>

> ---
>
> 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
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] selftests/exec: Check if the syscall exists and bail if not
  2015-02-03  7:58 ` David Drysdale
@ 2015-02-03 15:32   ` Shuah Khan
  2015-02-04  2:46     ` Michael Ellerman
  0 siblings, 1 reply; 4+ messages in thread
From: Shuah Khan @ 2015-02-03 15:32 UTC (permalink / raw)
  To: David Drysdale, Michael Ellerman
  Cc: linux-kernel, Linux API, Geert Uytterhoeven, davej

On 02/03/2015 12:58 AM, David Drysdale wrote:
> On Tue, Feb 3, 2015 at 3:53 AM, Michael Ellerman <mpe@ellerman.id.au> 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 <mpe@ellerman.id.au>
> 
> Acked-by: David Drysdale <drysdale@google.com>

Thanks Michael, and David. I will queue this for 3.20

-- Shuah


-- 
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
shuahkh@osg.samsung.com | (970) 217-8978

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] selftests/exec: Check if the syscall exists and bail if not
  2015-02-03 15:32   ` Shuah Khan
@ 2015-02-04  2:46     ` Michael Ellerman
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2015-02-04  2:46 UTC (permalink / raw)
  To: Shuah Khan
  Cc: David Drysdale, linux-kernel, Linux API, Geert Uytterhoeven, davej

On Tue, 2015-02-03 at 08:32 -0700, Shuah Khan wrote:
> On 02/03/2015 12:58 AM, David Drysdale wrote:
> > On Tue, Feb 3, 2015 at 3:53 AM, Michael Ellerman <mpe@ellerman.id.au> 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 <mpe@ellerman.id.au>
> > 
> > Acked-by: David Drysdale <drysdale@google.com>
> 
> Thanks Michael, and David. I will queue this for 3.20

Thanks.

cheers



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-04  2:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-03  3:53 [PATCH v2] selftests/exec: Check if the syscall exists and bail if not Michael Ellerman
2015-02-03  7:58 ` David Drysdale
2015-02-03 15:32   ` Shuah Khan
2015-02-04  2:46     ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).