• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 
10 #define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
11 
handler_errno(void)12 static void handler_errno(void)
13 {
14 	errno = 0;
15 }
16 
main(void)17 int main(void)
18 {
19 	t_setrlim(RLIMIT_NPROC, 0);
20 	pthread_atfork(handler_errno, handler_errno, handler_errno);
21 
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");
28 	}
29 
30 	return t_status;
31 }
32 
33