diff --git a/src/modules/meson.build b/src/modules/meson.build index 09df62cd6..1bac7414d 100644 --- a/src/modules/meson.build +++ b/src/modules/meson.build @@ -67,10 +67,10 @@ pipewire_module_link_factory = shared_library('pipewire-module-link-factory', dependencies : [mathlib, dl_lib, pipewire_dep], ) -pipewire_module_protocol_native_deps = [mathlib, dl_lib, pipewire_dep] +pipewire_module_protocol_deps = [mathlib, dl_lib, pipewire_dep] if get_option('systemd') - pipewire_module_protocol_native_deps += systemd_dep + pipewire_module_protocol_deps += systemd_dep endif pipewire_module_protocol_native = shared_library('pipewire-module-protocol-native', @@ -85,7 +85,7 @@ pipewire_module_protocol_native = shared_library('pipewire-module-protocol-nativ install : true, install_dir : modules_install_dir, install_rpath: modules_install_dir, - dependencies : pipewire_module_protocol_native_deps, + dependencies : pipewire_module_protocol_deps, ) pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse', @@ -97,7 +97,7 @@ pipewire_module_protocol_pulse = shared_library('pipewire-module-protocol-pulse' install : true, install_dir : modules_install_dir, install_rpath: modules_install_dir, - dependencies : [mathlib, dl_lib, pipewire_dep], + dependencies : pipewire_module_protocol_deps, ) pipewire_module_client_node = shared_library('pipewire-module-client-node', diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 6e54e77c2..317c36656 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -44,6 +44,10 @@ #include #endif +#ifdef HAVE_SYSTEMD +#include +#endif + #include #define spa_debug pw_log_debug @@ -4390,16 +4394,31 @@ get_server_name(struct pw_context *context) return name; } -static int check_connect(struct server *server, int fd) +static bool is_stale_socket(struct server *server, int fd) { - int res; socklen_t size; - size = offsetof(struct sockaddr_un, sun_path) + strlen(server->addr.sun_path); - if ((res = connect(fd, (struct sockaddr *)&server->addr, size)) < 0) - return -errno; +#ifdef HAVE_SYSTEMD + { + int i, n = sd_listen_fds(0); + for (i = 0; i < n; ++i) { + if (sd_is_socket_unix(SD_LISTEN_FDS_START + i, SOCK_STREAM, + 1, server->addr.sun_path, 0) > 0) { + /* socket activated sockets are not stale */ + pw_log_info(NAME" %p: Found socket activation socket for '%s'", + server, server->addr.sun_path); + return false; + } + } + } +#endif - return 0; + size = offsetof(struct sockaddr_un, sun_path) + strlen(server->addr.sun_path); + if (connect(fd, (struct sockaddr *)&server->addr, size) < 0) { + if (errno == ECONNREFUSED) + return true; + } + return false; } static int make_local_socket(struct server *server, char *name) @@ -4437,7 +4456,7 @@ static int make_local_socket(struct server *server, char *name) } } else if (socket_stat.st_mode & S_IWUSR || socket_stat.st_mode & S_IWGRP) { /* socket is there, check if we can connect */ - if ((res = check_connect(server, fd)) < 0) { + if (is_stale_socket(server, fd)) { /* we can't connect, probably stale, remove it */ pw_log_warn(NAME" %p: unlink stale socket %s: %s", server, server->addr.sun_path, spa_strerror(res));