mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 01:42:18 +00:00
Improve monitor client logging
To assist diagnosis of latest Solaris port bug, issue #16.
This commit is contained in:
parent
f93216f369
commit
cfc16e8e87
2
log.h
2
log.h
@ -135,7 +135,7 @@ ssize_t get_self_executable_path(char *buf, size_t len);
|
||||
int log_backtrace(struct __sourceloc whence);
|
||||
void set_log_implementation(void (*log_function)(int level, struct strbuf *buf));
|
||||
|
||||
#define alloca_toprint(dstlen,buf,len) toprint((char *)alloca((dstlen) == -1 ? toprint_len((buf),(len), "``") + 1 : (dstlen)), (dstlen), (buf), (len), "``")
|
||||
#define alloca_toprint(dstlen,buf,len) toprint((char *)alloca((dstlen) == -1 ? toprint_len((const char *)(buf),(len), "``") + 1 : (dstlen)), (dstlen), (const char *)(buf), (len), "``")
|
||||
#define alloca_str_toprint(str) toprint_str((char *)alloca(toprint_str_len(str, "``") + 1), -1, (str), "``")
|
||||
|
||||
#define __HERE__ ((struct __sourceloc){ .file = __FILE__, .line = __LINE__, .function = __FUNCTION__ })
|
||||
|
@ -94,22 +94,25 @@ int monitor_client_open(struct monitor_state **res)
|
||||
struct sockaddr_un addr;
|
||||
|
||||
if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
||||
perror("socket");
|
||||
WHYF_perror("socket(AF_UNIX, SOCK_STREAM, 0)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sun_family = AF_UNIX;
|
||||
int len = monitor_socket_name(&addr);
|
||||
|
||||
INFOF("Attempting to connect to %s", &addr.sun_path[1]);
|
||||
|
||||
INFOF("Attempting to connect to %s %s",
|
||||
addr.sun_path[0] ? "local" : "abstract",
|
||||
alloca_str_toprint(addr.sun_path[0] ? &addr.sun_path[0] : &addr.sun_path[1])
|
||||
);
|
||||
|
||||
if (connect(fd, (struct sockaddr*)&addr, len) == -1) {
|
||||
perror("connect");
|
||||
WHYF_perror("connect(%d, %s)", fd, alloca_toprint(-1, &addr, len));
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
*res = (struct monitor_state*)malloc(sizeof(struct monitor_state));
|
||||
memset(*res,0,sizeof(struct monitor_state));
|
||||
return fd;
|
||||
|
24
monitor.c
24
monitor.c
@ -83,7 +83,7 @@ int monitor_setup_sockets()
|
||||
name.sun_family = AF_UNIX;
|
||||
|
||||
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0))==-1) {
|
||||
WHY_perror("socket");
|
||||
WHYF_perror("socket(AF_UNIX, SOCK_STREAM, 0)");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -93,26 +93,26 @@ int monitor_setup_sockets()
|
||||
#endif
|
||||
|
||||
if(bind(sock, (struct sockaddr *)&name, len)==-1) {
|
||||
WHY_perror("bind");
|
||||
WHYF_perror("bind(%d, %s)", sock, alloca_toprint(-1, &name, len));
|
||||
goto error;
|
||||
}
|
||||
if(listen(sock,MAX_MONITOR_SOCKETS)==-1) {
|
||||
WHY_perror("listen");
|
||||
WHYF_perror("listen(%d, %d)", sock, MAX_MONITOR_SOCKETS);
|
||||
goto error;
|
||||
}
|
||||
|
||||
int reuseP=1;
|
||||
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||
&reuseP, sizeof(reuseP)) < 0) {
|
||||
WHY_perror("setsockopt");
|
||||
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseP, sizeof reuseP) < 0) {
|
||||
WHYF_perror("setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, &%d, %d)", sock, reuseP, sizeof reuseP);
|
||||
WHY("Could not indicate reuse addresses. Not necessarily a problem (yet)");
|
||||
}
|
||||
|
||||
int send_buffer_size=64*1024;
|
||||
if(setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
|
||||
&send_buffer_size, sizeof(send_buffer_size))==-1)
|
||||
WHY_perror("setsockopt");
|
||||
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO)) DEBUG("Monitor server socket setup");
|
||||
if(setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &send_buffer_size, sizeof send_buffer_size)==-1)
|
||||
WHYF_perror("setsockopt(%d, SOL_SOCKET, SO_RCVBUF, &%d, %d)", sock, send_buffer_size, sizeof send_buffer_size);
|
||||
|
||||
if (debug&(DEBUG_IO|DEBUG_VERBOSE_IO))
|
||||
DEBUGF("Monitor server socket bound to %s", alloca_toprint(-1, &name, len));
|
||||
|
||||
named_socket.function=monitor_poll;
|
||||
named_stats.name="monitor_poll";
|
||||
@ -323,7 +323,7 @@ static void monitor_new_client(int s) {
|
||||
#elif defined(HAVE_UCRED_H)
|
||||
/* Solaris way */
|
||||
if (getpeerucred(s, &ucred) != 0) {
|
||||
WHY_perror("getpeerucred()");
|
||||
WHY_perror("getpeerucred");
|
||||
goto error;
|
||||
}
|
||||
otheruid = ucred_geteuid(ucred);
|
||||
@ -331,7 +331,7 @@ static void monitor_new_client(int s) {
|
||||
#elif defined(HAVE_GETPEEREID)
|
||||
/* BSD way */
|
||||
if (getpeereid(s, &otheruid, &othergid) != 0) {
|
||||
WHY_perror("getpeereid()");
|
||||
WHY_perror("getpeereid");
|
||||
goto error;
|
||||
}
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user