From: djm Date: Thu, 16 Sep 2021 15:11:19 +0000 (+0000) Subject: allow log_stderr==2 to prefix log messages with argv[0] X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=6862aa31a417de6e89e213dc6048c74561bc3f39;p=openbsd 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@ --- diff --git a/usr.bin/ssh/log.c b/usr.bin/ssh/log.c index c9e4b60fff1..dd704437a9e 100644 --- a/usr.bin/ssh/log.c +++ b/usr.bin/ssh/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 * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -311,6 +311,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; @@ -367,11 +368,13 @@ 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 { - 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); } diff --git a/usr.bin/ssh/scp.c b/usr.bin/ssh/scp.c index 77eefaf17e9..f9fc14da1ae 100644 --- a/usr.bin/ssh/scp.c +++ b/usr.bin/ssh/scp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scp.c,v 1.234 2021/09/11 00:40:24 djm Exp $ */ +/* $OpenBSD: scp.c,v 1.235 2021/09/16 15:11:19 djm Exp $ */ /* * scp - secure remote copy. This is basically patched BSD rcp which * uses ssh to do the data transfer (instead of using rcmd). @@ -437,7 +437,7 @@ main(int argc, char **argv) newargv[n] = xstrdup(argv[n]); argv = newargv; - log_init(argv0, log_level, SYSLOG_FACILITY_USER, 1); + log_init(argv0, log_level, SYSLOG_FACILITY_USER, 2); memset(&args, '\0', sizeof(args)); memset(&remote_remote_args, '\0', sizeof(remote_remote_args)); @@ -555,7 +555,7 @@ main(int argc, char **argv) argc -= optind; argv += optind; - log_init(argv0, log_level, SYSLOG_FACILITY_USER, 1); + log_init(argv0, log_level, SYSLOG_FACILITY_USER, 2); /* Do this last because we want the user to be able to override it */ addargs(&args, "-oForwardAgent=no"); @@ -1507,10 +1507,8 @@ out: free(abs_src); free(tmp); globfree(&g); - if (err == -1) { - error("Failed to download '%s'", src); + if (err == -1) errs = 1; - } } @@ -1901,7 +1899,7 @@ out: free(tmp); globfree(&g); if (err == -1) - fatal("Failed to download file '%s'", src); + errs = 1; } int