summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2021-09-16 15:11:19 +0000
committerDamien Miller <djm@mindrot.org>2021-09-19 17:21:59 +1000
commite694f8ac4409931e67d08ac44ed251b20b10a957 (patch)
tree8c5e8ccc8261faaca82acd046bd5e8304c9ebebb /log.c
parent8a7a06ee505cb833e613f74a07392e9296286c30 (diff)
upstream: allow log_stderr==2 to prefix log messages with argv[0]
use this to make scp's SFTP mode error messages more scp-like prompted by and ok deraadt@ OpenBSD-Commit-ID: 0e821dbde423fc2280e47414bdc22aaa5b4e0733
Diffstat (limited to 'log.c')
-rw-r--r--log.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/log.c b/log.c
index 42c6f9a6..99bf046a 100644
--- a/log.c
+++ b/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.59 2021/05/07 04:11:51 djm Exp $ */
+/* $OpenBSD: log.c,v 1.60 2021/09/16 15:11:19 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -346,6 +346,7 @@ do_log(LogLevel level, int force, const char *suffix, const char *fmt,
int pri = LOG_INFO;
int saved_errno = errno;
log_handler_fn *tmp_handler;
+ const char *progname = argv0 != NULL ? argv0 : __progname;
if (!force && level > log_level)
return;
@@ -403,16 +404,18 @@ do_log(LogLevel level, int force, const char *suffix, const char *fmt,
tmp_handler(level, force, fmtbuf, log_handler_ctx);
log_handler = tmp_handler;
} else if (log_on_stderr) {
- snprintf(msgbuf, sizeof msgbuf, "%.*s\r\n",
+ snprintf(msgbuf, sizeof msgbuf, "%s%s%.*s\r\n",
+ (log_on_stderr > 1) ? progname : "",
+ (log_on_stderr > 1) ? ": " : "",
(int)sizeof msgbuf - 3, fmtbuf);
(void)write(log_stderr_fd, msgbuf, strlen(msgbuf));
} else {
#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
- openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);
+ openlog_r(progname, LOG_PID, log_facility, &sdata);
syslog_r(pri, &sdata, "%.500s", fmtbuf);
closelog_r(&sdata);
#else
- openlog(argv0 ? argv0 : __progname, LOG_PID, log_facility);
+ openlog(progname, LOG_PID, log_facility);
syslog(pri, "%.500s", fmtbuf);
closelog();
#endif