@@ -106,6 +106,12 @@ pid_t safe_fork(const char *filename, unsigned int lineno);
*/
void tst_reap_children(void);
+/*
+ * Wait for one child and exit with TBROK if it returns a non-zero
+ * exit status
+ */
+void tst_reap_child(pid_t child);
+
struct tst_option {
char *optstr;
char **arg;
@@ -416,6 +416,28 @@ void tst_reap_children(void)
}
}
+void tst_reap_child(const pid_t pid)
+{
+ int status;
+
+ for (;;) {
+ const pid_t ret_pid = waitpid(pid, &status, 0);
+
+ if (ret_pid > 0) {
+ check_child_status(ret_pid, status);
+ continue;
+ }
+
+ if (errno == ECHILD)
+ break;
+
+ if (errno == EINTR)
+ continue;
+
+ tst_brk(TBROK | TERRNO, "waitpid(%d, ...) failed", pid);
+ }
+}
+
pid_t safe_fork(const char *filename, unsigned int lineno)
{
Add a simple way to wait for a specific child process. This makes sense when you want to wait for a child while others continue to run in the background. Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- include/tst_test.h | 6 ++++++ lib/tst_test.c | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+)