add log syslog off; don't turn syslog off when log access is specified

This commit is contained in:
Omar Polo 2023-07-26 08:10:12 +00:00
parent cba01a8687
commit 46bcc4ea95
6 changed files with 23 additions and 6 deletions

View File

@ -44,6 +44,7 @@ config_new(void)
init_mime(&conf->mime);
conf->prefork = 3;
conf->log_syslog = 1;
#ifdef __OpenBSD__
conf->use_privsep_crypto = 1;
@ -148,6 +149,7 @@ config_purge(struct conf *conf)
conf->ps = ps;
conf->use_privsep_crypto = use_privsep_crypto;
conf->protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
conf->log_syslog = 1;
init_mime(&conf->mime);
TAILQ_INIT(&conf->fcgi);
TAILQ_INIT(&conf->hosts);

3
gmid.c
View File

@ -408,6 +408,9 @@ main_send_logfd(struct conf *conf)
if (proc_compose_imsg(ps, PROC_LOGGER, -1, IMSG_LOG_ACCESS, -1, fd,
NULL, 0) == -1)
return -1;
if (proc_compose_imsg(ps, PROC_LOGGER, -1, IMSG_LOG_SYSLOG, -1, -1,
&conf->log_syslog, sizeof(conf->log_syslog)) == -1)
return -1;
return 0;
}

View File

@ -134,9 +134,11 @@ Specify logging options.
Multiple options may be provided within curly braces.
The available options are as follows:
.Bl -tag -width Ds
.It Ic syslog
.It Ic syslog Op Ic off
Log to syslog.
This is the default behaviour.
It is enabled by default, use the
.Ic off
argument to disable.
.It Ic access Ar file
Log the requests to
.Ar file .

2
gmid.h
View File

@ -248,6 +248,7 @@ struct conf {
char user[LOGIN_NAME_MAX];
int prefork;
int reload;
int log_syslog;
char *log_access;
enum log_format log_format;
int use_privsep_crypto;
@ -330,6 +331,7 @@ struct connreq {
enum imsg_type {
IMSG_LOG_REQUEST,
IMSG_LOG_ACCESS,
IMSG_LOG_SYSLOG,
IMSG_RECONF_START,
IMSG_RECONF_MIME,

View File

@ -38,6 +38,7 @@
#endif
static int logfd = -1;
static int log_to_syslog = 1;
static void logger_init(struct privsep *, struct privsep_proc *, void *);
static void logger_shutdown(void);
@ -74,6 +75,11 @@ static int
logger_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
{
switch (imsg->hdr.type) {
case IMSG_LOG_SYSLOG:
if (IMSG_DATA_SIZE(imsg) != sizeof(log_to_syslog))
fatal("corrupted IMSG_LOG_SYSLOG");
memcpy(&log_to_syslog, imsg->data, sizeof(log_to_syslog));
break;
case IMSG_LOG_ACCESS:
if (logfd != -1)
close(logfd);
@ -104,7 +110,7 @@ logger_dispatch_server(int fd, struct privsep_proc *p, struct imsg *imsg)
msg[datalen - 1] = '\0';
if (logfd != -1)
dprintf(logfd, "%s\n", msg);
else
if (log_to_syslog)
syslog(LOG_DAEMON | LOG_NOTICE, "%s", msg);
break;
default:

View File

@ -260,9 +260,11 @@ logopts : /* empty */
| logopts logopt optnl
;
logopt : SYSLOG {
free(conf->log_access);
conf->log_access = NULL;
logopt : SYSLOG OFF {
conf->log_syslog = 0;
}
| SYSLOG {
conf->log_syslog = 1;
}
| ACCESS string {
free(conf->log_access);