summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-05-25 08:28:11 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-05-25 08:28:11 +0000
commit901172262afa9f37f2f6ba043f387ecb39830288 (patch)
tree795596f2513c2d598be81a48194e9d6f562f467e /usr.bin
parent3f0f03c8ee809caa8c707c7f696453806e4779fe (diff)
Simplify logging and just fprintf(stderr, ...) for early errors.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/client.c12
-rw-r--r--usr.bin/tmux/log.c77
-rw-r--r--usr.bin/tmux/tmux.c8
-rw-r--r--usr.bin/tmux/tmux.h5
4 files changed, 32 insertions, 70 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c
index ffbf4e2b481..1e6338d560e 100644
--- a/usr.bin/tmux/client.c
+++ b/usr.bin/tmux/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.54 2012/05/21 18:27:42 nicm Exp $ */
+/* $OpenBSD: client.c,v 1.55 2012/05/25 08:28:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -209,15 +209,15 @@ client_main(int argc, char **argv, int flags)
if (shell_cmd == NULL && environ_path != NULL &&
(cmdflags & CMD_CANTNEST) &&
strcmp(socket_path, environ_path) == 0) {
- log_warnx("sessions should be nested with care. "
- "unset $TMUX to force.");
+ fprintf(stderr, "sessions should be nested with care, "
+ "unset $TMUX to force\n");
return (1);
}
/* Initialise the client socket and start the server. */
fd = client_connect(socket_path, cmdflags & CMD_STARTSERVER);
if (fd == -1) {
- log_warn("failed to connect to server");
+ fprintf(stderr, "failed to connect to server\n");
return (1);
}
@@ -252,7 +252,7 @@ client_main(int argc, char **argv, int flags)
cmddata.argc = argc;
if (cmd_pack_argv(
argc, argv, cmddata.argv, sizeof cmddata.argv) != 0) {
- log_warnx("command too long");
+ fprintf(stderr, "command too long\n");
return (1);
}
@@ -538,7 +538,7 @@ client_dispatch_attached(void)
return (0);
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
- log_debug("client got %d", imsg.hdr.type);
+ log_debug("got %d from server", imsg.hdr.type);
switch (imsg.hdr.type) {
case MSG_DETACHKILL:
case MSG_DETACH:
diff --git a/usr.bin/tmux/log.c b/usr.bin/tmux/log.c
index cade075ccf8..73cffde98de 100644
--- a/usr.bin/tmux/log.c
+++ b/usr.bin/tmux/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.6 2012/03/17 18:38:58 nicm Exp $ */
+/* $OpenBSD: log.c,v 1.7 2012/05/25 08:28:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,20 +27,14 @@
#include "tmux.h"
-/* Logging type. */
-#define LOG_TYPE_OFF 0
-#define LOG_TYPE_TTY 1
-#define LOG_TYPE_FILE 2
-int log_type = LOG_TYPE_OFF;
-
/* Log file, if needed. */
-FILE *log_file;
+FILE *log_file = stderr;
/* Debug level. */
-int log_level;
+int log_level = 0;
void log_event_cb(int, const char *);
-void log_vwrite(int, const char *, va_list);
+void log_vwrite(const char *, va_list);
__dead void log_vfatal(const char *, va_list);
/* Log callback for libevent. */
@@ -50,29 +44,13 @@ log_event_cb(unused int severity, const char *msg)
log_warnx("%s", msg);
}
-/* Open logging to tty. */
-void
-log_open_tty(int level)
-{
- log_type = LOG_TYPE_TTY;
- log_level = level;
-
- setlinebuf(stderr);
- setlinebuf(stdout);
- event_set_log_callback(log_event_cb);
-
- tzset();
-}
-
/* Open logging to file. */
void
-log_open_file(int level, const char *path)
+log_open(int level, const char *path)
{
log_file = fopen(path, "w");
if (log_file == NULL)
return;
-
- log_type = LOG_TYPE_FILE;
log_level = level;
setlinebuf(log_file);
@@ -85,37 +63,24 @@ log_open_file(int level, const char *path)
void
log_close(void)
{
- if (log_type == LOG_TYPE_FILE)
+ if (log_file != stderr)
fclose(log_file);
event_set_log_callback(NULL);
-
- log_type = LOG_TYPE_OFF;
}
/* Write a log message. */
void
-log_vwrite(int pri, const char *msg, va_list ap)
+log_vwrite(const char *msg, va_list ap)
{
char *fmt;
- FILE *f = log_file;
-
- switch (log_type) {
- case LOG_TYPE_TTY:
- if (pri == LOG_INFO)
- f = stdout;
- else
- f = stderr;
- /* FALLTHROUGH */
- case LOG_TYPE_FILE:
- if (asprintf(&fmt, "%s\n", msg) == -1)
- exit(1);
- if (vfprintf(f, fmt, ap) == -1)
- exit(1);
- fflush(f);
- free(fmt);
- break;
- }
+
+ if (asprintf(&fmt, "%s\n", msg) == -1)
+ exit(1);
+ if (vfprintf(log_file, fmt, ap) == -1)
+ exit(1);
+ fflush(log_file);
+ free(fmt);
}
/* Log a warning with error string. */
@@ -128,7 +93,7 @@ log_warn(const char *msg, ...)
va_start(ap, msg);
if (asprintf(&fmt, "%s: %s", msg, strerror(errno)) == -1)
exit(1);
- log_vwrite(LOG_CRIT, fmt, ap);
+ log_vwrite(fmt, ap);
free(fmt);
va_end(ap);
}
@@ -140,7 +105,7 @@ log_warnx(const char *msg, ...)
va_list ap;
va_start(ap, msg);
- log_vwrite(LOG_CRIT, msg, ap);
+ log_vwrite(msg, ap);
va_end(ap);
}
@@ -152,7 +117,7 @@ log_info(const char *msg, ...)
if (log_level > -1) {
va_start(ap, msg);
- log_vwrite(LOG_INFO, msg, ap);
+ log_vwrite(msg, ap);
va_end(ap);
}
}
@@ -165,7 +130,7 @@ log_debug(const char *msg, ...)
if (log_level > 0) {
va_start(ap, msg);
- log_vwrite(LOG_DEBUG, msg, ap);
+ log_vwrite(msg, ap);
va_end(ap);
}
}
@@ -178,7 +143,7 @@ log_debug2(const char *msg, ...)
if (log_level > 1) {
va_start(ap, msg);
- log_vwrite(LOG_DEBUG, msg, ap);
+ log_vwrite(msg, ap);
va_end(ap);
}
}
@@ -192,11 +157,11 @@ log_vfatal(const char *msg, va_list ap)
if (errno != 0) {
if (asprintf(&fmt, "fatal: %s: %s", msg, strerror(errno)) == -1)
exit(1);
- log_vwrite(LOG_CRIT, fmt, ap);
+ log_vwrite(fmt, ap);
} else {
if (asprintf(&fmt, "fatal: %s", msg) == -1)
exit(1);
- log_vwrite(LOG_CRIT, fmt, ap);
+ log_vwrite(fmt, ap);
}
free(fmt);
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 1cb7364f11c..fd8b7b5d633 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.108 2012/01/21 08:40:09 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.109 2012/05/25 08:28:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -73,7 +73,7 @@ logfile(const char *name)
log_close();
if (debug_level > 0) {
xasprintf(&path, "tmux-%s-%ld.log", name, (long) getpid());
- log_open_file(debug_level, path);
+ log_open(debug_level, path);
xfree(path);
}
}
@@ -294,8 +294,6 @@ main(int argc, char **argv)
if (shell_cmd != NULL && argc != 0)
usage();
- log_open_tty(debug_level);
-
if (!(flags & IDENTIFY_UTF8)) {
/*
* If the user has set whichever of LC_ALL, LC_CTYPE or LANG
@@ -379,7 +377,7 @@ main(int argc, char **argv)
/* -L or default set. */
if (label != NULL) {
if ((path = makesocketpath(label)) == NULL) {
- log_warn("can't create socket");
+ fprintf(stderr, "can't create socket\n");
exit(1);
}
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 16e44e6e58c..70165787fd5 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.338 2012/05/23 19:19:40 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.339 2012/05/25 08:28:10 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -2181,8 +2181,7 @@ char *get_proc_name(int, char *);
char *get_proc_cwd(pid_t);
/* log.c */
-void log_open_tty(int);
-void log_open_file(int, const char *);
+void log_open(int, const char *);
void log_close(void);
void printflike1 log_warn(const char *, ...);
void printflike1 log_warnx(const char *, ...);