1570af302Sopenharmony_ci#include <errno.h> 2570af302Sopenharmony_ci#include <pthread.h> 3570af302Sopenharmony_ci#include <stdio.h> 4570af302Sopenharmony_ci#include <unistd.h> 5570af302Sopenharmony_ci#include <sys/resource.h> 6570af302Sopenharmony_ci#include <sys/types.h> 7570af302Sopenharmony_ci#include <sys/wait.h> 8570af302Sopenharmony_ci#include "test.h" 9570af302Sopenharmony_ci 10570af302Sopenharmony_ci#define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0)) 11570af302Sopenharmony_ci 12570af302Sopenharmony_cistatic void handler_errno(void) 13570af302Sopenharmony_ci{ 14570af302Sopenharmony_ci errno = 0; 15570af302Sopenharmony_ci} 16570af302Sopenharmony_ci 17570af302Sopenharmony_ciint main(void) 18570af302Sopenharmony_ci{ 19570af302Sopenharmony_ci t_setrlim(RLIMIT_NPROC, 0); 20570af302Sopenharmony_ci pthread_atfork(handler_errno, handler_errno, handler_errno); 21570af302Sopenharmony_ci 22570af302Sopenharmony_ci pid_t pid; 23570af302Sopenharmony_ci if (!TEST((pid = fork()) == -1, "fork succeeded despite rlimit\n")) { 24570af302Sopenharmony_ci if (!pid) _exit(0); 25570af302Sopenharmony_ci while (waitpid(pid, NULL, 0)<0 && errno==EINTR); 26570af302Sopenharmony_ci } else { 27570af302Sopenharmony_ci TEST(errno != 0, "fork failed but errno was clobbered\n"); 28570af302Sopenharmony_ci } 29570af302Sopenharmony_ci 30570af302Sopenharmony_ci return t_status; 31570af302Sopenharmony_ci} 32570af302Sopenharmony_ci 33