Skip to contentSkip to conversation

syscalls/execveat03: Fix compiler errors

PATCH New Xiao Yang 2 participants 5 messages Aug 20, 2018 – Aug 22, 2018

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/1 syscalls/execveat03: Fix compiler errors

According to open(2) and linkat(2) manpages, O_PATH and AT_EMPTY_PATH flags were added since kernel v2.6.39, so these undefined flags led to the following errors on older kernels(e.g. v2.6.32):
---------------------------------------------------------
execveat03.c:66: error: ‘O_PATH’ undeclared (first use in this function) execveat03.c:69: error: ‘AT_EMPTY_PATH’ undeclared (first use in this function)
---------------------------------------------------------

1) Add AT_EMPTY_PATH into lapi/fcntl.h
2) Include lapi/fcntl.h in execveat03.c
3) Check if open(2) supports O_PATH

---
 include/lapi/fcntl.h                            |  4 ++++
 testcases/kernel/syscalls/execveat/execveat03.c | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
include/lapi/fcntl.h +4 -0
index 849439d..358230f 100644
@@ -103,6 +103,10 @@
 # define AT_SYMLINK_NOFOLLOW 0x100
 #endif
 
+#ifndef AT_EMPTY_PATH
+# define AT_EMPTY_PATH 0x1000
+#endif
+
 #ifndef AT_REMOVEDIR
 # define AT_REMOVEDIR 0x200
 #endif
testcases/kernel/syscalls/execveat/execveat03.c +9 -1
index df27273..701784e 100644
@@ -49,6 +49,7 @@
 #include <fcntl.h>
 #include "tst_test.h"
 #include "lapi/execveat.h"
+#include "lapi/fcntl.h"
 
 #define OVL_MNT "ovl"
 #define TEST_APP "execveat_child"
@@ -63,7 +64,14 @@ static void do_child(void)
 
 	SAFE_CP(TEST_APP, TEST_FILE_PATH);
 
-	fd = SAFE_OPEN(TEST_FILE_PATH, O_PATH);
+	fd = open(TEST_FILE_PATH, O_PATH);
+	if (fd == -1) {
+		if (errno == EINVAL)
+			tst_brk(TCONF, "open() did not support O_PATH");
+		else
+			tst_brk(TBROK, "open() failed");
+	}
+
 	SAFE_UNLINK(TEST_FILE_PATH);
 
 	TEST(execveat(fd, "", argv, environ, AT_EMPTY_PATH));
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 syscalls/execveat03: Fix compiler errors

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

Quoted 11 lines

According to open(2) and linkat(2) manpages, O_PATH and AT_EMPTY_PATH flags were added since kernel v2.6.39, so these undefined flags led to the following errors on older kernels(e.g. v2.6.32):
---------------------------------------------------------
execveat03.c:66: error: ‘O_PATH’ undeclared (first use in this function) execveat03.c:69: error: ‘AT_EMPTY_PATH’ undeclared (first use in this function)
---------------------------------------------------------

1) Add AT_EMPTY_PATH into lapi/fcntl.h
2) Include lapi/fcntl.h in execveat03.c

Agreed with 1 and 2.

Quoted 1 line

3) Check if open(2) supports O_PATH

Do we need to worry about this one? execveat() has been introduced [1] around v3.19. Those kernels should already support O_PATH.

[1] 51f39a1f0cea ("syscalls: implement execveat() system call")

Quoted 60 lines
---
 include/lapi/fcntl.h                            |  4 ++++
 testcases/kernel/syscalls/execveat/execveat03.c | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
include/lapi/fcntl.h +4 -0
index 849439d..358230f 100644
@@ -103,6 +103,10 @@
 # define AT_SYMLINK_NOFOLLOW 0x100
 #endif
 
+#ifndef AT_EMPTY_PATH
+# define AT_EMPTY_PATH 0x1000
+#endif
+
 #ifndef AT_REMOVEDIR
 # define AT_REMOVEDIR 0x200
 #endif
testcases/kernel/syscalls/execveat/execveat03.c +9 -2
index df27273..701784e 100644
@@ -49,6 +49,7 @@
 #include <fcntl.h>
 #include "tst_test.h"
 #include "lapi/execveat.h"
+#include "lapi/fcntl.h"
 
 #define OVL_MNT "ovl"
 #define TEST_APP "execveat_child"
@@ -63,7 +64,14 @@ static void do_child(void)
 
 	SAFE_CP(TEST_APP, TEST_FILE_PATH);
 
-	fd = SAFE_OPEN(TEST_FILE_PATH, O_PATH);
+	fd = open(TEST_FILE_PATH, O_PATH);
+	if (fd == -1) {
+		if (errno == EINVAL)
+			tst_brk(TCONF, "open() did not support O_PATH");
+		else
+			tst_brk(TBROK, "open() failed");
+	}
+
 	SAFE_UNLINK(TEST_FILE_PATH);
 
 	TEST(execveat(fd, "", argv, environ, AT_EMPTY_PATH));
--

1.8.3.1

--
Mailing list info: https://lists.linux.it/listinfo/ltp

author
#2 lore raw

PATCH 1/1 syscalls/execveat03: Fix compiler errors

Quoted 13 lines · Jan Stancek

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

Quoted 11 lines

