Blame src/regression/pthread_atfork-errno-clobber.c

Bobby Bingham 735f0c
#include <errno.h>
Bobby Bingham 735f0c
#include <pthread.h>
Bobby Bingham 735f0c
#include <stdio.h>
Bobby Bingham 735f0c
#include <unistd.h>
Bobby Bingham 735f0c
#include <sys/resource.h>
Bobby Bingham 735f0c
#include <sys/types.h>
Bobby Bingham 735f0c
#include <sys/wait.h>
Bobby Bingham 735f0c
#include "test.h"
Bobby Bingham 735f0c
Bobby Bingham 735f0c
#define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
Bobby Bingham 735f0c
Bobby Bingham 735f0c
static void handler_errno(void)
Bobby Bingham 735f0c
{
Bobby Bingham 735f0c
	errno = 0;
Bobby Bingham 735f0c
}
Bobby Bingham 735f0c
Bobby Bingham 735f0c
int main(void)
Bobby Bingham 735f0c
{
Bobby Bingham 735f0c
	t_setrlim(RLIMIT_NPROC, 0);
Bobby Bingham 735f0c
	pthread_atfork(handler_errno, handler_errno, handler_errno);
Bobby Bingham 735f0c
Bobby Bingham 735f0c
	pid_t pid;
Bobby Bingham 735f0c
	if (!TEST((pid = fork()) == -1, "fork succeeded despite rlimit\n")) {
Bobby Bingham 735f0c
		if (!pid) _exit(0);
Bobby Bingham 735f0c
		while (waitpid(pid, NULL, 0)<0 && errno==EINTR);
Bobby Bingham 735f0c
	} else {
Bobby Bingham 735f0c
		TEST(errno != 0, "fork failed but errno was clobbered\n");
Bobby Bingham 735f0c
	}
Bobby Bingham 735f0c
Bobby Bingham 735f0c
	return t_status;
Bobby Bingham 735f0c
}
Bobby Bingham 735f0c