mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-30 16:13:51 +00:00
Issue #20: improve socket set-up logging
This commit is contained in:
parent
259834a4c1
commit
d64d9487c1
@ -78,10 +78,8 @@ struct profile_total client_stats;
|
|||||||
int monitor_setup_sockets()
|
int monitor_setup_sockets()
|
||||||
{
|
{
|
||||||
int sock = -1;
|
int sock = -1;
|
||||||
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
if ((sock = esocket(AF_UNIX, SOCK_STREAM, 0)) == -1)
|
||||||
WHYF_perror("socket(AF_UNIX, SOCK_STREAM, 0)");
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
if (socket_setname(&addr, config.monitor.socket, &addrlen) == -1)
|
if (socket_setname(&addr, config.monitor.socket, &addrlen) == -1)
|
||||||
@ -93,14 +91,13 @@ int monitor_setup_sockets()
|
|||||||
if (socket_set_reuseaddr(sock, 1) == -1)
|
if (socket_set_reuseaddr(sock, 1) == -1)
|
||||||
WHY("Could not indicate reuse addresses. Not necessarily a problem (yet)");
|
WHY("Could not indicate reuse addresses. Not necessarily a problem (yet)");
|
||||||
socket_set_rcvbufsize(sock, 64 * 1024);
|
socket_set_rcvbufsize(sock, 64 * 1024);
|
||||||
if (config.debug.io || config.debug.verbose_io)
|
|
||||||
DEBUGF("Monitor server socket bound to %s", alloca_sockaddr(&addr, addrlen));
|
|
||||||
named_socket.function=monitor_poll;
|
named_socket.function=monitor_poll;
|
||||||
named_stats.name="monitor_poll";
|
named_stats.name="monitor_poll";
|
||||||
named_socket.stats=&named_stats;
|
named_socket.stats=&named_stats;
|
||||||
named_socket.poll.fd=sock;
|
named_socket.poll.fd=sock;
|
||||||
named_socket.poll.events=POLLIN;
|
named_socket.poll.events=POLLIN;
|
||||||
watch(&named_socket);
|
watch(&named_socket);
|
||||||
|
INFOF("Monitor socket: fd=%d %s", sock, alloca_sockaddr(&addr, addrlen));
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "strbuf.h"
|
#include "strbuf.h"
|
||||||
|
#include "strbuf_helpers.h"
|
||||||
#include "overlay_buffer.h"
|
#include "overlay_buffer.h"
|
||||||
#include "overlay_address.h"
|
#include "overlay_address.h"
|
||||||
#include "overlay_packet.h"
|
#include "overlay_packet.h"
|
||||||
@ -89,15 +90,16 @@ int overlay_mdp_setup_sockets()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
socket_set_rcvbufsize(mdp_sock.poll.fd, 64 * 1024);
|
socket_set_rcvbufsize(mdp_sock.poll.fd, 64 * 1024);
|
||||||
/*
|
#if 0
|
||||||
int buffer_size = 64 * 1024;
|
int buffer_size = 64 * 1024;
|
||||||
if (setsockopt(mdp_sock.poll.fd, SOL_SOCKET, SO_SNDBUF, &buffer_size, sizeof(buffer_size)) == -1)
|
if (setsockopt(mdp_sock.poll.fd, SOL_SOCKET, SO_SNDBUF, &buffer_size, sizeof(buffer_size)) == -1)
|
||||||
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_SNDBUF,&%d,%d)", mdp_sock.poll.fd, buffer_size, sizeof buffer_size);
|
WARNF_perror("setsockopt(%d,SOL_SOCKET,SO_SNDBUF,&%d,%d)", mdp_sock.poll.fd, buffer_size, sizeof buffer_size);
|
||||||
*/
|
#endif
|
||||||
mdp_sock.function = overlay_mdp_poll;
|
mdp_sock.function = overlay_mdp_poll;
|
||||||
mdp_sock.stats = &mdp_stats;
|
mdp_sock.stats = &mdp_stats;
|
||||||
mdp_sock.poll.events = POLLIN;
|
mdp_sock.poll.events = POLLIN;
|
||||||
watch(&mdp_sock);
|
watch(&mdp_sock);
|
||||||
|
INFOF("MDP socket: fd=%d %s", mdp_sock.poll.fd, alloca_sockaddr(&addr, addrlen));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -319,7 +319,7 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
|
|||||||
strbuf_toprint_quoted_len(sb, "\"\"", addr->sa_data, len);
|
strbuf_toprint_quoted_len(sb, "\"\"", addr->sa_data, len);
|
||||||
if (len < 2)
|
if (len < 2)
|
||||||
strbuf_sprintf(sb, " (addrlen=%d too short)", (int)addrlen);
|
strbuf_sprintf(sb, " (addrlen=%d too short)", (int)addrlen);
|
||||||
if (len && addr->sa_data[len - 1] != '\0')
|
if (len == 0 || addr->sa_data[len - 1] != '\0')
|
||||||
strbuf_sprintf(sb, " (addrlen=%d, no nul terminator)", (int)addrlen);
|
strbuf_sprintf(sb, " (addrlen=%d, no nul terminator)", (int)addrlen);
|
||||||
} else {
|
} else {
|
||||||
strbuf_puts(sb, "abstract ");
|
strbuf_puts(sb, "abstract ");
|
||||||
@ -330,8 +330,6 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AF_INET: {
|
case AF_INET: {
|
||||||
if (addrlen != sizeof(struct sockaddr_in))
|
|
||||||
strbuf_sprintf(sb, " (addrlen=%d should be %d)", (int)addrlen, sizeof(struct sockaddr_in));
|
|
||||||
const struct sockaddr_in *addr_in = (const struct sockaddr_in *) addr;
|
const struct sockaddr_in *addr_in = (const struct sockaddr_in *) addr;
|
||||||
strbuf_sprintf(sb, " %u.%u.%u.%u:%u",
|
strbuf_sprintf(sb, " %u.%u.%u.%u:%u",
|
||||||
((unsigned char *) &addr_in->sin_addr.s_addr)[0],
|
((unsigned char *) &addr_in->sin_addr.s_addr)[0],
|
||||||
@ -340,6 +338,8 @@ strbuf strbuf_append_sockaddr(strbuf sb, const struct sockaddr *addr, socklen_t
|
|||||||
((unsigned char *) &addr_in->sin_addr.s_addr)[3],
|
((unsigned char *) &addr_in->sin_addr.s_addr)[3],
|
||||||
ntohs(addr_in->sin_port)
|
ntohs(addr_in->sin_port)
|
||||||
);
|
);
|
||||||
|
if (addrlen != sizeof(struct sockaddr_in))
|
||||||
|
strbuf_sprintf(sb, " (addrlen=%d should be %d)", (int)addrlen, sizeof(struct sockaddr_in));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user