According to open(2) and linkat(2) manpages, O_PATH and AT_EMPTY_PATH flags were added since kernel v2.6.39, so these undefined flags led to the following errors on older kernels(e.g. v2.6.32):
---------------------------------------------------------
execveat03.c:66: error: ‘O_PATH’ undeclared (first use in this function) execveat03.c:69: error: ‘AT_EMPTY_PATH’ undeclared (first use in this function)
---------------------------------------------------------

1) Add AT_EMPTY_PATH into lapi/fcntl.h
2) Include lapi/fcntl.h in execveat03.c

Quoted 7 lines

Agreed with 1 and 2.

Quoted 1 line

3) Check if open(2) supports O_PATH

Do we need to worry about this one? execveat() has been introduced [1] around v3.19. Those kernels should already support O_PATH.

[1] 51f39a1f0cea ("syscalls: implement execveat() system call")

Hi Jan,

Thanks for your review.
It is reasonable to drop this check as you explained.

Thanks,
Xiao Yang

Quoted 62 lines
Quoted 56 lines
---
  include/lapi/fcntl.h                            |  4 ++++
  testcases/kernel/syscalls/execveat/execveat03.c | 10 +++++++++-
  2 files changed, 13 insertions(+), 1 deletion(-)
include/lapi/fcntl.h +4 -0
index 849439d..358230f 100644
@@ -103,6 +103,10 @@
  # define AT_SYMLINK_NOFOLLOW 0x100
  #endif
 
+#ifndef AT_EMPTY_PATH
+# define AT_EMPTY_PATH 0x1000
+#endif
+
  #ifndef AT_REMOVEDIR
  # define AT_REMOVEDIR 0x200
  #endif
testcases/kernel/syscalls/execveat/execveat03.c +9 -2
index df27273..701784e 100644
@@ -49,6 +49,7 @@
  #include<fcntl.h>
  #include "tst_test.h"
  #include "lapi/execveat.h"
+#include "lapi/fcntl.h"
 
  #define OVL_MNT "ovl"
  #define TEST_APP "execveat_child"
@@ -63,7 +64,14 @@ static void do_child(void)
 
  	SAFE_CP(TEST_APP, TEST_FILE_PATH);
 
-	fd = SAFE_OPEN(TEST_FILE_PATH, O_PATH);
+	fd = open(TEST_FILE_PATH, O_PATH);
+	if (fd == -1) {
+		if (errno == EINVAL)
+			tst_brk(TCONF, "open() did not support O_PATH");
+		else
+			tst_brk(TBROK, "open() failed");
+	}
+
  	SAFE_UNLINK(TEST_FILE_PATH);
 
  	TEST(execveat(fd, "", argv, environ, AT_EMPTY_PATH));
--

1.8.3.1

Quoted 3 lines

--
Mailing list info: https://lists.linux.it/listinfo/ltp

.

author
#3 lore raw

PATCH v2 1/1 syscalls/execveat03: Fix compiler errors

In reply to Jan Stancek

According to open(2) and linkat(2) manpages, O_PATH and AT_EMPTY_PATH flags were added since kernel v2.6.39, so these undefined flags led to the following errors on older kernels(e.g. v2.6.32):
---------------------------------------------------------
execveat03.c:66: error: ‘O_PATH’ undeclared (first use in this function) execveat03.c:69: error: ‘AT_EMPTY_PATH’ undeclared (first use in this function)
---------------------------------------------------------

1) Add AT_EMPTY_PATH into lapi/fcntl.h
2) Include lapi/fcntl.h in execveat03.c

---
 include/lapi/fcntl.h                            | 4 ++++
 testcases/kernel/syscalls/execveat/execveat03.c | 1 +
 2 files changed, 5 insertions(+)
include/lapi/fcntl.h +4 -0
index 849439d..358230f 100644
@@ -103,6 +103,10 @@
 # define AT_SYMLINK_NOFOLLOW 0x100
 #endif
 
+#ifndef AT_EMPTY_PATH
+# define AT_EMPTY_PATH 0x1000
+#endif
+
 #ifndef AT_REMOVEDIR
 # define AT_REMOVEDIR 0x200
 #endif
testcases/kernel/syscalls/execveat/execveat03.c +1 -0
index df27273..315620b 100644
@@ -49,6 +49,7 @@
 #include <fcntl.h>
 #include "tst_test.h"
 #include "lapi/execveat.h"
+#include "lapi/fcntl.h"
 
 #define OVL_MNT "ovl"
 #define TEST_APP "execveat_child"
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v2 1/1 syscalls/execveat03: Fix compiler errors

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

Quoted 9 lines

According to open(2) and linkat(2) manpages, O_PATH and AT_EMPTY_PATH flags were added since kernel v2.6.39, so these undefined flags led to the following errors on older kernels(e.g. v2.6.32):
---------------------------------------------------------
execveat03.c:66: error: ‘O_PATH’ undeclared (first use in this function) execveat03.c:69: error: ‘AT_EMPTY_PATH’ undeclared (first use in this function)
---------------------------------------------------------

Quoted 4 lines

1) Add AT_EMPTY_PATH into lapi/fcntl.h
2) Include lapi/fcntl.h in execveat03.c

Pushed.

We could add also minimum kernel version check, but since test is using ltp_syscall(), it handles ENOSYS. I'll leave it as it is for now.

Thanks,
Jan