mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	os: define SOCK_CLOEXEC on Linux
If it's not already defined, and we are on Linux, #define it. This gets rid of a load of #ifdefs. This should also allow to use it when the kernel supports it, but the libc does not define it. Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This commit is contained in:
		
							parent
							
								
									1f827a4776
								
							
						
					
					
						commit
						3b29783dc8
					
				
					 3 changed files with 14 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -55,13 +55,11 @@ wl_os_socket_cloexec(int domain, int type, int protocol)
 | 
			
		|||
{
 | 
			
		||||
	int fd;
 | 
			
		||||
 | 
			
		||||
#ifdef SOCK_CLOEXEC
 | 
			
		||||
	fd = socket(domain, type | SOCK_CLOEXEC, protocol);
 | 
			
		||||
	if (fd >= 0)
 | 
			
		||||
		return fd;
 | 
			
		||||
	if (errno != EINVAL)
 | 
			
		||||
		return -1;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	fd = socket(domain, type, protocol);
 | 
			
		||||
	return set_cloexec_or_close(fd);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,4 +26,17 @@
 | 
			
		|||
int
 | 
			
		||||
wl_os_socket_cloexec(int domain, int type, int protocol);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * The following are for wayland-os.c and the unit tests.
 | 
			
		||||
 * Do not use them elsewhere.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
 | 
			
		||||
#ifndef SOCK_CLOEXEC
 | 
			
		||||
#define SOCK_CLOEXEC 02000000
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif /* __linux__ */
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,12 +50,10 @@ socket(int domain, int type, int protocol)
 | 
			
		|||
{
 | 
			
		||||
	wrapped_calls++;
 | 
			
		||||
 | 
			
		||||
#ifdef SOCK_CLOEXEC
 | 
			
		||||
	if (fall_back && (type & SOCK_CLOEXEC)) {
 | 
			
		||||
		errno = EINVAL;
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	return real_socket(domain, type, protocol);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -70,17 +68,13 @@ do_os_wrappers_socket_cloexec(int n)
 | 
			
		|||
 | 
			
		||||
	/* simply create a socket that closes on exec */
 | 
			
		||||
	fd = wl_os_socket_cloexec(PF_LOCAL, SOCK_STREAM, 0);
 | 
			
		||||
	assert(fd >= 0);
 | 
			
		||||
 | 
			
		||||
#ifdef SOCK_CLOEXEC
 | 
			
		||||
	/*
 | 
			
		||||
	 * Must have 2 calls if falling back, but must also allow
 | 
			
		||||
	 * falling back without a forced fallback.
 | 
			
		||||
	 */
 | 
			
		||||
	assert(wrapped_calls > n);
 | 
			
		||||
#else
 | 
			
		||||
	assert(wrapped_calls == 1);
 | 
			
		||||
#endif
 | 
			
		||||
	assert(fd >= 0);
 | 
			
		||||
 | 
			
		||||
	exec_fd_leak_check(nr_fds);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue