1
0
mirror of https://github.com/tmux/tmux.git synced 2025-04-21 20:08:48 +00:00

Merge branch 'obsd-master' into master

This commit is contained in:
Thomas Adam 2021-09-10 18:01:11 +01:00
commit b28fffc0f7

35
log.c
View File

@ -98,28 +98,27 @@ log_close(void)
/* Write a log message. */ /* Write a log message. */
static void printflike(1, 0) static void printflike(1, 0)
log_vwrite(const char *msg, va_list ap) log_vwrite(const char *msg, va_list ap, const char *prefix)
{ {
char *fmt, *out; char *s, *out;
struct timeval tv; struct timeval tv;
if (log_file == NULL) if (log_file == NULL)
return; return;
if (vasprintf(&fmt, msg, ap) == -1) if (vasprintf(&s, msg, ap) == -1)
return; return;
if (stravis(&out, fmt, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL) == -1) { if (stravis(&out, s, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL) == -1) {
free(fmt); free(s);
return; return;
} }
free(s);
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
if (fprintf(log_file, "%lld.%06d %s\n", (long long)tv.tv_sec, if (fprintf(log_file, "%lld.%06d %s%s\n", (long long)tv.tv_sec,
(int)tv.tv_usec, out) != -1) (int)tv.tv_usec, prefix, out) != -1)
fflush(log_file); fflush(log_file);
free(out); free(out);
free(fmt);
} }
/* Log a debug message. */ /* Log a debug message. */
@ -132,7 +131,7 @@ log_debug(const char *msg, ...)
return; return;
va_start(ap, msg); va_start(ap, msg);
log_vwrite(msg, ap); log_vwrite(msg, ap, "");
va_end(ap); va_end(ap);
} }
@ -140,14 +139,16 @@ log_debug(const char *msg, ...)
__dead void __dead void
fatal(const char *msg, ...) fatal(const char *msg, ...)
{ {
char *fmt; char tmp[256];
va_list ap; va_list ap;
if (snprintf(tmp, sizeof tmp, "fatal: %s: ", strerror(errno)) < 0)
exit (1);
va_start(ap, msg); va_start(ap, msg);
if (asprintf(&fmt, "fatal: %s: %s", msg, strerror(errno)) == -1) log_vwrite(msg, ap, tmp);
exit(1);
log_vwrite(fmt, ap);
va_end(ap); va_end(ap);
exit(1); exit(1);
} }
@ -155,13 +156,11 @@ fatal(const char *msg, ...)
__dead void __dead void
fatalx(const char *msg, ...) fatalx(const char *msg, ...)
{ {
char *fmt;
va_list ap; va_list ap;
va_start(ap, msg); va_start(ap, msg);
if (asprintf(&fmt, "fatal: %s", msg) == -1) log_vwrite(msg, ap, "fatal: ");
exit(1);
log_vwrite(fmt, ap);
va_end(ap); va_end(ap);
exit(1); exit(1);
} }