From 735f0ce7e431c588840f6fb832b12f6b64d7b378 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Fri, 10 Nov 2017 14:59:18 -0600 Subject: [PATCH] pthread_atfork/fork regression test --- src/regression/pthread_atfork-errno-clobber.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/regression/pthread_atfork-errno-clobber.c diff --git a/src/regression/pthread_atfork-errno-clobber.c b/src/regression/pthread_atfork-errno-clobber.c new file mode 100644 index 0000000..ab3b378 --- /dev/null +++ b/src/regression/pthread_atfork-errno-clobber.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include +#include +#include "test.h" + +#define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0)) + +static void handler_errno(void) +{ + errno = 0; +} + +int main(void) +{ + t_setrlim(RLIMIT_NPROC, 0); + pthread_atfork(handler_errno, handler_errno, handler_errno); + + pid_t pid; + if (!TEST((pid = fork()) == -1, "fork succeeded despite rlimit\n")) { + if (!pid) _exit(0); + while (waitpid(pid, NULL, 0)<0 && errno==EINTR); + } else { + TEST(errno != 0, "fork failed but errno was clobbered\n"); + } + + return t_status; +} + -- 2.20.1