diff --git a/src/server.c b/src/server.c index 1de60c5..35623e4 100644 --- a/src/server.c +++ b/src/server.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -579,6 +581,7 @@ static int server_accept_unix(patty_ax25_server *server, patty_ax25_call_accept_response *response, patty_ax25_sock *sock) { struct sockaddr_un addr; + struct stat st; if ((sock->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { goto error_socket; @@ -591,6 +594,10 @@ static int server_accept_unix(patty_ax25_server *server, goto error_snprintf; } + if (stat(response->path, &st) >= 0) { + unlink(response->path); + } + memset(&addr, '\0', sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, response->path, sizeof(addr.sun_path)); @@ -813,6 +820,7 @@ static patty_ax25_server_call server_calls[PATTY_AX25_CALL_COUNT] = { static int listen_unix(patty_ax25_server *server, const char *path) { struct sockaddr_un addr; + struct stat st; if (server->fd) { errno = EBUSY; @@ -820,6 +828,10 @@ static int listen_unix(patty_ax25_server *server, const char *path) { goto error_listening; } + if (stat(path, &st) >= 0) { + unlink(path); + } + if ((server->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { goto error_socket; }