summaryrefslogtreecommitdiff
path: root/usr.sbin/unbound/dnstap/unbound-dnstap-socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/unbound/dnstap/unbound-dnstap-socket.c')
-rw-r--r--usr.sbin/unbound/dnstap/unbound-dnstap-socket.c70
1 files changed, 17 insertions, 53 deletions
diff --git a/usr.sbin/unbound/dnstap/unbound-dnstap-socket.c b/usr.sbin/unbound/dnstap/unbound-dnstap-socket.c
index 44a0eda9599..3ebe2b4e412 100644
--- a/usr.sbin/unbound/dnstap/unbound-dnstap-socket.c
+++ b/usr.sbin/unbound/dnstap/unbound-dnstap-socket.c
@@ -278,57 +278,31 @@ static int make_tcp_accept(char* ip)
}
if((s = socket(addr.ss_family, SOCK_STREAM, 0)) == -1) {
-#ifndef USE_WINSOCK
- log_err("can't create socket: %s", strerror(errno));
-#else
- log_err("can't create socket: %s",
- wsa_strerror(WSAGetLastError()));
-#endif
+ log_err("can't create socket: %s", sock_strerror(errno));
return -1;
}
#ifdef SO_REUSEADDR
if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*)&on,
(socklen_t)sizeof(on)) < 0) {
-#ifndef USE_WINSOCK
log_err("setsockopt(.. SO_REUSEADDR ..) failed: %s",
- strerror(errno));
- close(s);
-#else
- log_err("setsockopt(.. SO_REUSEADDR ..) failed: %s",
- wsa_strerror(WSAGetLastError()));
- closesocket(s);
-#endif
+ sock_strerror(errno));
+ sock_close(s);
return -1;
}
#endif /* SO_REUSEADDR */
if(bind(s, (struct sockaddr*)&addr, len) != 0) {
-#ifndef USE_WINSOCK
- log_err_addr("can't bind socket", strerror(errno),
+ log_err_addr("can't bind socket", sock_strerror(errno),
&addr, len);
- close(s);
-#else
- log_err_addr("can't bind socket",
- wsa_strerror(WSAGetLastError()), &addr, len);
- closesocket(s);
-#endif
+ sock_close(s);
return -1;
}
if(!fd_set_nonblock(s)) {
-#ifndef USE_WINSOCK
- close(s);
-#else
- closesocket(s);
-#endif
+ sock_close(s);
return -1;
}
if(listen(s, LISTEN_BACKLOG) == -1) {
-#ifndef USE_WINSOCK
- log_err("can't listen: %s", strerror(errno));
- close(s);
-#else
- log_err("can't listen: %s", wsa_strerror(WSAGetLastError()));
- closesocket(s);
-#endif
+ log_err("can't listen: %s", sock_strerror(errno));
+ sock_close(s);
return -1;
}
return s;
@@ -654,7 +628,6 @@ static ssize_t receive_bytes(struct tap_data* data, int fd, void* buf,
#ifndef USE_WINSOCK
if(errno == EINTR || errno == EAGAIN)
return -1;
- log_err("could not recv: %s", strerror(errno));
#else /* USE_WINSOCK */
if(WSAGetLastError() == WSAEINPROGRESS)
return -1;
@@ -662,9 +635,8 @@ static ssize_t receive_bytes(struct tap_data* data, int fd, void* buf,
ub_winsock_tcp_wouldblock(data->ev, UB_EV_READ);
return -1;
}
- log_err("could not recv: %s",
- wsa_strerror(WSAGetLastError()));
#endif
+ log_err("could not recv: %s", sock_strerror(errno));
if(verbosity) log_info("dnstap client stream closed from %s",
(data->id?data->id:""));
return 0;
@@ -796,12 +768,7 @@ static int reply_with_accept(struct tap_data* data)
}
} else {
if(send(data->fd, acceptframe, len, 0) == -1) {
-#ifndef USE_WINSOCK
- log_err("send failed: %s", strerror(errno));
-#else
- log_err("send failed: %s",
- wsa_strerror(WSAGetLastError()));
-#endif
+ log_err("send failed: %s", sock_strerror(errno));
fd_set_nonblock(data->fd);
free(acceptframe);
return 0;
@@ -834,11 +801,7 @@ static int reply_with_finish(int fd)
fd_set_block(fd);
if(send(fd, finishframe, len, 0) == -1) {
-#ifndef USE_WINSOCK
- log_err("send failed: %s", strerror(errno));
-#else
- log_err("send failed: %s", wsa_strerror(WSAGetLastError()));
-#endif
+ log_err("send failed: %s", sock_strerror(errno));
fd_set_nonblock(fd);
free(finishframe);
return 0;
@@ -1094,7 +1057,6 @@ void dtio_mainfdcallback(int fd, short ATTR_UNUSED(bits), void* arg)
#endif /* EPROTO */
)
return;
- log_err_addr("accept failed", strerror(errno), &addr, addrlen);
#else /* USE_WINSOCK */
if(WSAGetLastError() == WSAEINPROGRESS ||
WSAGetLastError() == WSAECONNRESET)
@@ -1103,9 +1065,9 @@ void dtio_mainfdcallback(int fd, short ATTR_UNUSED(bits), void* arg)
ub_winsock_tcp_wouldblock(maindata->ev, UB_EV_READ);
return;
}
- log_err_addr("accept failed", wsa_strerror(WSAGetLastError()),
- &addr, addrlen);
#endif
+ log_err_addr("accept failed", sock_strerror(errno), &addr,
+ addrlen);
return;
}
fd_set_nonblock(s);
@@ -1205,8 +1167,10 @@ int sig_quit = 0;
static RETSIGTYPE main_sigh(int sig)
{
verbose(VERB_ALGO, "exit on signal %d\n", sig);
- if(sig_base)
+ if(sig_base) {
ub_event_base_loopexit(sig_base);
+ sig_base = NULL;
+ }
sig_quit = 1;
}
@@ -1247,9 +1211,9 @@ setup_and_run(struct config_strlist_head* local_list,
if(verbosity) log_info("start of service");
ub_event_base_dispatch(base);
+ sig_base = NULL;
if(verbosity) log_info("end of service");
- sig_base = NULL;
tap_socket_list_delete(maindata->acceptlist);
ub_event_base_free(base);
free(maindata);