functional: add mntent test
[libc-test.git] / src / regression / pthread_atfork-errno-clobber.c
blobab3b3787855f8b3d1d3b0be8549faac79e724489
1 #include <errno.h>
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/resource.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
8 #include "test.h"
10 #define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
12 static void handler_errno(void)
14 errno = 0;
17 int main(void)
19 t_setrlim(RLIMIT_NPROC, 0);
20 pthread_atfork(handler_errno, handler_errno, handler_errno);
22 pid_t pid;
23 if (!TEST((pid = fork()) == -1, "fork succeeded despite rlimit\n")) {
24 if (!pid) _exit(0);
25 while (waitpid(pid, NULL, 0)<0 && errno==EINTR);
26 } else {
27 TEST(errno != 0, "fork failed but errno was clobbered\n");
30 return t_status;