Skip to contentSkip to conversation

newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

PATCH New Xiao Yang 4 participants 10 messages Aug 23, 2018 – Sep 10, 2018

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

From: xiao yang <[email protected]>

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

---
 doc/test-writing-guidelines.txt | 11 ++++++++---
 lib/newlib_tests/test_exec.c    | 11 ++++++++---
 2 files changed, 16 insertions(+), 6 deletions(-)
doc/test-writing-guidelines.txt +8 -3
index a169724..f62e16e 100644
@@ -696,15 +696,20 @@ a non zero exit code.
 [source,c]
 -------------------------------------------------------------------------------
 /* test.c */
-#define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
+extern char **environ;
+
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
lib/newlib_tests/test_exec.c +8 -3
index 8aef621..e70080e 100644
@@ -24,15 +24,20 @@
  * $ PATH=$PATH:$PWD ./test_exec
  */
 
-#define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
+extern char **environ;
+
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
Signature · 1 line
1.7.11.rc0
author
#1 lore raw

PATCH 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

Quoted 7 lines · Xiao Yang

From: xiao yang <[email protected]>

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

Hi,

Sorry for the wrong signature.

The correct one:

Thanks,
Xiao Yang

Quoted 61 lines
---
 doc/test-writing-guidelines.txt | 11 ++++++++---
 lib/newlib_tests/test_exec.c    | 11 ++++++++---
 2 files changed, 16 insertions(+), 6 deletions(-)
doc/test-writing-guidelines.txt +8 -3
index a169724..f62e16e 100644
@@ -696,15 +696,20 @@ a non zero exit code.
 [source,c]
 -------------------------------------------------------------------------------
 /* test.c */
-#define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
+extern char **environ;
+
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
lib/newlib_tests/test_exec.c +8 -3
index 8aef621..e70080e 100644
@@ -24,15 +24,20 @@
  * $ PATH=$PATH:$PWD ./test_exec
  */
 
-#define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
+extern char **environ;
+
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
#2 lore raw

PATCH 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

In reply to Xiao Yang

Hi!

Quoted 15 lines

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

---
 doc/test-writing-guidelines.txt | 11 ++++++++---
 lib/newlib_tests/test_exec.c    | 11 ++++++++---
 2 files changed, 16 insertions(+), 6 deletions(-)
doc/test-writing-guidelines.txt +0 -0
index a169724..f62e16e 100644

doc/test-writing-guidelines.txt a non zero exit code. · line 702

Quoted 9 lines
doc/test-writing-guidelines.txt +2 -2
@@ -696,15 +696,20 @@ a non zero exit code.
 [source,c]
 -------------------------------------------------------------------------------
 /* test.c */
-#define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
+extern char **environ;

Looking at this the only change here should be:

doc/test-writing-guidelines.txt a non zero exit code. · line 703

Quoted 2 lines
doc/test-writing-guidelines.txt +1 -1
-#include <stdlib.h>
+#include <unistd.h>

As man 7 environ says:

(This variable must be declared in the user program, but is declared in the header file <unistd.h> if the _GNU_SOURCE feature test macro is defined.)

Or is environ not defined with _GNU_SOURCE for older libc?

Quoted 17 lines
doc/test-writing-guidelines.txt +5 -1
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
lib/newlib_tests/test_exec.c +0 -0
index 8aef621..e70080e 100644

lib/newlib_tests/test_exec.c line 30

Quoted 9 lines
lib/newlib_tests/test_exec.c +2 -2
@@ -24,15 +24,20 @@
  * $ PATH=$PATH:$PWD ./test_exec
  */
 
-#define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
+extern char **environ;

Here as well.

lib/newlib_tests/test_exec.c line 42

Quoted 13 lines
lib/newlib_tests/test_exec.c +5 -1
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#3 lore raw

PATCH 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

Quoted 31 lines · Cyril Hrubis

Hi!

Quoted 15 lines

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

---
  doc/test-writing-guidelines.txt | 11 ++++++++---
  lib/newlib_tests/test_exec.c    | 11 ++++++++---
  2 files changed, 16 insertions(+), 6 deletions(-)
doc/test-writing-guidelines.txt +0 -0
index a169724..f62e16e 100644

doc/test-writing-guidelines.txt a non zero exit code. · line 702

Quoted 9 lines
doc/test-writing-guidelines.txt +2 -2
@@ -696,15 +696,20 @@ a non zero exit code.
  [source,c]
  -------------------------------------------------------------------------------
  /* test.c */
-#define _GNU_SOURCE
-#include<stdlib.h>
+#include<unistd.h>
  #include "tst_test.h"
 
+extern char **environ;

Looking at this the only change here should be:

doc/test-writing-guidelines.txt a non zero exit code. · line 703

