From 673c40954e368b3ca5e479aa5962f81fe643118b Mon Sep 17 00:00:00 2001 From: yrutschle Date: Sun, 19 Sep 2021 20:29:43 +0200 Subject: [PATCH] migrate sslh-fork to new log system --- sslh-fork.c | 17 ++++++++--------- sslh-select.c | 7 ++----- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sslh-fork.c b/sslh-fork.c index 128c144..4ad699e 100644 --- a/sslh-fork.c +++ b/sslh-fork.c @@ -24,6 +24,7 @@ #include "probe.h" #include "sslh-conf.h" #include "udp-listener.h" +#include "log.h" #ifdef LIBBSD #include @@ -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; diff --git a/sslh-select.c b/sslh-select.c index 65fbadf..a5cc45b 100644 --- a/sslh-select.c +++ b/sslh-select.c @@ -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)