unlink() stale sockets
This commit is contained in:
parent
696ce80b5b
commit
36a7de1b2c
1 changed files with 12 additions and 0 deletions
12
src/server.c
12
src/server.c
|
@ -4,6 +4,8 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <errno.h>
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue