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 <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <errno.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_call_accept_response *response,
|
||||||
patty_ax25_sock *sock) {
|
patty_ax25_sock *sock) {
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
if ((sock->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((sock->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||||
goto error_socket;
|
goto error_socket;
|
||||||
|
@ -591,6 +594,10 @@ static int server_accept_unix(patty_ax25_server *server,
|
||||||
goto error_snprintf;
|
goto error_snprintf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stat(response->path, &st) >= 0) {
|
||||||
|
unlink(response->path);
|
||||||
|
}
|
||||||
|
|
||||||
memset(&addr, '\0', sizeof(addr));
|
memset(&addr, '\0', sizeof(addr));
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
strncpy(addr.sun_path, response->path, sizeof(addr.sun_path));
|
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) {
|
static int listen_unix(patty_ax25_server *server, const char *path) {
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
if (server->fd) {
|
if (server->fd) {
|
||||||
errno = EBUSY;
|
errno = EBUSY;
|
||||||
|
@ -820,6 +828,10 @@ static int listen_unix(patty_ax25_server *server, const char *path) {
|
||||||
goto error_listening;
|
goto error_listening;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stat(path, &st) >= 0) {
|
||||||
|
unlink(path);
|
||||||
|
}
|
||||||
|
|
||||||
if ((server->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((server->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||||
goto error_socket;
|
goto error_socket;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue