summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2013-04-23 15:21:06 +1000
committerDamien Miller <djm@mindrot.org>2013-04-23 15:21:06 +1000
commit03d4d7e60b16f913c75382e32e136ddfa8d6485f (patch)
tree56db601b0ddcd36e27c565ce0e127330ac2de381 /log.c
parent37f1c08473b1ef2a188ee178ce2e11e841f88563 (diff)
- dtucker@cvs.openbsd.org 2013/04/07 02:10:33
[log.c log.h ssh.1 ssh.c sshd.8 sshd.c] Add -E option to ssh and sshd to append debugging logs to a specified file instead of stderr or syslog. ok markus@, man page help jmc@
Diffstat (limited to 'log.c')
-rw-r--r--log.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/log.c b/log.c
index d69154a67..81497a442 100644
--- a/log.c
+++ b/log.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: log.c,v 1.43 2012/09/06 04:37:39 dtucker Exp $ */ 1/* $OpenBSD: log.c,v 1.44 2013/04/07 02:10:33 dtucker Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -38,6 +38,7 @@
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40 40
41#include <fcntl.h>
41#include <stdarg.h> 42#include <stdarg.h>
42#include <stdio.h> 43#include <stdio.h>
43#include <stdlib.h> 44#include <stdlib.h>
@@ -54,6 +55,7 @@
54 55
55static LogLevel log_level = SYSLOG_LEVEL_INFO; 56static LogLevel log_level = SYSLOG_LEVEL_INFO;
56static int log_on_stderr = 1; 57static int log_on_stderr = 1;
58static int log_stderr_fd = STDERR_FILENO;
57static int log_facility = LOG_AUTH; 59static int log_facility = LOG_AUTH;
58static char *argv0; 60static char *argv0;
59static log_handler_fn *log_handler; 61static log_handler_fn *log_handler;
@@ -344,6 +346,20 @@ log_is_on_stderr(void)
344 return log_on_stderr; 346 return log_on_stderr;
345} 347}
346 348
349/* redirect what would usually get written to stderr to specified file */
350void
351log_redirect_stderr_to(const char *logfile)
352{
353 int fd;
354
355 if ((fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0600)) == -1) {
356 fprintf(stderr, "Couldn't open logfile %s: %s\n", logfile,
357 strerror(errno));
358 exit(1);
359 }
360 log_stderr_fd = fd;
361}
362
347#define MSGBUFSIZ 1024 363#define MSGBUFSIZ 1024
348 364
349void 365void
@@ -429,7 +445,7 @@ do_log(LogLevel level, const char *fmt, va_list args)
429 log_handler = tmp_handler; 445 log_handler = tmp_handler;
430 } else if (log_on_stderr) { 446 } else if (log_on_stderr) {
431 snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf); 447 snprintf(msgbuf, sizeof msgbuf, "%s\r\n", fmtbuf);
432 write(STDERR_FILENO, msgbuf, strlen(msgbuf)); 448 write(log_stderr_fd, msgbuf, strlen(msgbuf));
433 } else { 449 } else {
434#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT) 450#if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT)
435 openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata); 451 openlog_r(argv0 ? argv0 : __progname, LOG_PID, log_facility, &sdata);