diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-11-24 21:19:47 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2015-11-24 21:19:47 +0000 |
commit | 78f27fe459376e790db79833621e7889ed8f90a3 (patch) | |
tree | e0edfcbd72115c8599956fcf5d59536b9743a5f1 | |
parent | 3bb8736a035231461532fc3569b67eb3f792bf89 (diff) |
Make the log stuff a bit tidier with some helper functions.
-rw-r--r-- | usr.bin/tmux/cmd-show-messages.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/log.c | 37 | ||||
-rw-r--r-- | usr.bin/tmux/proc.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/server.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.c | 17 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 10 |
6 files changed, 42 insertions, 33 deletions
diff --git a/usr.bin/tmux/cmd-show-messages.c b/usr.bin/tmux/cmd-show-messages.c index de1b7cf5410..5f5273f4045 100644 --- a/usr.bin/tmux/cmd-show-messages.c +++ b/usr.bin/tmux/cmd-show-messages.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-show-messages.c,v 1.13 2015/07/28 15:18:10 nicm Exp $ */ +/* $OpenBSD: cmd-show-messages.c,v 1.14 2015/11/24 21:19:46 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -61,7 +61,6 @@ cmd_show_messages_server(struct cmd_q *cmdq) cmdq_print(cmdq, "started %s", tim); cmdq_print(cmdq, "socket path %s", socket_path); - cmdq_print(cmdq, "debug level %d", debug_level); cmdq_print(cmdq, "protocol version %d", PROTOCOL_VERSION); return (1); diff --git a/usr.bin/tmux/log.c b/usr.bin/tmux/log.c index f89cd7c73cb..4e1a25df012 100644 --- a/usr.bin/tmux/log.c +++ b/usr.bin/tmux/log.c @@ -1,4 +1,4 @@ -/* $OpenBSD: log.c,v 1.19 2015/11/18 14:27:44 nicm Exp $ */ +/* $OpenBSD: log.c,v 1.20 2015/11/24 21:19:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -22,30 +22,53 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <vis.h> #include "tmux.h" -FILE *log_file; +static FILE *log_file; +static int log_level; -void log_event_cb(int, const char *); -void log_vwrite(const char *, va_list); +static void log_event_cb(int, const char *); +static void log_vwrite(const char *, va_list); /* Log callback for libevent. */ -void +static void log_event_cb(__unused int severity, const char *msg) { log_debug("%s", msg); } +/* Increment log level. */ +void +log_add_level(void) +{ + log_level++; +} + +/* Get log level. */ +int +log_get_level(void) +{ + return (log_level); +} + /* Open logging to file. */ void -log_open(const char *path) +log_open(const char *name) { + char *path; + + if (log_level == 0) + return; + if (log_file != NULL) fclose(log_file); + xasprintf(&path, "tmux-%s-%ld.log", name, (long)getpid()); log_file = fopen(path, "w"); + free(path); if (log_file == NULL) return; @@ -65,7 +88,7 @@ log_close(void) } /* Write a log message. */ -void +static void log_vwrite(const char *msg, va_list ap) { char *fmt, *out; diff --git a/usr.bin/tmux/proc.c b/usr.bin/tmux/proc.c index 9ba65c04f88..68decb66aef 100644 --- a/usr.bin/tmux/proc.c +++ b/usr.bin/tmux/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.4 2015/11/18 14:27:44 nicm Exp $ */ +/* $OpenBSD: proc.c,v 1.5 2015/11/24 21:19:46 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@users.sourceforge.net> @@ -188,7 +188,7 @@ proc_start(const char *name, struct event_base *base, int forkflag, fatalx("event_reinit failed"); } - logfile(name); + log_open(name); setproctitle("%s (%s)", name, socket_path); log_debug("%s started (%ld): socket %s, protocol %d", name, diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index 6f1fd4cf42d..657d77beca2 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.151 2015/11/22 19:41:19 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.152 2015/11/24 21:19:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -173,7 +173,7 @@ server_start(struct event_base *base, int lockfd, char *lockfile) } close(pair[0]); - if (debug_level > 3) + if (log_get_level() > 3) tty_create_log(); if (pledge("stdio rpath wpath cpath fattr unix getpw recvfd proc exec " "tty ps", NULL) != 0) diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 14c6e44dfdb..af6fec24308 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.156 2015/11/22 19:41:19 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.157 2015/11/24 21:19:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -44,7 +44,6 @@ struct options *global_w_options; /* window options */ struct environ *global_environ; char *shell_cmd; -int debug_level; time_t start_time; char socket_path[PATH_MAX]; @@ -61,18 +60,6 @@ usage(void) exit(1); } -void -logfile(const char *name) -{ - char *path; - - if (debug_level > 0) { - xasprintf(&path, "tmux-%s-%ld.log", name, (long) getpid()); - log_open(path); - free(path); - } -} - const char * getshell(void) { @@ -243,7 +230,7 @@ main(int argc, char **argv) flags |= CLIENT_UTF8; break; case 'v': - debug_level++; + log_add_level(); break; default: usage(); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index b14354e9574..5da1311936e 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.587 2015/11/24 09:34:55 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.588 2015/11/24 21:19:46 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -1432,10 +1432,8 @@ extern struct options *global_s_options; extern struct options *global_w_options; extern struct environ *global_environ; extern char *shell_cmd; -extern int debug_level; extern time_t start_time; extern char socket_path[PATH_MAX]; -void logfile(const char *); const char *getshell(void); int checkshell(const char *); int areshell(const char *); @@ -2210,8 +2208,10 @@ char *utf8_padcstr(const char *, u_int); char *get_proc_name(int, char *); /* log.c */ -void log_open(const char *); -void log_close(void); +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 *, ...); __dead void printflike(1, 2) fatal(const char *, ...); __dead void printflike(1, 2) fatalx(const char *, ...); |