selftests/exec: Avoid future NULL argv execve warning
Subsystems (3)
PATCH 1/1 selftests/exec: Avoid future NULL argv execve warning
Build actual argv for launching recursion test to avoid future warning about using an empty argv in execve().
--- tools/testing/selftests/exec/recursion-depth.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/exec/recursion-depth.c +8 -4
@@ -24,8 +24,14 @@#include <sys/mount.h> #include <unistd.h> +#define FILENAME "/tmp/1" +#define HASHBANG "#!" FILENAME "\n" +int main (void ) { +char *const argv[] = {FILENAME ,NULL }; +int rv; +if (unshare (CLONE_NEWNS ) ==-1 ) {if (errno ==ENOSYS || errno ==EPERM ) {fprintf (stderr,"error: unshare, errno %d\n" , errno);
@@ -44,21 +50,19 @@ int main(void)return 1 ; } -#define FILENAME "/tmp/1"int fd =creat (FILENAME ,0700 );if (fd ==-1 ) {fprintf (stderr,"error: creat, errno %d\n" , errno);return 1 ; } -#define S "#!" FILENAME "\n" -if (write (fd,S ,strlen (S )) !=strlen (S )) { +if (write (fd,HASHBANG ,strlen (HASHBANG )) !=strlen (HASHBANG )) {fprintf (stderr,"error: write, errno %d\n" , errno);return 1 ; }close (fd); -int rv =execve (FILENAME ,NULL ,NULL ); + rv =execve (FILENAME , argv,NULL );if (rv ==-1 && errno ==ELOOP ) {return 0 ; }
Signature · 1 line
2.30.2
Quoted 6 lines · Kees Cook
Build actual argv for launching recursion test to avoid future warning about using an empty argv in
execve().
tools/testing/selftests/exec/recursion-depth.c line 33
Quoted 10 lines
tools/testing/selftests/exec/recursion-depth.c +5
-0@@ -24,8 +24,14 @@#include <sys/mount.h> #include <unistd.h> +#define FILENAME "/tmp/1" +#define HASHBANG "#!" FILENAME "\n" +int main (void ) { +char *const argv[] = {FILENAME ,NULL }; +int rv;
Can we move out of -Wdeclaration-after-statement mentality in tests at least?
tools/testing/selftests/exec/recursion-depth.c int main(void) · line 65
Quoted 2 lines
tools/testing/selftests/exec/recursion-depth.c +1
-1-int rv =execve (FILENAME ,NULL ,NULL ); + rv =execve (FILENAME , argv,NULL );
int rv = execve(FILENAME, (char*[]){FILENAME, NULL}, NULL);is cleaner (and modern)!
Quoted 3 lines
tools/testing/selftests/exec/recursion-depth.c +0
-0if (rv ==-1 && errno ==ELOOP ) {return 0 ; }
Shuah Khan
maintainerQuoted 10 lines · Alexey Dobriyan
Quoted 9 lines · Kees Cook
Build actual argv for launching recursion test to avoid future warning about using an empty argv in
execve().tools/testing/selftests/exec/recursion-depth.c +0
-0@@ -24,8 +24,14 @@#include <sys/mount.h> #include <unistd.h>
Quoted 9 lines
tools/testing/selftests/exec/recursion-depth.c line 33
Quoted 7 lines
tools/testing/selftests/exec/recursion-depth.c +5
-0+#define FILENAME "/tmp/1" +#define HASHBANG "#!" FILENAME "\n" +int main (void ) { +char *const argv[] = {FILENAME ,NULL }; +int rv;Can we move out of -Wdeclaration-after-statement mentality in tests at least?
selftest like the rest of the kernel follows the same coding guidelines. It will follow the moving "-Wdeclaration-after-statement mentality" when the rest of the kernel does.
Looks like this topic was discussed in the following:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/
thanks,
-- Shuah
Quoted 20 lines · Shuah Khan
Quoted 4 lines · Alexey Dobriyan
Quoted 2 lines · Kees Cook
Build actual argv for launching recursion test to avoid future warning about using an empty argv in
execve().Quoted 14 lines
tools/testing/selftests/exec/recursion-depth.c line 32
Quoted 12 lines
tools/testing/selftests/exec/recursion-depth.c +5
-0@@ -24,8 +24,14 @@#include <sys/mount.h> #include <unistd.h> +#define FILENAME "/tmp/1" +#define HASHBANG "#!" FILENAME "\n" +int main (void ) { +char *const argv[] = {FILENAME ,NULL }; +int rv;Can we move out of -Wdeclaration-after-statement mentality in tests at least?
Quoted 6 lines
selftest like the rest of the kernel follows the same coding guidelines. It will follow the moving "-Wdeclaration-after-statement mentality" when the rest of the kernel does.
Looks like this topic was discussed in the following:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/
The only real argument is "gcc miscompiles /proc" to which adding -Wdeclaration-after-statement looks like a too big hammer.
Why can't we have nice things?
Shuah Khan
maintainerQuoted 25 lines · Alexey Dobriyan
Quoted 24 lines · Shuah Khan
Quoted 4 lines · Alexey Dobriyan
Quoted 2 lines · Kees Cook
Build actual argv for launching recursion test to avoid future warning about using an empty argv in
execve().Quoted 14 lines
tools/testing/selftests/exec/recursion-depth.c line 32
Quoted 12 lines
tools/testing/selftests/exec/recursion-depth.c +5
-0@@ -24,8 +24,14 @@#include <sys/mount.h> #include <unistd.h> +#define FILENAME "/tmp/1" +#define HASHBANG "#!" FILENAME "\n" +int main (void ) { +char *const argv[] = {FILENAME ,NULL }; +int rv;Can we move out of -Wdeclaration-after-statement mentality in tests at least?
selftest like the rest of the kernel follows the same coding guidelines. It will follow the moving "-Wdeclaration-after-statement mentality" when the rest of the kernel does.
Quoted 6 lines
Quoted 2 lines
Looks like this topic was discussed in the following:
https://patchwork.kernel.org/project/linux-kbuild/patch/[email protected]/The only real argument is "gcc miscompiles /proc" to which adding -Wdeclaration-after-statement looks like a too big hammer.
Either way - selftest will stay in sync with the kernel coding standards for good reasons. Doing its own thing confuses developers and makes it hard for maintainers.
thanks,
-- Shuah