From b97f8dc7d6f5dfb2ce03520c4285acce6f36fec9 Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Thu, 7 Nov 2019 11:27:36 -0500 Subject: [PATCH] Cleanup logging --- log.c | 109 +++++++++++++++-------------------------- server-client.c | 4 +- server.c | 2 + tmate-auth-keys.c | 2 +- tmate-daemon-decoder.c | 12 ++--- tmate-daemon-encoder.c | 4 +- tmate-main.c | 30 ++++++------ tmate-ssh-client-pty.c | 3 +- tmate-ssh-daemon.c | 12 ++--- tmate-ssh-exec.c | 8 ++- tmate-ssh-server.c | 63 ++++++++++++++---------- tmate-websocket.c | 7 ++- tmate.h | 24 ++------- tmux.h | 8 ++- 14 files changed, 133 insertions(+), 155 deletions(-) diff --git a/log.c b/log.c index 2299b6db..7327f4c1 100644 --- a/log.c +++ b/log.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -31,16 +30,11 @@ FILE *log_file; -struct logging_settings { - const char *program_name; - bool use_syslog; - int log_level; -}; - -static struct logging_settings log_settings; - static void log_event_cb(int, const char *); -static void log_vwrite(int, const char *, va_list); +static void log_vwrite(const char *, va_list); + +static int log_level; +char *log_prefix; static void log_event_cb(__unused int severity, const char *msg) @@ -52,72 +46,69 @@ log_event_cb(__unused int severity, const char *msg) void log_add_level(void) { - log_settings.log_level++; + log_level++; } /* Get log level. */ int log_get_level(void) { - return (log_settings.log_level); + return log_level; } -void init_logging(const char *program_name, bool use_syslog, int log_level) +void init_logging(int _log_level) { - log_settings.log_level = log_level; - log_settings.use_syslog = use_syslog; - log_settings.program_name = xstrdup(program_name); + log_level = _log_level; + log_prefix = xstrdup(""); - if (use_syslog) { - openlog(program_name, LOG_CONS | LOG_PID, LOG_USER); - setlogmask(LOG_UPTO(log_level)); - } else { - log_file = fdopen(dup(STDERR_FILENO), "a"); - if (!log_file) - exit(1); - } + log_file = fdopen(dup(STDERR_FILENO), "a"); + if (!log_file) + exit(1); event_set_log_callback(log_event_cb); } -/* Write a log message. */ -__attribute__((__format__(__printf__, 2, 0))) -static void -log_vwrite(int level, const char *msg, va_list ap) +void set_log_prefix(char *_log_prefix) { - char *fmt = NULL; + free(log_prefix); + log_prefix = xstrdup(_log_prefix); +} - const char *token = tmate_session->obfuscated_session_token; +/* Write a log message. */ +__attribute__((__format__(__printf__, 1, 0))) +static void +log_vwrite(const char *msg, va_list ap) +{ + char *fmt, *out; + struct timeval tv; - if (log_settings.log_level < level) + if (log_file == NULL) return; - if (token) { - if (asprintf(&fmt, "[%s] %s", token, msg) < 0) - exit(1); - msg = fmt; - } + if (vasprintf(&fmt, msg, ap) == -1) + exit(1); + if (stravis(&out, fmt, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL) == -1) + exit(1); - if (log_settings.use_syslog) { - vsyslog(level, msg, ap); - } else { - fprintf(log_file, "<%d> ", level); - vfprintf(log_file, msg, ap); - fprintf(log_file, "\n"); - fflush(log_file); - } + if (fprintf(log_file, "%s%s\n", log_prefix, out) == -1) + exit(1); + fflush(log_file); + + free(out); free(fmt); } -/* Log a debug message. */ void -log_debug(const char *msg, ...) +log_emit(int level, const char *msg, ...) { va_list ap; + if (log_level < level) + return; + va_start(ap, msg); - log_vwrite(LOG_DEBUG, msg, ap); + log_vwrite(msg, ap); va_end(ap); } @@ -133,7 +124,7 @@ fatal(const char *msg, ...) if (asprintf(&fmt, "fatal: %s: %s", msg, strerror(errno)) == -1) exit(1); msg = fmt; - log_vwrite(LOG_CRIT, msg, ap); + log_vwrite(msg, ap); exit(1); } @@ -149,26 +140,6 @@ fatalx(const char *msg, ...) if (asprintf(&fmt, "fatal: %s", msg) == -1) exit(1); msg = fmt; - log_vwrite(LOG_CRIT, msg, ap); + log_vwrite(msg, ap); exit(1); } - -__attribute__((__format__(__printf__, 2, 0))) -void tmate_log(int level, const char *msg, ...) -{ - char *fmt; - va_list ap; - - if (log_settings.log_level < level) - return; - - va_start(ap, msg); - - if (asprintf(&fmt, "(tmate) %s", msg) < 0) - exit(1); - msg = fmt; - log_vwrite(level, msg, ap); - va_end(ap); - - free(fmt); -} diff --git a/server-client.c b/server-client.c index 7a0d819b..06d9c6b6 100644 --- a/server-client.c +++ b/server-client.c @@ -1084,7 +1084,7 @@ server_client_dispatch(struct imsg *imsg, void *arg) if (!(c->flags & CLIENT_TMATE_AUTHENTICATED)) { control_write(c, "Authentication needed"); - tmate_warn("Dropping unauthenticated client"); + tmate_info("Dropping unauthenticated client"); c->flags |= CLIENT_EXIT; return; } @@ -1105,7 +1105,7 @@ server_client_dispatch(struct imsg *imsg, void *arg) #ifdef TMATE if (!(c->flags & CLIENT_IDENTIFIED)) { - tmate_warn("dropping unidentified client message: %d", imsg->hdr.type); + tmate_info("dropping unidentified client message: %d", imsg->hdr.type); return; } #endif diff --git a/server.c b/server.c index 867779f2..4139ef51 100644 --- a/server.c +++ b/server.c @@ -247,6 +247,8 @@ server_loop(void) if (!TAILQ_EMPTY(&clients)) return (0); + tmate_info("Session terminated"); + return (1); } diff --git a/tmate-auth-keys.c b/tmate-auth-keys.c index f390b837..e5c3de49 100644 --- a/tmate-auth-keys.c +++ b/tmate-auth-keys.c @@ -216,7 +216,7 @@ bool would_tmate_session_allow_auth(const char *token, const char *pubkey) recv_msg.hdr.len == sizeof(recv_msg)) ret = recv_msg.allow; - tmate_info("(preauth) allow=%d", ret); + tmate_debug("(preauth) allow=%d", ret); out: if (sock_fd != -1) diff --git a/tmate-daemon-decoder.c b/tmate-daemon-decoder.c index b4094300..62e38af9 100644 --- a/tmate-daemon-decoder.c +++ b/tmate-daemon-decoder.c @@ -45,8 +45,8 @@ static void tmate_header(struct tmate_session *session, session->daemon_encoder.mpac_version = 4; } - tmate_notice("Daemon header: client version: %s, protocol version: %d", - session->client_version, session->client_protocol_version); + tmate_info("Daemon header: version=%s, protocol=%d", + session->client_version, session->client_protocol_version); if (tmate_has_websocket()) { /* If we have a websocket server, it takes care of all the following notificatons */ @@ -222,10 +222,10 @@ static void tmate_exec_cmd_str(__unused struct tmate_session *session, cmd_str = unpack_string(uk); - tmate_info("Local cmd: %s", cmd_str); + tmate_debug("Local cmd: %s", cmd_str); if (cmd_string_parse(cmd_str, &cmdlist, NULL, 0, &cause) != 0) { - tmate_info("parse error: %s", cause); + tmate_debug("parse error: %s", cause); free(cause); goto out; } @@ -257,13 +257,13 @@ static void tmate_exec_cmd(__unused struct tmate_session *session, cmd = cmd_parse(argc, argv, NULL, 0, &cause); if (!cmd) { - tmate_info("parse error: %s", cause); + tmate_debug("parse error: %s", cause); free(cause); goto out; } cmd_str = cmd_print(cmd); - tmate_info("Local cmd: %s", cmd_str); + tmate_debug("Local cmd: %s", cmd_str); free(cmd_str); cmdlist = xcalloc(1, sizeof *cmdlist); diff --git a/tmate-daemon-encoder.c b/tmate-daemon-encoder.c index 4baf6985..8adf599b 100644 --- a/tmate-daemon-encoder.c +++ b/tmate-daemon-encoder.c @@ -147,7 +147,7 @@ int tmate_should_exec_cmd_locally(const struct cmd_entry *cmd) void tmate_client_cmd_str(int client_id, const char *cmd) { - tmate_info("Remote cmd (cid=%d): %s", client_id, cmd); + tmate_debug("Remote cmd (cid=%d): %s", client_id, cmd); pack(array, 3); pack(int, TMATE_IN_EXEC_CMD_STR); @@ -217,7 +217,7 @@ void tmate_client_cmd(int client_id, struct cmd *cmd) free(cmd_str); return; } - tmate_info("Remote cmd (cid=%d): %s", client_id, cmd_str); + tmate_debug("Remote cmd (cid=%d): %s", client_id, cmd_str); free(cmd_str); extract_cmd(cmd, &argc, &argv); diff --git a/tmate-main.c b/tmate-main.c index 1a25846f..071a0af2 100644 --- a/tmate-main.c +++ b/tmate-main.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include "tmate.h" @@ -32,9 +31,8 @@ struct tmate_settings _tmate_settings = { .bind_addr = NULL, .websocket_port = TMATE_DEFAULT_WEBSOCKET_PORT, .tmate_host = NULL, - .log_level = LOG_NOTICE, + .log_level = LOG_INFO, .use_proxy_protocol = false, - .use_syslog = false, }; struct tmate_settings *tmate_settings = &_tmate_settings; @@ -51,7 +49,7 @@ void request_server_termination(void) static void usage(void) { - fprintf(stderr, "usage: tmate-ssh-server [-b ip] [-h hostname] [-k keys_dir] [-p listen_port] [-q ssh_port_advertized] [-w websocket_hostname] [-z websocket_port] [-x] [-s] [-v]\n"); + fprintf(stderr, "usage: tmate-ssh-server [-b ip] [-h hostname] [-k keys_dir] [-p listen_port] [-q ssh_port_advertized] [-w websocket_hostname] [-z websocket_port] [-x] [-v]\n"); } static char* get_full_hostname(void) @@ -71,7 +69,7 @@ static char* get_full_hostname(void) hints.ai_flags = AI_CANONNAME; if ((gai_result = getaddrinfo(hostname, NULL, &hints, &info)) != 0) { - tmate_warn("cannot lookup hostname: %s", gai_strerror(gai_result)); + tmate_info("cannot lookup hostname: %s", gai_strerror(gai_result)); return xstrdup(hostname); } @@ -104,7 +102,7 @@ int main(int argc, char **argv, char **envp) { int opt; - while ((opt = getopt(argc, argv, "b:h:k:p:q:w:z:xsv")) != -1) { + while ((opt = getopt(argc, argv, "b:h:k:p:q:w:z:xv")) != -1) { switch (opt) { case 'b': tmate_settings->bind_addr = xstrdup(optarg); @@ -130,9 +128,6 @@ int main(int argc, char **argv, char **envp) case 'x': tmate_settings->use_proxy_protocol = true; break; - case 's': - tmate_settings->use_syslog = true; - break; case 'v': tmate_settings->log_level++; break; @@ -142,8 +137,7 @@ int main(int argc, char **argv, char **envp) } } - init_logging("tmate-remote-tmux", - tmate_settings->use_syslog, tmate_settings->log_level); + init_logging(tmate_settings->log_level); setup_locale(); @@ -196,11 +190,17 @@ void set_session_token(struct tmate_session *session, const char *token) xasprintf((char **)&session->obfuscated_session_token, "%.4s...", session->session_token); - memset(cmdline, 0, cmdline_end - cmdline); - sprintf(cmdline, "tmate-ssh-server [%s] %s %s", + size_t size = cmdline_end - cmdline; + memset(cmdline, 0, size); + snprintf(cmdline, size-1, "tmate-ssh-server [%s] %s %s", tmate_session->obfuscated_session_token, session->ssh_client.role == TMATE_ROLE_DAEMON ? "(daemon)" : "(pty client)", session->ssh_client.ip_address); + + char *log_prefix; + xasprintf(&log_prefix, "[%s] ", session->obfuscated_session_token); + set_log_prefix(log_prefix); + free(log_prefix); } void close_fds_except(int *fd_to_preserve, int num_fds) @@ -273,8 +273,8 @@ void get_in_jail(void) nice(1); - tmate_info("Dropped priviledges to %s (%d,%d), jailed in %s", - TMATE_JAIL_USER, uid, gid, TMATE_WORKDIR "/jail"); + tmate_debug("Dropped priviledges to %s (%d,%d), jailed in %s", + TMATE_JAIL_USER, uid, gid, TMATE_WORKDIR "/jail"); } void setup_ncurse(int fd, const char *name) diff --git a/tmate-ssh-client-pty.c b/tmate-ssh-client-pty.c index 6379104c..4a7bb0e8 100644 --- a/tmate-ssh-client-pty.c +++ b/tmate-ssh-client-pty.c @@ -176,8 +176,7 @@ void tmate_spawn_pty_client(struct tmate_session *session) set_session_token(session, token); - tmate_info("Spawning pty client for %s (%s)", - client->ip_address, client->pubkey); + tmate_info("Spawning pty client ip=%s", client->ip_address); session->tmux_socket_fd = client_connect(session->ev_base, socket_path, 0); if (session->tmux_socket_fd < 0) { diff --git a/tmate-ssh-daemon.c b/tmate-ssh-daemon.c index 8f224a28..c4e6874c 100644 --- a/tmate-ssh-daemon.c +++ b/tmate-ssh-daemon.c @@ -59,8 +59,8 @@ static void on_daemon_encoder_write(void *userdata, struct evbuffer *buffer) written = ssh_channel_write(session->ssh_client.channel, buf, len); if (written < 0) { - tmate_warn("Error writing to channel: %s", - ssh_get_error(session->ssh_client.session)); + tmate_info("Error writing to channel: %s", + ssh_get_error(session->ssh_client.session)); request_server_termination(); break; } @@ -156,8 +156,8 @@ void tmate_spawn_daemon(struct tmate_session *session) set_session_token(session, token); free(token); - tmate_info("Spawning daemon for %s at %s (%s)", - client->username, client->ip_address, client->pubkey); + tmate_info("Spawning daemon username=%s ip=%s", + client->username, client->ip_address); session->tmux_socket_fd = server_create_socket(); if (session->tmux_socket_fd < 0) @@ -197,8 +197,8 @@ static void handle_session_name_options(const char *name, __unused const char *v !strcmp(name, "tmate-session-name-ro")) { static bool warned; if (!warned) { - tmate_warn("/!\\ Named sessions are not supported without the websocket server"); - tmate_notify("/!\\ Named sessions are not supported without the websocket server"); + tmate_info("Named sessions are not supported (no websocket server)"); + tmate_notify("Named sessions are not supported (no websocket server)"); } warned = true; } diff --git a/tmate-ssh-exec.c b/tmate-ssh-exec.c index fff384fc..209a1b61 100644 --- a/tmate-ssh-exec.c +++ b/tmate-ssh-exec.c @@ -14,12 +14,12 @@ void tmate_dump_exec_response(struct tmate_session *session, ssh_channel_close(client->channel); if (event_base_loopexit(session->ev_base, NULL) < 0) - tmate_fatal("cannot stop event loop"); + tmate_fatal("Cannot stop event loop"); } static void on_websocket_error(struct tmate_session *session, __unused short events) { - tmate_warn("Lost websocket server connection"); + tmate_info("Lost websocket server connection"); tmate_dump_exec_response(session, 1, "Internal Error\r\n"); } @@ -38,6 +38,10 @@ static void tmate_client_exec_init(struct tmate_session *session) void tmate_spawn_exec(struct tmate_session *session) { + struct tmate_ssh_client *client = &session->ssh_client; + + tmate_info("Spawning exec client ip=%s", client->ip_address); + close_fds_except((int[]){ssh_get_fd(session->ssh_client.session), log_file ? fileno(log_file) : -1, session->websocket_fd}, 3); diff --git a/tmate-ssh-server.c b/tmate-ssh-server.c index 6bcc871c..d9879fda 100644 --- a/tmate-ssh-server.c +++ b/tmate-ssh-server.c @@ -186,7 +186,7 @@ static void on_ssh_read(__unused evutil_socket_t fd, __unused short what, void * ssh_execute_message_callbacks(client->session); if (!ssh_is_connected(client->session)) { - tmate_warn("SSH Disconnected"); + tmate_debug("ssh disconnected"); event_del(&client->ev_ssh); @@ -204,7 +204,7 @@ static void register_on_ssh_read(struct tmate_ssh_client *client) static void handle_sigalrm(__unused int sig) { - tmate_fatal_info("Connection grace period (%ds) passed", TMATE_SSH_GRACE_PERIOD); + tmate_fatal_quiet("Connection grace period (%ds) passed", TMATE_SSH_GRACE_PERIOD); } static void client_bootstrap(struct tmate_session *_session) @@ -214,7 +214,7 @@ static void client_bootstrap(struct tmate_session *_session) ssh_event mainloop; ssh_session session = client->session; - tmate_info("Bootstrapping ssh client ip=%s", client->ip_address); + tmate_debug("Bootstrapping ssh client ip=%s", client->ip_address); _session->ev_base = osdep_event_init(); @@ -247,14 +247,14 @@ static void client_bootstrap(struct tmate_session *_session) tmate_debug("Exchanging DH keys"); if (ssh_handle_key_exchange(session) < 0) - tmate_fatal_info("Error doing the key exchange: %s", ssh_get_error(session)); + tmate_fatal_quiet("Error doing the key exchange: %s", ssh_get_error(session)); mainloop = ssh_event_new(); ssh_event_add_session(mainloop, session); while (!client->role) { if (ssh_event_dopoll(mainloop, -1) == SSH_ERROR) - tmate_fatal_info("Error polling ssh socket: %s", ssh_get_error(session)); + tmate_fatal_quiet("Error polling ssh socket: %s", ssh_get_error(session)); } alarm(0); @@ -298,7 +298,7 @@ static int get_client_ip_socket(int fd, char *dst, size_t len) return 0; } -static void read_single_line(int fd, char *dst, size_t len) +static int read_single_line(int fd, char *dst, size_t len) { /* * This reads exactly one line from fd. @@ -314,26 +314,30 @@ static void read_single_line(int fd, char *dst, size_t len) if (dst[i] == '\n') { dst[i] = '\0'; - return; + return i; } } - tmate_fatal("Cannot read proxy header. Load balancer may be misconfigured"); + return -1; } static int get_client_ip_proxy_protocol(int fd, char *dst, size_t len) { char header[110]; int tok_num; - const char *signature = "PROXY "; - if (read(fd, header, strlen(signature)) != (ssize_t)strlen(signature)) - tmate_fatal("Cannot read proxy header"); +#define SIGNATURE "PROXY " + ssize_t ret = read(fd, header, sizeof(SIGNATURE)-1); + if (ret <= 0) + tmate_fatal_quiet("Disconnected, health checker?"); + if (ret != sizeof(SIGNATURE)-1) + return -1; + if (memcmp(header, SIGNATURE, sizeof(SIGNATURE)-1)) + return -1; +#undef SIGNATURE - if (memcmp(header, signature, strlen(signature))) - tmate_fatal("No proxy header found. Load balancer may be misconfigured"); - - read_single_line(fd, header, sizeof(header)); + if (read_single_line(fd, header, sizeof(header)) < 0) + return -1; tmate_debug("proxy header: %s", header); @@ -344,7 +348,7 @@ static int get_client_ip_proxy_protocol(int fd, char *dst, size_t len) } if (tok_num != 5) - tmate_fatal("Proxy header is invalid"); + return -1; return 0; } @@ -360,7 +364,8 @@ static int get_client_ip(int fd, char *dst, size_t len) static void ssh_log_function(int priority, const char *function, const char *buffer, __unused void *userdata) { - tmate_log(LOG_NOTICE + priority, "[%s] %s", function, buffer); + /* loglevel already applied */ + log_emit(LOG_DEBUG, "[%s] %s", function, buffer); } static inline int max(int a, int b) @@ -380,7 +385,7 @@ static void ssh_import_key(ssh_bind bind, const char *keys_dir, const char *name if (access(path, F_OK) < 0) return; - tmate_notice("Loading key %s", path); + tmate_info("Loading key %s", path); ssh_pki_import_privkey_file(path, NULL, NULL, NULL, &key); ssh_bind_options_set(bind, SSH_BIND_OPTIONS_IMPORT_KEY, key); @@ -391,7 +396,7 @@ static ssh_bind prepare_ssh(const char *keys_dir, const char *bind_addr, int por ssh_bind bind; int ssh_log_level; - ssh_log_level = SSH_LOG_WARNING + max(log_get_level() - LOG_NOTICE, 0); + ssh_log_level = SSH_LOG_WARNING + max(log_get_level() - LOG_INFO, 0); ssh_set_log_callback(ssh_log_function); @@ -411,7 +416,7 @@ static ssh_bind prepare_ssh(const char *keys_dir, const char *bind_addr, int por if (ssh_bind_listen(bind) < 0) tmate_fatal("Error listening to socket: %s\n", ssh_get_error(bind)); - tmate_notice("Accepting connections on %s:%d", bind_addr ?: "", port); + tmate_info("Accepting connections on %s:%d", bind_addr ?: "", port); return bind; } @@ -428,18 +433,18 @@ static void handle_sigchld(__unused int sig) */ #if 0 if (WIFEXITED(status)) - tmate_info("Child %d exited (%d)", pid, WEXITSTATUS(status)); + tmate_debug("Child %d exited (%d)", pid, WEXITSTATUS(status)); if (WIFSIGNALED(status)) - tmate_info("Child %d killed (%d)", pid, WTERMSIG(status)); + tmate_debug("Child %d killed (%d)", pid, WTERMSIG(status)); if (WIFSTOPPED(status)) - tmate_info("Child %d stopped (%d)", pid, WSTOPSIG(status)); + tmate_debug("Child %d stopped (%d)", pid, WSTOPSIG(status)); #endif } } static void handle_sigsegv(__unused int sig) { - tmate_crit("CRASH, printing stack trace"); + tmate_info("CRASH, printing stack trace"); tmate_print_stack_trace(); tmate_fatal("CRASHED"); } @@ -485,10 +490,14 @@ void tmate_ssh_server_main(struct tmate_session *session, const char *keys_dir, signal(SIGALRM, handle_sigalrm); alarm(TMATE_SSH_GRACE_PERIOD); - if (get_client_ip(fd, client->ip_address, sizeof(client->ip_address)) < 0) - tmate_fatal("Error getting client IP from connection"); + if (get_client_ip(fd, client->ip_address, sizeof(client->ip_address)) < 0) { + if (tmate_settings->use_proxy_protocol) + tmate_fatal("Proxy header invalid. Load balancer may be misconfigured"); + else + tmate_fatal("Error getting client IP from connection"); + } - tmate_info("Connection accepted ip=%s", client->ip_address); + tmate_debug("Connection accepted ip=%s", client->ip_address); if (ssh_bind_accept_fd(bind, client->session, fd) < 0) tmate_fatal("Error accepting connection: %s", ssh_get_error(bind)); diff --git a/tmate-websocket.c b/tmate-websocket.c index eed4145b..d390e109 100644 --- a/tmate-websocket.c +++ b/tmate-websocket.c @@ -197,7 +197,7 @@ static void tmate_dispatch_websocket_message(struct tmate_session *session, dispatch(TMATE_CTL_RESIZE, ctl_resize); dispatch(TMATE_CTL_EXEC_RESPONSE, ctl_ssh_exec_response); dispatch(TMATE_CTL_RENAME_SESSION, ctl_rename_session); - default: tmate_warn("Bad websocket server message type: %d", cmd); + default: tmate_info("Bad websocket server message type: %d", cmd); } } @@ -237,6 +237,9 @@ void tmate_notify_client_join(__unused struct tmate_session *session, void tmate_notify_client_left(__unused struct tmate_session *session, struct client *c) { + if (!(c->flags & CLIENT_IDENTIFIED)) + return; + tmate_info("Client left (cid=%d)", c->id); if (!tmate_has_websocket()) @@ -410,7 +413,7 @@ static int _tmate_connect_to_websocket(const char *hostname, int port) if (fcntl(sockfd, F_SETFL, O_NONBLOCK) < 0) tmate_fatal("Can't set websocket server socket to non-blocking"); - tmate_info("Connected to websocket server at %s:%d", hostname, port); + tmate_debug("Connected to websocket server at %s:%d", hostname, port); return sockfd; } diff --git a/tmate.h b/tmate.h index 71bdcdd6..d11a7d14 100644 --- a/tmate.h +++ b/tmate.h @@ -1,7 +1,6 @@ #ifndef TMATE_H #define TMATE_H -#include #include #include #include @@ -14,24 +13,10 @@ struct tmate_session; /* log.c */ -extern void init_logging(const char *program_name, bool use_syslog, int log_level); -extern void printflike(2, 3) tmate_log(int level, const char *msg, ...); - -#define tmate_debug(str, ...) tmate_log(LOG_DEBUG, str, ##__VA_ARGS__) -#define tmate_info(str, ...) tmate_log(LOG_INFO, str, ##__VA_ARGS__) -#define tmate_notice(str, ...) tmate_log(LOG_NOTICE, str, ##__VA_ARGS__) -#define tmate_warn(str, ...) tmate_log(LOG_WARNING, str, ##__VA_ARGS__) -#define tmate_crit(str, ...) tmate_log(LOG_CRIT, str, ##__VA_ARGS__) -#define tmate_fatal(str, ...) \ -({ \ - tmate_crit("fatal: " str, ##__VA_ARGS__); \ - exit(1); \ -}) -#define tmate_fatal_info(str, ...) \ -({ \ - tmate_info("fatal: " str, ##__VA_ARGS__); \ - exit(1); \ -}) +#define tmate_debug(...) log_emit(LOG_DEBUG, __VA_ARGS__) +#define tmate_info(...) log_emit(LOG_INFO, __VA_ARGS__) +#define tmate_fatal(...) fatalx( __VA_ARGS__) +#define tmate_fatal_quiet(...) ({tmate_debug(__VA_ARGS__); exit(1);}) /* tmate-auth-keys.c */ extern void tmate_hook_set_option_auth(const char *name, const char *val); @@ -217,7 +202,6 @@ struct tmate_settings { const char *bind_addr; int log_level; bool use_proxy_protocol; - bool use_syslog; }; extern struct tmate_settings *tmate_settings; diff --git a/tmux.h b/tmux.h index 53ee8234..c8c9a7be 100644 --- a/tmux.h +++ b/tmux.h @@ -2386,7 +2386,13 @@ void log_add_level(void); int log_get_level(void); void log_open(const char *); void log_close(void); -void printflike(1, 2) log_debug(const char *, ...); +#define LOG_ERROR 0 +#define LOG_INFO 1 +#define LOG_DEBUG 2 +#define log_debug(...) log_emit(LOG_DEBUG+1, __VA_ARGS__) +void init_logging(int log_level); +void set_log_prefix(char *_log_prefix); +void printflike(2, 3) log_emit(int level, const char *, ...); __dead void printflike(1, 2) fatal(const char *, ...); __dead void printflike(1, 2) fatalx(const char *, ...);