Skip to content

Commit

Permalink
Enhance debug error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelortmann committed Jul 31, 2024
1 parent 74c7861 commit 648ad9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,8 @@ int main(int arg_c, char **arg_v)
putlog(LOG_MISC, "*", "Error renaming stderr file handle: %s", strerror(errno));
}
#ifdef CYGWIN_HACKS
FreeConsole();
if (!FreeConsole())
putlog(LOG_MISC, "*", "FreeConsole() failed with error %lu", GetLastError());
#endif
}

Expand Down
16 changes: 11 additions & 5 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ int open_telnet_raw(int sock, sockname_t *addr)
FD_SET(sock, &sockset);
select(sock + 1, &sockset, NULL, NULL, &tv);
res_len = sizeof(res);
getsockopt(sock, SOL_SOCKET, SO_ERROR, &res, &res_len);
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &res, &res_len) < 0)
debug2("net: open_telnet_raw(): getsockopt() s %i level SOL_SOCKET optname SO_ERROR error %s",
sock, strerror(errno));
if (res == EINPROGRESS) /* Operation now in progress */
return sock; /* This could probably fail somewhere */
if (res == ECONNREFUSED) { /* Connection refused */
Expand Down Expand Up @@ -652,7 +654,9 @@ int open_address_listen(sockname_t *addr)
#if defined IPV6 && IPV6_V6ONLY
if (addr->family == AF_INET6) {
int on = 0;
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on, sizeof(on));
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &on, sizeof on))
debug2("net: open_address_listen(): setsockopt() s %i level IPPROTO_IPV6 optname IPV6_V6ONLY error %s",
sock, strerror(errno));
}
#endif
if (bind(sock, &addr->addr.sa, addr->addrlen) < 0) {
Expand Down Expand Up @@ -1243,7 +1247,7 @@ int sockgets(char *s, int *len)
}
}
/* Look for EOL marker; if it's there, i have something to show */
for (p = xx; *p != 0 ; p++) {
for (p = xx; *p != 0; p++) {
if ((*p == '\r') || (*p == '\n')) {
memcpy(s, xx, p - xx);
s[p - xx] = 0;
Expand Down Expand Up @@ -1427,13 +1431,15 @@ void dequeue_sockets()
socklen_t res_len;
if (socklist[i].flags == SOCK_CONNECT) {
res_len = sizeof(res);
getsockopt(socklist[i].sock, SOL_SOCKET, SO_ERROR, &res, &res_len);
if (getsockopt(socklist[i].sock, SOL_SOCKET, SO_ERROR, &res, &res_len) < 0)
debug2("net: dequeue_sockets(): getsockopt() s %i level SOL_SOCKET optname SO_ERROR error %s",
socklist[i].sock, strerror(errno));
if (res == ECONNREFUSED) { /* Connection refused */
int idx = findanyidx(socklist[i].sock);
putlog(LOG_MISC, "*", "Connection refused: %s:%i", dcc[idx].host,
dcc[idx].port);
socklist[i].flags |= SOCK_EOFD;
return ;
return;
}
}
#endif
Expand Down

0 comments on commit 648ad9a

Please sign in to comment.