Changeset View
Changeset View
Standalone View
Standalone View
log.c
/* $OpenBSD: log.c,v 1.51 2018/07/27 12:03:17 markus Exp $ */ | /* $OpenBSD: log.c,v 1.52 2020/07/03 06:46:41 djm Exp $ */ | ||||
/* | /* | ||||
* Author: Tatu Ylonen <ylo@cs.hut.fi> | * Author: Tatu Ylonen <ylo@cs.hut.fi> | ||||
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | ||||
* All rights reserved | * All rights reserved | ||||
* | * | ||||
* As far as I am concerned, the code I have written for this software | * As far as I am concerned, the code I have written for this software | ||||
* can be used freely for any purpose. Any derived versions of this | * can be used freely for any purpose. Any derived versions of this | ||||
* software must be clearly marked as such, and if the derived work is | * software must be clearly marked as such, and if the derived work is | ||||
▲ Show 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | log_is_on_stderr(void) | ||||
return log_on_stderr && log_stderr_fd == STDERR_FILENO; | return log_on_stderr && log_stderr_fd == STDERR_FILENO; | ||||
} | } | ||||
/* redirect what would usually get written to stderr to specified file */ | /* redirect what would usually get written to stderr to specified file */ | ||||
void | void | ||||
log_redirect_stderr_to(const char *logfile) | log_redirect_stderr_to(const char *logfile) | ||||
{ | { | ||||
int fd; | int fd; | ||||
if (logfile == NULL) { | |||||
if (log_stderr_fd != STDERR_FILENO) { | |||||
close(log_stderr_fd); | |||||
log_stderr_fd = STDERR_FILENO; | |||||
} | |||||
return; | |||||
} | |||||
if ((fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0600)) == -1) { | if ((fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0600)) == -1) { | ||||
fprintf(stderr, "Couldn't open logfile %s: %s\n", logfile, | fprintf(stderr, "Couldn't open logfile %s: %s\n", logfile, | ||||
strerror(errno)); | strerror(errno)); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
log_stderr_fd = fd; | log_stderr_fd = fd; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |