|  | @@ -26,6 +26,7 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #include <assert.h>
 | 
	
		
			
				|  |  |  #include <errno.h>
 | 
	
		
			
				|  |  | +#include <fcntl.h>
 | 
	
		
			
				|  |  |  #include <limits.h>
 | 
	
		
			
				|  |  |  #include <poll.h>
 | 
	
		
			
				|  |  |  #include <pthread.h>
 | 
	
	
		
			
				|  | @@ -84,11 +85,32 @@ typedef struct epoll_set {
 | 
	
		
			
				|  |  |  /* The global singleton epoll set */
 | 
	
		
			
				|  |  |  static epoll_set g_epoll_set;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +static int epoll_create_and_set_flag() {
 | 
	
		
			
				|  |  | +#ifdef GRPC_LINUX_EPOLL_CREATE1
 | 
	
		
			
				|  |  | +  int fd = epoll_create1(EPOLL_CLOEXEC);
 | 
	
		
			
				|  |  | +  if (fd >= 0) {
 | 
	
		
			
				|  |  | +    return fd;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  gpr_log(GPR_ERROR, "epoll_create1 unavailable");
 | 
	
		
			
				|  |  | +  return -1;
 | 
	
		
			
				|  |  | +#else
 | 
	
		
			
				|  |  | +  int fd = epoll_create(MAX_EPOLL_EVENTS);
 | 
	
		
			
				|  |  | +  if (fd < 0) {
 | 
	
		
			
				|  |  | +    gpr_log(GPR_ERROR, "epoll_create unavailable");
 | 
	
		
			
				|  |  | +    return -1;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  if (fcntl(fd, F_SETFD, FD_CLOEXEC) == 0) {
 | 
	
		
			
				|  |  | +    return fd;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  gpr_log(GPR_ERROR, "fcntl following epoll_create failed");
 | 
	
		
			
				|  |  | +  return -1;
 | 
	
		
			
				|  |  | +#endif
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  /* Must be called *only* once */
 | 
	
		
			
				|  |  |  static bool epoll_set_init() {
 | 
	
		
			
				|  |  | -  g_epoll_set.epfd = epoll_create1(EPOLL_CLOEXEC);
 | 
	
		
			
				|  |  | +  g_epoll_set.epfd = epoll_create_and_set_flag();
 | 
	
		
			
				|  |  |    if (g_epoll_set.epfd < 0) {
 | 
	
		
			
				|  |  | -    gpr_log(GPR_ERROR, "epoll unavailable");
 | 
	
		
			
				|  |  |      return false;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 |