[LTP] [PATCH v3 1/7] Merge multiple pidfd*.h into one header
Yang Xu
xuyang2018.jy@fujitsu.com
Tue Feb 22 09:41:06 CET 2022
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
More information about the ltp
mailing list