migrate sslh-fork to new log system

This commit is contained in:
yrutschle 2021-09-19 20:29:43 +02:00
parent f7b6f669a4
commit 673c40954e
2 changed files with 10 additions and 14 deletions

View File

@ -24,6 +24,7 @@
#include "probe.h"
#include "sslh-conf.h"
#include "udp-listener.h"
#include "log.h"
#ifdef LIBBSD
#include <bsd/unistd.h>
@ -58,8 +59,7 @@ int shovel(struct connection *cnx)
if (FD_ISSET(cnx->q[i].fd, &fds)) {
res = fd2fd(&cnx->q[1-i], &cnx->q[i]);
if (res == FD_CNXCLOSED) {
if (cfg.verbose)
fprintf(stderr, "%s %s", i ? "client" : "server", "socket closed\n");
print_message(msg_fd, "%s %s", i ? "client" : "server", "socket closed\n");
return res;
}
}
@ -100,7 +100,7 @@ void start_shoveler(int in_socket)
/* Timed out: it's necessarily SSH */
cnx.proto = timeout_protocol();
if (cfg.verbose)
log_message(LOG_INFO, "timed out, connect to %s\n", cnx.proto->name);
print_message(msg_fd, "timed out, connect to %s\n", cnx.proto->name);
break;
}
}
@ -129,8 +129,7 @@ void start_shoveler(int in_socket)
close(in_socket);
close(out_socket);
if (cfg.verbose)
fprintf(stderr, "connection closed down\n");
print_message(msg_fd, "connection closed down\n");
exit(0);
}
@ -179,10 +178,10 @@ void tcp_listener(struct listen_endpoint* endpoint, int num_endpoints, int activ
while (1) {
in_socket = accept(endpoint[active_endpoint].socketfd, 0, 0);
if (cfg.verbose) fprintf(stderr, "accepted fd %d\n", in_socket);
print_message(msg_fd, "accepted fd %d\n", in_socket);
switch(fork()) {
case -1: log_message(LOG_ERR, "fork failed: err %d: %s\n", errno, strerror(errno));
case -1: print_message(msg_system_error, "fork failed: err %d: %s\n", errno, strerror(errno));
break;
case 0: /* In child process */
@ -214,13 +213,13 @@ void main_loop(struct listen_endpoint listen_sockets[], int num_addr_listen)
listener_pid[i] = fork();
switch(listener_pid[i]) {
/* Log if fork() fails for some reason */
case -1: log_message(LOG_ERR, "fork failed: err %d: %s\n", errno, strerror(errno));
case -1: print_message(msg_system_error, "fork failed: err %d: %s\n", errno, strerror(errno));
break;
/* We're in the child, we have work to do */
case 0:
set_listen_procname(&listen_sockets[i]);
if (listen_sockets[i].type == SOCK_DGRAM)
log_message(LOG_ERR, "UDP not (yet?) supported in sslh-fork\n");
print_message(msg_config_error, "UDP not (yet?) supported in sslh-fork\n");
else
tcp_listener(listen_sockets, num_addr_listen, i);
break;

View File

@ -83,7 +83,7 @@ static int tidy_connection(struct connection *cnx, struct select_info* fd_info)
* and FD_CLR. Need to drop connections if we go above that limit */
static int fd_is_in_range(int fd) {
if (fd >= FD_SETSIZE) {
log_message(LOG_ERR, "too many open file descriptor to monitor them all -- dropping connection\n");
print_message(msg_system_error, "too many open file descriptor to monitor them all -- dropping connection\n");
return 0;
}
return 1;
@ -286,10 +286,7 @@ static void probing_read_process(struct connection* cnx,
* data so probe the protocol */
if ((cnx->probe_timeout < time(NULL))) {
cnx->proto = timeout_protocol();
if (cfg.verbose)
log_message(LOG_INFO,
"timed out, connect to %s\n",
cnx->proto->name);
print_message(msg_fd, "timed out, connect to %s\n", cnx->proto->name);
} else {
res = probe_client_protocol(cnx);
if (res == PROBE_AGAIN)