Quoted 2 lines
doc/test-writing-guidelines.txt +1 -1
-#include<stdlib.h>
+#include<unistd.h>

As man 7 environ says:

Quoted 5 lines

(This variable must be declared in the user program, but is declared in the header file<unistd.h> if the _GNU_SOURCE feature test macro is defined.)

Or is environ not defined with _GNU_SOURCE for older libc?

Hi, Cyril

Older libc declares environ when _GNU_SOURCE is defined, so only repalcing stdlib.h with unistd.h seems simpler.

I will send the v2 patch soon.

Thanks,
Xiao Yang

Quoted 43 lines
Quoted 17 lines
doc/test-writing-guidelines.txt +5 -1
  static void do_test(void)
  {
  	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
  	tst_res(TBROK | TERRNO, "EXEC!");
  }
lib/newlib_tests/test_exec.c +0 -0
index 8aef621..e70080e 100644

lib/newlib_tests/test_exec.c line 30

Quoted 9 lines
lib/newlib_tests/test_exec.c +2 -2
@@ -24,15 +24,20 @@
   * $ PATH=$PATH:$PWD ./test_exec
   */
 
-#define _GNU_SOURCE
-#include<stdlib.h>
+#include<unistd.h>
  #include "tst_test.h"
 
+extern char **environ;

Here as well.

lib/newlib_tests/test_exec.c line 42

Quoted 13 lines
lib/newlib_tests/test_exec.c +5 -1
  static void do_test(void)
  {
  	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
 
-	execvpe(argv[0], argv, environ);
+	execve(path, argv, environ);
 
  	tst_res(TBROK | TERRNO, "EXEC!");
  }

Otherwise it looks good.

author
#4 lore raw

PATCH v2 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

In reply to Cyril Hrubis

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

---
 doc/test-writing-guidelines.txt | 8 ++++++--
 lib/newlib_tests/test_exec.c    | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)
doc/test-writing-guidelines.txt +6 -2
index a169724..0b89cf9 100644
@@ -697,14 +697,18 @@ a non zero exit code.
 -------------------------------------------------------------------------------
 /* test.c */
 #define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
 
-	execvpe(argv[0], argv, environ);
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
+
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
lib/newlib_tests/test_exec.c +6 -2
index 8aef621..2c86568 100644
@@ -25,14 +25,18 @@
  */
 
 #define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
 
-	execvpe(argv[0], argv, environ);
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
+
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v2 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

----- Original Message -----

Quoted 5 lines

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

This is older than oldest RHEL distro I still use to check LTP builds, but it works fine on more recent ones, so ACK.

Regards,
Jan

author
#6 lore raw

PATCH v2 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

Quoted 8 lines · Jan Stancek

----- Original Message -----

Quoted 5 lines

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

This is older than oldest RHEL distro I still use to check LTP builds, but it works fine on more recent ones, so ACK.

Hi Jan,

Thanks for your review.
I saw this issue on RHEL5.

Thanks,
Xiao Yang

Quoted 5 lines

Regards,
Jan

#7 lore raw

PATCH v2 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

In reply to Xiao Yang

Hi Xiao,

Quoted 3 lines

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

Oh, that's a history :). But as it's forward compatible, why not.

Quoted 1 line

Kind regards,
Petr

author
#8 lore raw

PATCH v2 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

In reply to Xiao Yang

Hi,

Could you help me push the v2 patch? Thanks a lot. :-)

Thanks,
Xiao Yang

Quoted 60 lines · Xiao Yang

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

---
 doc/test-writing-guidelines.txt | 8 ++++++--
 lib/newlib_tests/test_exec.c    | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)
doc/test-writing-guidelines.txt +6 -2
index a169724..0b89cf9 100644
@@ -697,14 +697,18 @@ a non zero exit code.
 -------------------------------------------------------------------------------
 /* test.c */
 #define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
 
-	execvpe(argv[0], argv, environ);
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
+
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
lib/newlib_tests/test_exec.c +6 -2
index 8aef621..2c86568 100644
@@ -25,14 +25,18 @@
  */
 
 #define _GNU_SOURCE
-#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
 static void do_test(void)
 {
 	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
 
-	execvpe(argv[0], argv, environ);
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
+
+	execve(path, argv, environ);
 
 	tst_res(TBROK | TERRNO, "EXEC!");
 }
#9 lore raw

PATCH v2 1/1 newlib_tests/test_exec.c: Fix compiler error before glibc v2.11

In reply to Xiao Yang

Hi Xiao,

Quoted 5 lines

Before glibc v2.11, execvpe() was not introduced and resulted in compiler error, so we replace execvpe() with execve() and update test-writing-guidelines.txt.

Pushed, thanks!

Kind regards,
Petr