* [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header
@ 2022-02-22 8:41 Yang Xu
2022-02-22 8:41 ` [LTP] [PATCH v3 2/7] syscalls/pidfd_send_signal: Add docparse formatting Yang Xu
` (4 more replies)
0 siblings, 5 replies; 13+ messages in thread
From: Yang Xu @ 2022-02-22 8:41 UTC (permalink / raw)
To: ltp
Since pidfd_getfd.h/pidfd_send_signal.h/pidfd_open.h doesn't have own struct
definition, it only about syscall wrapper. Kernel also doesn't have the same
name headers.
So use pidfd.h instead of own header. It is also convenient to add the safe
macros or case uses multiple pidfd syscalls in the future.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/lapi/pidfd.h | 58 +++++++++++++++++++
include/lapi/pidfd_getfd.h | 26 ---------
include/lapi/pidfd_open.h | 28 ---------
include/lapi/pidfd_send_signal.h | 27 ---------
testcases/kernel/syscalls/clone3/clone301.c | 2 +-
.../kernel/syscalls/fanotify/fanotify21.c | 2 +-
.../kernel/syscalls/pidfd_open/pidfd_open01.c | 3 +-
.../kernel/syscalls/pidfd_open/pidfd_open02.c | 2 +-
.../kernel/syscalls/pidfd_open/pidfd_open03.c | 2 +-
.../kernel/syscalls/pidfd_open/pidfd_open04.c | 7 +--
.../pidfd_send_signal/pidfd_send_signal01.c | 3 +-
.../pidfd_send_signal/pidfd_send_signal02.c | 3 +-
.../pidfd_send_signal/pidfd_send_signal03.c | 3 +-
13 files changed, 70 insertions(+), 96 deletions(-)
create mode 100644 include/lapi/pidfd.h
delete mode 100644 include/lapi/pidfd_getfd.h
delete mode 100644 include/lapi/pidfd_open.h
delete mode 100644 include/lapi/pidfd_send_signal.h
diff --git a/include/lapi/pidfd.h b/include/lapi/pidfd.h
new file mode 100644
index 000000000..244d3acaf
--- /dev/null
+++ b/include/lapi/pidfd.h
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef LAPI_PIDFD_H__
+#define LAPI_PIDFD_H__
+
+#include <fcntl.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#ifndef PIDFD_NONBLOCK
+#define PIDFD_NONBLOCK O_NONBLOCK
+#endif
+
+static inline void pidfd_send_signal_supported(void)
+{
+ /* allow the tests to fail early */
+ tst_syscall(__NR_pidfd_send_signal);
+}
+
+#ifndef HAVE_PIDFD_SEND_SIGNAL
+static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
+ unsigned int flags)
+{
+ return tst_syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
+}
+#endif
+
+static inline void pidfd_open_supported(void)
+{
+ /* allow the tests to fail early */
+ tst_syscall(__NR_pidfd_open);
+}
+
+#ifndef HAVE_PIDFD_OPEN
+static inline int pidfd_open(pid_t pid, unsigned int flags)
+{
+ return tst_syscall(__NR_pidfd_open, pid, flags);
+}
+#endif
+
+static inline void pidfd_getfd_supported(void)
+{
+ /* allow the tests to fail early */
+ tst_syscall(__NR_pidfd_getfd);
+}
+
+#ifndef HAVE_PIDFD_GETFD
+static inline int pidfd_getfd(int pidfd, int targetfd, unsigned int flags)
+{
+ return tst_syscall(__NR_pidfd_getfd, pidfd, targetfd, flags);
+}
+#endif
+
+#endif /* LAPI_PIDFD_H__ */
diff --git a/include/lapi/pidfd_getfd.h b/include/lapi/pidfd_getfd.h
deleted file mode 100644
index c6778163d..000000000
--- a/include/lapi/pidfd_getfd.h
+++ /dev/null
@@ -1,26 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
- */
-
-#ifndef LAPI_PIDFD_GETFD_H__
-#define LAPI_PIDFD_GETFD_H__
-
-#include "config.h"
-#include "lapi/syscalls.h"
-
-static inline void pidfd_getfd_supported(void)
-{
- /* allow the tests to fail early */
- tst_syscall(__NR_pidfd_getfd);
-}
-
-#ifndef HAVE_PIDFD_GETFD
-static inline int pidfd_getfd(int pidfd, int targetfd, unsigned int flags)
-{
- return tst_syscall(__NR_pidfd_getfd, pidfd, targetfd, flags);
-}
-#endif
-
-#endif /* LAPI_PIDFD_GETFD_H__ */
diff --git a/include/lapi/pidfd_open.h b/include/lapi/pidfd_open.h
deleted file mode 100644
index 5cf10933e..000000000
--- a/include/lapi/pidfd_open.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2020 Linaro Limited. All rights reserved.
- * Author: Viresh Kumar <viresh.kumar@linaro.org>
- */
-
-#ifndef LAPI_PIDFD_OPEN_H__
-#define LAPI_PIDFD_OPEN_H__
-
-#include <sys/syscall.h>
-#include <sys/types.h>
-#include "lapi/syscalls.h"
-#include "config.h"
-
-static inline void pidfd_open_supported(void)
-{
- /* allow the tests to fail early */
- tst_syscall(__NR_pidfd_open);
-}
-
-#ifndef HAVE_PIDFD_OPEN
-static inline int pidfd_open(pid_t pid, unsigned int flags)
-{
- return tst_syscall(__NR_pidfd_open, pid, flags);
-}
-#endif
-
-#endif /* LAPI_PIDFD_OPEN_H__ */
diff --git a/include/lapi/pidfd_send_signal.h b/include/lapi/pidfd_send_signal.h
deleted file mode 100644
index 7426a91da..000000000
--- a/include/lapi/pidfd_send_signal.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2019 SUSE LLC
- * Author: Christian Amann <camann@suse.com>
- */
-
-#ifndef LAPI_PIDFD_SEND_SIGNAL_H__
-#define LAPI_PIDFD_SEND_SIGNAL_H__
-
-#include "tst_test.h"
-#include "lapi/syscalls.h"
-
-static inline void pidfd_send_signal_supported(void)
-{
- /* allow the tests to fail early */
- tst_syscall(__NR_pidfd_send_signal);
-}
-
-#ifndef HAVE_PIDFD_SEND_SIGNAL
-static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
- unsigned int flags)
-{
- return tst_syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
-}
-#endif /* HAVE_PIDFD_SEND_SIGNAL */
-
-#endif /* LAPI_PIDFD_SEND_SIGNAL_H__ */
diff --git a/testcases/kernel/syscalls/clone3/clone301.c b/testcases/kernel/syscalls/clone3/clone301.c
index 7ac4bb5a3..f7ef0b2d7 100644
--- a/testcases/kernel/syscalls/clone3/clone301.c
+++ b/testcases/kernel/syscalls/clone3/clone301.c
@@ -16,7 +16,7 @@
#include "tst_test.h"
#include "lapi/clone.h"
-#include "lapi/pidfd_send_signal.h"
+#include "lapi/pidfd.h"
#define CHILD_SIGNAL SIGUSR1
#define DATA 777
diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
index 6ae70c57e..bd6429ab5 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify21.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
@@ -23,7 +23,7 @@
#include <string.h>
#include "tst_test.h"
#include "tst_safe_stdio.h"
-#include "lapi/pidfd_open.h"
+#include "lapi/pidfd.h"
#ifdef HAVE_SYS_FANOTIFY_H
#include "fanotify.h"
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
index c0e88647f..6f1e95ba8 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
@@ -13,9 +13,8 @@
*/
#include <unistd.h>
-#include <fcntl.h>
#include "tst_test.h"
-#include "lapi/pidfd_open.h"
+#include "lapi/pidfd.h"
static void run(void)
{
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
index 93a61a51d..9d6c9321d 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
@@ -13,7 +13,7 @@
* - EINVAL flags is not valid
*/
#include "tst_test.h"
-#include "lapi/pidfd_open.h"
+#include "lapi/pidfd.h"
static pid_t expired_pid, my_pid, invalid_pid = -1;
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c
index 7c7c75cb1..16a8442f5 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c
@@ -15,7 +15,7 @@
#include <stdlib.h>
#include "tst_test.h"
-#include "lapi/pidfd_open.h"
+#include "lapi/pidfd.h"
static void run(void)
{
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
index e94bb20db..60080c0c8 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
@@ -12,15 +12,10 @@
*/
#include <unistd.h>
-#include <fcntl.h>
#include <sys/wait.h>
#include <stdlib.h>
#include "tst_test.h"
-#include "lapi/pidfd_open.h"
-
-#ifndef PIDFD_NONBLOCK
-#define PIDFD_NONBLOCK O_NONBLOCK
-#endif
+#include "lapi/pidfd.h"
#ifndef P_PIDFD
#define P_PIDFD 3
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
index 4cb5df94c..3d201aa9d 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
@@ -12,7 +12,8 @@
#define _GNU_SOURCE
#include <signal.h>
#include <stdlib.h>
-#include "lapi/pidfd_send_signal.h"
+#include "tst_test.h"
+#include "lapi/pidfd.h"
#include "tst_safe_pthread.h"
#define SIGNAL SIGUSR1
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
index 1e62b417f..9600fc2f9 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
@@ -24,7 +24,8 @@
#define _GNU_SOURCE
#include <pwd.h>
#include <signal.h>
-#include "lapi/pidfd_send_signal.h"
+#include "tst_test.h"
+#include "lapi/pidfd.h"
#include "tst_safe_pthread.h"
#define CORRECT_SIGNAL SIGUSR1
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
index 0903d6707..fb61516d7 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
@@ -19,7 +19,8 @@
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
-#include "lapi/pidfd_send_signal.h"
+#include "tst_test.h"
+#include "lapi/pidfd.h"
#include "tst_safe_pthread.h"
#define PIDTRIES 3
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3 2/7] syscalls/pidfd_send_signal: Add docparse formatting
2022-02-22 8:41 [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Yang Xu
@ 2022-02-22 8:41 ` Yang Xu
2022-02-23 13:25 ` Cyril Hrubis
2022-02-22 8:41 ` [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro Yang Xu
` (3 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2022-02-22 8:41 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../pidfd_send_signal/pidfd_send_signal01.c | 5 +++-
.../pidfd_send_signal/pidfd_send_signal02.c | 25 +++++++++----------
.../pidfd_send_signal/pidfd_send_signal03.c | 7 +++++-
3 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
index 3d201aa9d..471585025 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
@@ -3,7 +3,10 @@
* Copyright (c) 2019 SUSE LLC
* Author: Christian Amann <camann@suse.com>
*/
-/*
+
+/*\
+ * [Description]
+ *
* Tests if the pidfd_send_signal syscall behaves
* like rt_sigqueueinfo when a pointer to a siginfo_t
* struct is passed.
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
index 9600fc2f9..a3bf994f9 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
@@ -3,22 +3,21 @@
* Copyright (c) 2019 SUSE LLC
* Author: Christian Amann <camann@suse.com>
*/
-/*
+
+/*\
+ * [Description]
+ *
* Tests basic error handling of the pidfd_send_signal
* system call.
*
- * 1) Pass invalid flag value to syscall (value chosen
- * to be unlikely to collide with future extensions)
- * -> EINVAL
- * 2) Pass a file descriptor that is corresponding to a
- * regular file instead of a pid directory
- * -> EBADF
- * 3) Pass a signal that is different from the one used
- * to initialize the siginfo_t struct
- * -> EINVAL
- * 4) Try to send signal to other process (init) with
- * missing privileges
- * -> EPERM
+ * - EINVAL Pass invalid flag value to syscall (value chosen
+ * to be unlikely to collide with future extensions)
+ * - EBADF Pass a file descriptor that is corresponding to a
+ * regular file instead of a pid directory
+ * - EINVAL Pass a signal that is different from the one used
+ * to initialize the siginfo_t struct
+ * - EPERM Try to send signal to other process (init) with
+ * missing privileges
*/
#define _GNU_SOURCE
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
index fb61516d7..20d96b118 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
@@ -3,13 +3,18 @@
* Copyright (c) 2019 SUSE LLC
* Author: Christian Amann <camann@suse.com>
*/
-/*
+
+/*\
+ * [Description]
+ *
* This test checks if the pidfd_send_signal syscall wrongfully sends
* a signal to a new process which inherited the PID of the actual
* target process.
+ *
* In order to do so it is necessary to start a process with a pre-
* determined PID. This is accomplished by writing to the
* /proc/sys/kernel/ns_last_pid file.
+ *
* By utilizing this, this test forks two children with the same PID.
* It is then checked, if the syscall will send a signal to the second
* child using the pidfd of the first one.
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro
2022-02-22 8:41 [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Yang Xu
2022-02-22 8:41 ` [LTP] [PATCH v3 2/7] syscalls/pidfd_send_signal: Add docparse formatting Yang Xu
@ 2022-02-22 8:41 ` Yang Xu
2022-02-23 13:28 ` Cyril Hrubis
2022-02-22 8:41 ` [LTP] [PATCH v3 4/7] syscalls/fanotify21: Make use of SAFE_PIDFD_OPEN Yang Xu
` (2 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2022-02-22 8:41 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
include/tst_safe_pidfd.h | 19 +++++++++++++++++++
lib/tst_safe_pidfd.c | 28 ++++++++++++++++++++++++++++
2 files changed, 47 insertions(+)
create mode 100644 include/tst_safe_pidfd.h
create mode 100644 lib/tst_safe_pidfd.c
diff --git a/include/tst_safe_pidfd.h b/include/tst_safe_pidfd.h
new file mode 100644
index 000000000..5c37099bd
--- /dev/null
+++ b/include/tst_safe_pidfd.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef TST_SAFE_PIDFD_H__
+#define TST_SAFE_PIDFD_H__
+
+#include <unistd.h>
+#include "lapi/pidfd.h"
+
+int safe_pidfd_open(const char *file, const int lineno, pid_t pid,
+ unsigned int flags);
+
+#define SAFE_PIDFD_OPEN(pid, flags) \
+ safe_pidfd_open(__FILE__, __LINE__, (pid), (flags))
+
+#endif /* TST_SAFE_PIDFD_H__ */
diff --git a/lib/tst_safe_pidfd.c b/lib/tst_safe_pidfd.c
new file mode 100644
index 000000000..c9fe5e1d0
--- /dev/null
+++ b/lib/tst_safe_pidfd.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_safe_pidfd.h"
+
+int safe_pidfd_open(const char *file, const int lineno, pid_t pid,
+ unsigned int flags)
+{
+ int rval;
+
+ rval = pidfd_open(pid, flags);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "pidfd_open(%i, %i) failed", pid, flags);
+ } else if (rval < 0) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid pidfd_open(%i, %i) return value %d",
+ pid, flags, rval);
+ }
+
+ return rval;
+}
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3 4/7] syscalls/fanotify21: Make use of SAFE_PIDFD_OPEN
2022-02-22 8:41 [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Yang Xu
2022-02-22 8:41 ` [LTP] [PATCH v3 2/7] syscalls/pidfd_send_signal: Add docparse formatting Yang Xu
2022-02-22 8:41 ` [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro Yang Xu
@ 2022-02-22 8:41 ` Yang Xu
2022-02-23 13:29 ` Cyril Hrubis
2022-02-22 8:41 ` [LTP] [PATCH v3 5/7] syscalls/pidfd_open01, 04: Make use of SAFE_FCNTL Yang Xu
2022-02-23 13:22 ` [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Cyril Hrubis
4 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2022-02-22 8:41 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
testcases/kernel/syscalls/fanotify/fanotify21.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
index bd6429ab5..d5be3e270 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify21.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
@@ -23,7 +23,7 @@
#include <string.h>
#include "tst_test.h"
#include "tst_safe_stdio.h"
-#include "lapi/pidfd.h"
+#include "tst_safe_pidfd.h"
#ifdef HAVE_SYS_FANOTIFY_H
#include "fanotify.h"
@@ -124,12 +124,7 @@ static void do_setup(void)
SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD, FAN_OPEN, AT_FDCWD,
TEST_FILE);
- pidfd = pidfd_open(getpid(), 0);
- if (pidfd < 0) {
- tst_brk(TBROK | TERRNO,
- "pidfd=%d, pidfd_open(%d, 0) failed",
- pidfd, getpid());
- }
+ pidfd = SAFE_PIDFD_OPEN(getpid(), 0);
self_pidfd_fdinfo = read_pidfd_fdinfo(pidfd);
if (self_pidfd_fdinfo == NULL) {
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [LTP] [PATCH v3 5/7] syscalls/pidfd_open01, 04: Make use of SAFE_FCNTL
2022-02-22 8:41 [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Yang Xu
` (2 preceding siblings ...)
2022-02-22 8:41 ` [LTP] [PATCH v3 4/7] syscalls/fanotify21: Make use of SAFE_PIDFD_OPEN Yang Xu
@ 2022-02-22 8:41 ` Yang Xu
2022-02-23 13:34 ` Cyril Hrubis
2022-02-23 13:22 ` [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Cyril Hrubis
4 siblings, 1 reply; 13+ messages in thread
From: Yang Xu @ 2022-02-22 8:41 UTC (permalink / raw)
To: ltp
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../kernel/syscalls/pidfd_open/pidfd_open01.c | 17 ++++++++++++-----
.../kernel/syscalls/pidfd_open/pidfd_open04.c | 15 +++++++++++----
2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
index 6f1e95ba8..ce07e6717 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
@@ -16,18 +16,18 @@
#include "tst_test.h"
#include "lapi/pidfd.h"
+static int pidfd = -1;
+
static void run(void)
{
int flag;
TST_EXP_FD_SILENT(pidfd_open(getpid(), 0), "pidfd_open(getpid(), 0)");
- flag = fcntl(TST_RET, F_GETFD);
-
- SAFE_CLOSE(TST_RET);
+ pidfd = TST_RET;
+ flag = SAFE_FCNTL(pidfd, F_GETFD);
- if (flag == -1)
- tst_brk(TFAIL | TERRNO, "fcntl(F_GETFD) failed");
+ SAFE_CLOSE(pidfd);
if (!(flag & FD_CLOEXEC))
tst_brk(TFAIL, "pidfd_open(getpid(), 0) didn't set close-on-exec flag");
@@ -35,7 +35,14 @@ static void run(void)
tst_res(TPASS, "pidfd_open(getpid(), 0) passed");
}
+static void cleanup(void)
+{
+ if (pidfd > -1)
+ SAFE_CLOSE(pidfd);
+}
+
static struct tst_test test = {
.setup = pidfd_open_supported,
+ .cleanup = cleanup,
.test_all = run,
};
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
index 60080c0c8..0e8ab6956 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
@@ -21,9 +21,11 @@
#define P_PIDFD 3
#endif
+static int pidfd = -1;
+
static void run(void)
{
- int flag, pid, pidfd, ret;
+ int flag, pid, ret;
siginfo_t info;
pid = SAFE_FORK();
@@ -36,9 +38,7 @@ static void run(void)
"pidfd_open(%d, PIDFD_NONBLOCK)", pid);
pidfd = TST_RET;
- flag = fcntl(pidfd, F_GETFL);
- if (flag == -1)
- tst_brk(TFAIL | TERRNO, "fcntl(F_GETFL) failed");
+ flag = SAFE_FCNTL(pidfd, F_GETFL);
if (!(flag & O_NONBLOCK))
tst_brk(TFAIL, "pidfd_open(%d, O_NONBLOCK) didn't set O_NONBLOCK flag", pid);
@@ -77,10 +77,17 @@ static void setup(void)
SAFE_CLOSE(TST_RET);
}
+static void cleanup(void)
+{
+ if (pidfd > -1)
+ SAFE_CLOSE(pidfd);
+}
+
static struct tst_test test = {
.needs_root = 1,
.forks_child = 1,
.needs_checkpoints = 1,
.setup = setup,
+ .cleanup = cleanup,
.test_all = run,
};
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header
2022-02-22 8:41 [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Yang Xu
` (3 preceding siblings ...)
2022-02-22 8:41 ` [LTP] [PATCH v3 5/7] syscalls/pidfd_open01, 04: Make use of SAFE_FCNTL Yang Xu
@ 2022-02-23 13:22 ` Cyril Hrubis
4 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-02-23 13:22 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
Nice cleanup.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 2/7] syscalls/pidfd_send_signal: Add docparse formatting
2022-02-22 8:41 ` [LTP] [PATCH v3 2/7] syscalls/pidfd_send_signal: Add docparse formatting Yang Xu
@ 2022-02-23 13:25 ` Cyril Hrubis
0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-02-23 13:25 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro
2022-02-22 8:41 ` [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro Yang Xu
@ 2022-02-23 13:28 ` Cyril Hrubis
2022-02-24 7:23 ` xuyang2018.jy
0 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2022-02-23 13:28 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
> + */
> +
> +#ifndef TST_SAFE_PIDFD_H__
> +#define TST_SAFE_PIDFD_H__
> +
> +#include <unistd.h>
> +#include "lapi/pidfd.h"
> +
> +int safe_pidfd_open(const char *file, const int lineno, pid_t pid,
> + unsigned int flags);
> +
> +#define SAFE_PIDFD_OPEN(pid, flags) \
> + safe_pidfd_open(__FILE__, __LINE__, (pid), (flags))
Is there a reason why we start a new header instead of adding this into
the tst_safe_macros.h?
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 4/7] syscalls/fanotify21: Make use of SAFE_PIDFD_OPEN
2022-02-22 8:41 ` [LTP] [PATCH v3 4/7] syscalls/fanotify21: Make use of SAFE_PIDFD_OPEN Yang Xu
@ 2022-02-23 13:29 ` Cyril Hrubis
0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-02-23 13:29 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 5/7] syscalls/pidfd_open01, 04: Make use of SAFE_FCNTL
2022-02-22 8:41 ` [LTP] [PATCH v3 5/7] syscalls/pidfd_open01, 04: Make use of SAFE_FCNTL Yang Xu
@ 2022-02-23 13:34 ` Cyril Hrubis
0 siblings, 0 replies; 13+ messages in thread
From: Cyril Hrubis @ 2022-02-23 13:34 UTC (permalink / raw)
To: Yang Xu; +Cc: ltp
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro
2022-02-23 13:28 ` Cyril Hrubis
@ 2022-02-24 7:23 ` xuyang2018.jy
2022-02-25 15:59 ` Cyril Hrubis
0 siblings, 1 reply; 13+ messages in thread
From: xuyang2018.jy @ 2022-02-24 7:23 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp@lists.linux.it
Hi Cyril
> Hi!
>> +// SPDX-License-Identifier: GPL-2.0-or-later
>> +/*
>> + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
>> + * Author: Yang Xu<xuyang2018.jy@fujitsu.com>
>> + */
>> +
>> +#ifndef TST_SAFE_PIDFD_H__
>> +#define TST_SAFE_PIDFD_H__
>> +
>> +#include<unistd.h>
>> +#include "lapi/pidfd.h"
>> +
>> +int safe_pidfd_open(const char *file, const int lineno, pid_t pid,
>> + unsigned int flags);
>> +
>> +#define SAFE_PIDFD_OPEN(pid, flags) \
>> + safe_pidfd_open(__FILE__, __LINE__, (pid), (flags))
>
> Is there a reason why we start a new header instead of adding this into
> the tst_safe_macros.h?
Just avoid a big tst_safe_macros.h like tst_safe_sysv_ipc.h does.
Also the pidfd related syscalls seems no libc wrapper.
Based on the above two points, I started a new header. Also if you want
to merge it into tst_safe_macros.h, I will do(I don't have objection to
add this into tst_safe_macros.h ).
Best Regards
Yang Xu
>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro
2022-02-24 7:23 ` xuyang2018.jy
@ 2022-02-25 15:59 ` Cyril Hrubis
2022-03-01 5:59 ` xuyang2018.jy
0 siblings, 1 reply; 13+ messages in thread
From: Cyril Hrubis @ 2022-02-25 15:59 UTC (permalink / raw)
To: xuyang2018.jy@fujitsu.com; +Cc: ltp@lists.linux.it
Hi!
> Just avoid a big tst_safe_macros.h like tst_safe_sysv_ipc.h does.
> Also the pidfd related syscalls seems no libc wrapper.
>
> Based on the above two points, I started a new header. Also if you want
> to merge it into tst_safe_macros.h, I will do(I don't have objection to
> add this into tst_safe_macros.h ).
I would have just added the definitions to the tst_safe_macros.h, but
it's not a big deal.
Otherwise the actuall code looks good, with the header merged to tst_safe_macros.h:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro
2022-02-25 15:59 ` Cyril Hrubis
@ 2022-03-01 5:59 ` xuyang2018.jy
0 siblings, 0 replies; 13+ messages in thread
From: xuyang2018.jy @ 2022-03-01 5:59 UTC (permalink / raw)
To: Cyril Hrubis, Petr Vorel; +Cc: ltp@lists.linux.it
Hi Cyril,Petr
I merged this patchset, thanks for your review.
Best Regards
Yang Xu
> Hi!
>> Just avoid a big tst_safe_macros.h like tst_safe_sysv_ipc.h does.
>> Also the pidfd related syscalls seems no libc wrapper.
>>
>> Based on the above two points, I started a new header. Also if you want
>> to merge it into tst_safe_macros.h, I will do(I don't have objection to
>> add this into tst_safe_macros.h ).
>
> I would have just added the definitions to the tst_safe_macros.h, but
> it's not a big deal.
>
> Otherwise the actuall code looks good, with the header merged to tst_safe_macros.h:
>
> Reviewed-by: Cyril Hrubis<chrubis@suse.cz>
>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-03-01 5:59 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-22 8:41 [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Yang Xu
2022-02-22 8:41 ` [LTP] [PATCH v3 2/7] syscalls/pidfd_send_signal: Add docparse formatting Yang Xu
2022-02-23 13:25 ` Cyril Hrubis
2022-02-22 8:41 ` [LTP] [PATCH v3 3/7] lib/tst_safe_pidfd: Add SAFE_PIDFD_OPEN macro Yang Xu
2022-02-23 13:28 ` Cyril Hrubis
2022-02-24 7:23 ` xuyang2018.jy
2022-02-25 15:59 ` Cyril Hrubis
2022-03-01 5:59 ` xuyang2018.jy
2022-02-22 8:41 ` [LTP] [PATCH v3 4/7] syscalls/fanotify21: Make use of SAFE_PIDFD_OPEN Yang Xu
2022-02-23 13:29 ` Cyril Hrubis
2022-02-22 8:41 ` [LTP] [PATCH v3 5/7] syscalls/pidfd_open01, 04: Make use of SAFE_FCNTL Yang Xu
2022-02-23 13:34 ` Cyril Hrubis
2022-02-23 13:22 ` [LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header Cyril Hrubis
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).