mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	protocol-native: support abstract socket addresses
They start with @ and do not create a file in the file system.
This commit is contained in:
		
							parent
							
								
									cfc8d414a9
								
							
						
					
					
						commit
						62035963a3
					
				
					 2 changed files with 25 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -746,7 +746,7 @@ static int init_socket_name(struct server *s, const char *name)
 | 
			
		|||
	const char *runtime_dir;
 | 
			
		||||
	bool path_is_absolute;
 | 
			
		||||
 | 
			
		||||
	path_is_absolute = name[0] == '/';
 | 
			
		||||
	path_is_absolute = name[0] == '/' || name[0] == '@';
 | 
			
		||||
 | 
			
		||||
	runtime_dir = get_runtime_dir();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -784,6 +784,9 @@ static int lock_socket(struct server *s)
 | 
			
		|||
{
 | 
			
		||||
	int res;
 | 
			
		||||
 | 
			
		||||
	if (s->addr.sun_path[0] == '\0')
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	snprintf(s->lock_addr, sizeof(s->lock_addr), "%s%s", s->addr.sun_path, LOCK_SUFFIX);
 | 
			
		||||
 | 
			
		||||
	s->fd_lock = open(s->lock_addr, O_CREAT | O_CLOEXEC,
 | 
			
		||||
| 
						 | 
				
			
			@ -939,18 +942,24 @@ static int add_socket(struct pw_protocol *protocol, struct server *s, struct soc
 | 
			
		|||
			res = -errno;
 | 
			
		||||
			goto error;
 | 
			
		||||
		}
 | 
			
		||||
		if (stat(s->addr.sun_path, &socket_stat) < 0) {
 | 
			
		||||
			if (errno != ENOENT) {
 | 
			
		||||
				res = -errno;
 | 
			
		||||
				pw_log_error("server %p: stat %s failed with error: %m",
 | 
			
		||||
						s, s->addr.sun_path);
 | 
			
		||||
				goto error_close;
 | 
			
		||||
		if (s->addr.sun_path[0] == '@') {
 | 
			
		||||
			s->addr.sun_path[0] = 0;
 | 
			
		||||
			size = (socklen_t) (strlen(&s->addr.sun_path[1]) + 1);
 | 
			
		||||
		} else {
 | 
			
		||||
			if (stat(s->addr.sun_path, &socket_stat) < 0) {
 | 
			
		||||
				if (errno != ENOENT) {
 | 
			
		||||
					res = -errno;
 | 
			
		||||
					pw_log_error("server %p: stat %s failed with error: %m",
 | 
			
		||||
							s, s->addr.sun_path);
 | 
			
		||||
					goto error_close;
 | 
			
		||||
				}
 | 
			
		||||
			} else if (socket_stat.st_mode & S_IWUSR || socket_stat.st_mode & S_IWGRP) {
 | 
			
		||||
				unlink(s->addr.sun_path);
 | 
			
		||||
			}
 | 
			
		||||
		} else if (socket_stat.st_mode & S_IWUSR || socket_stat.st_mode & S_IWGRP) {
 | 
			
		||||
			unlink(s->addr.sun_path);
 | 
			
		||||
			size = (socklen_t) (strlen(s->addr.sun_path) + 1);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		size = offsetof(struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
 | 
			
		||||
		size += offsetof(struct sockaddr_un, sun_path);
 | 
			
		||||
		if (bind(fd, (struct sockaddr *) &s->addr, size) < 0) {
 | 
			
		||||
			res = -errno;
 | 
			
		||||
			pw_log_error("server %p: bind() failed with error: %m", s);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -83,6 +83,11 @@ static int try_connect(struct pw_protocol_client *client,
 | 
			
		|||
	else
 | 
			
		||||
		name_size = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", runtime_dir, name) + 1;
 | 
			
		||||
 | 
			
		||||
	if (addr.sun_path[0] == '@') {
 | 
			
		||||
		addr.sun_path[0] = '\0';
 | 
			
		||||
		name_size--;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (name_size > (int) sizeof addr.sun_path) {
 | 
			
		||||
		if (runtime_dir == NULL)
 | 
			
		||||
			pw_log_error("client %p: socket path \"%s\" plus null terminator exceeds %i bytes",
 | 
			
		||||
| 
						 | 
				
			
			@ -136,7 +141,7 @@ static int try_connect_name(struct pw_protocol_client *client,
 | 
			
		|||
		if (res >= 0)
 | 
			
		||||
			return res;
 | 
			
		||||
	}
 | 
			
		||||
	if (name[0] == '/') {
 | 
			
		||||
	if (name[0] == '/' || name[0] == '@') {
 | 
			
		||||
		return try_connect(client, NULL, name, done_callback, data);
 | 
			
		||||
	} else {
 | 
			
		||||
		runtime_dir = get_runtime_dir();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue