protocol-native: attempt to remove socket

After we grab the lockfile we should remove the socket when it
exists so that we can bind again. This should solve startup
problems after a crash, which left the socket around and caused
bind failures.
This commit is contained in:
Wim Taymans 2019-08-30 18:08:00 +02:00
parent 9a202272f2
commit 312864d9e9

View file

@ -480,10 +480,23 @@ static int add_socket(struct pw_protocol *protocol, struct server *s)
#endif
if (fd < 0) {
struct stat socket_stat;
if ((fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) {
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;
}
} else if (socket_stat.st_mode & S_IWUSR || socket_stat.st_mode & S_IWGRP) {
pw_log_warn("removing stale socket");
unlink(s->addr.sun_path);
}
size = offsetof(struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
if (bind(fd, (struct sockaddr *) &s->addr, size) < 0) {