From ac6fb528227052a990013764c3754a2c778e2f49 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 30 Aug 2024 23:48:44 +0200 Subject: [PATCH] posix_openpt tests: Fix test failure on Haiku. * tests/test-posix_openpt.c (main): On Haiku, create a child process and call setsid(). --- ChangeLog | 6 ++++++ tests/test-posix_openpt.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index d1b9ea73d8..737b3dc490 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2024-08-30 Bruno Haible + + posix_openpt tests: Fix test failure on Haiku. + * tests/test-posix_openpt.c (main): On Haiku, create a child process and + call setsid(). + 2024-08-30 Bruno Haible Trivial relicensing of macro-only modules, part 3. diff --git a/tests/test-posix_openpt.c b/tests/test-posix_openpt.c index 95d69cd7ae..fdca5820d9 100644 --- a/tests/test-posix_openpt.c +++ b/tests/test-posix_openpt.c @@ -54,6 +54,29 @@ main (void) ASSERT (name); ASSERT (grantpt (master) == 0); ASSERT (unlockpt (master) == 0); + +#if defined __HAIKU__ + /* On Haiku, the open() call below succeeds only if + - done in a child process, and + - if that child process has done a setsid() call. + So, do that. */ + pid_t child_pid = fork (); + ASSERT (child_pid >= 0); + if (child_pid > 0) + { + /* We are in the parent. Wait for the child to terminate. */ + int child_status; + ASSERT (waitpid (child_pid, &child_status, 0) != -1); + ASSERT (WIFEXITED (child_status)); + int child_exit_status = WEXITSTATUS (child_status); + ASSERT (child_exit_status == 0); + + return test_exit_status; + } + /* We are in the child. */ + ASSERT (setsid () >= 0); +#endif + slave = open (name, O_RDWR); ASSERT (0 <= slave); -- 2.39.5