From 6981ec9f0a6a3a13803216838271afad51a59018 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 11 Aug 2007 00:07:52 +0000 Subject: [PATCH] Test to verify that the runtime loader semaphore is not initialized after fork(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21885 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/system/libroot/posix/Jamfile | 12 ++++-- .../posix/init_rld_after_fork_test.cpp | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 src/tests/system/libroot/posix/init_rld_after_fork_test.cpp diff --git a/src/tests/system/libroot/posix/Jamfile b/src/tests/system/libroot/posix/Jamfile index 01aae3abc7..4fc453e9bd 100644 --- a/src/tests/system/libroot/posix/Jamfile +++ b/src/tests/system/libroot/posix/Jamfile @@ -4,19 +4,23 @@ UsePrivateHeaders syslog_daemon ; SimpleTest SyslogTest : SyslogTest.cpp syslog.cpp - ; +; SimpleTest flock_test : flock_test.cpp - ; +; SimpleTest setjmp_test : setjmp_test.c - ; +; SimpleTest sigsetjmp_test : sigsetjmp_test.c - ; +; + +SimpleTest init_rld_after_fork_test + : init_rld_after_fork_test.cpp +; # Tell Jam where to find these sources SEARCH on [ FGristFiles diff --git a/src/tests/system/libroot/posix/init_rld_after_fork_test.cpp b/src/tests/system/libroot/posix/init_rld_after_fork_test.cpp new file mode 100644 index 0000000000..9ddf947235 --- /dev/null +++ b/src/tests/system/libroot/posix/init_rld_after_fork_test.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#include + + +static void +list_semaphores(const char* process) +{ + printf("%s (%ld) semaphores:\n", process, find_thread(NULL)); + + sem_info semInfo; + int32 cookie = 0; + while (get_next_sem_info(B_CURRENT_TEAM, &cookie, &semInfo) == B_OK) + printf(" %9ld %s\n", semInfo.sem, semInfo.name); +} + + +int +main() +{ + pid_t child = fork(); + if (child < 0) { + fprintf(stderr, "Error: fork() failed: %s\n", strerror(errno)); + exit(1); + } + + if (child > 0) { + // the parent process -- wait for the child to finish + status_t result; + wait_for_thread(child, &result); + } + + list_semaphores(child == 0 ? "child" : "parent"); + + return 0; +} \ No newline at end of file