Commit Diff


commit - 3a93c90445bc762cbef00d130feffd9a7f6b083f
commit + 9abba172b6f9ff373dd1e45d7b9587d3bdd0afcf
blob - d9c5f32a2a7d81c4ca3d9c4179c11c39a2b5d74c
blob + e27d0796da5bdea0b04c358c7ce510a80fc41302
--- config.c
+++ config.c
@@ -21,6 +21,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <string.h>
+#include <syslog.h>
 
 #include <openssl/pem.h>
 
@@ -45,6 +46,7 @@ config_new(void)
 
 	conf->prefork = 3;
 	conf->log_syslog = 1;
+	conf->log_facility = LOG_DAEMON;
 	conf->log_format = LOG_FORMAT_LEGACY;
 
 #ifdef __OpenBSD__
@@ -152,6 +154,7 @@ config_purge(struct conf *conf)
 	conf->use_privsep_crypto = use_privsep_crypto;
 	conf->protos = TLS_PROTOCOL_TLSv1_2 | TLS_PROTOCOL_TLSv1_3;
 	conf->log_syslog = 1;
+	conf->log_facility = LOG_DAEMON;
 	conf->log_format = log_format;
 	init_mime(&conf->mime);
 	TAILQ_INIT(&conf->fcgi);
blob - 658f961a0e2727e1cc33a35015a89b666e677564
blob + 360feba7e9a21eb868b0f782f84d8bf62b90120c
--- gmid.c
+++ gmid.c
@@ -411,6 +411,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_FACILITY, -1, -1,
+	    &conf->log_facility, sizeof(conf->log_facility)) == -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;
blob - f49b7dfe4ebbe3032137b0e571e142cc0a6f999b
blob + 7ae413926ec910f018b5155d1efaab8ac891ae79
--- gmid.conf.5
+++ gmid.conf.5
@@ -190,6 +190,18 @@ Log to syslog.
 It is enabled by default, use the
 .Ic off
 argument to disable.
+.It Ic syslog facility Ar facility
+Log to
+.Xr syslog 3
+using specified
+.Ar facility .
+Available facilities are as follows: daemon, ftp, local0 through local7 and
+user.
+These are case insensitive and can be prefixed with
+.Sq LOG_ .
+Not all level may be available on all operating systems.
+The default facility is
+.Ev LOG_DAEMON .
 .El
 .It Ic prefork Ar number
 Run the specified number of server processes.
blob - 0ff9f6b47acd247834136d1fb386f7932d48a2d1
blob + a29cfe44ea2f325c167cc7f725a3194c35688746
--- gmid.h
+++ gmid.h
@@ -249,6 +249,7 @@ struct conf {
 	int		 prefork;
 	int		 reload;
 	int		 log_syslog;
+	int		 log_facility;
 	char		*log_access;
 	enum log_format	 log_format;
 	int		 use_privsep_crypto;
@@ -332,6 +333,7 @@ enum imsg_type {
 	IMSG_LOG_REQUEST,
 	IMSG_LOG_ACCESS,
 	IMSG_LOG_SYSLOG,
+	IMSG_LOG_FACILITY,
 
 	IMSG_RECONF_START,
 	IMSG_RECONF_LOG_FMT,
blob - d0e25c9daab970a58ac13056b4a90ae85fc6f801
blob + 7949bd50a2649599e7a4832b765ac7bc043c0509
--- logger.c
+++ logger.c
@@ -39,6 +39,7 @@
 
 static int logfd = -1;
 static int log_to_syslog = 1;
+static int facility = LOG_DAEMON;
 
 static void logger_init(struct privsep *, struct privsep_proc *, void *);
 static void logger_shutdown(void);
@@ -75,6 +76,11 @@ static int
 logger_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
 {
 	switch (imsg->hdr.type) {
+	case IMSG_LOG_FACILITY:
+		if (IMSG_DATA_SIZE(imsg) != sizeof(facility))
+			fatal("corrupted IMSG_LOG_SYSLOG");
+		memcpy(&facility, imsg->data, sizeof(facility));
+		break;
 	case IMSG_LOG_SYSLOG:
 		if (IMSG_DATA_SIZE(imsg) != sizeof(log_to_syslog))
 			fatal("corrupted IMSG_LOG_SYSLOG");
@@ -111,7 +117,7 @@ logger_dispatch_server(int fd, struct privsep_proc *p,
 		if (logfd != -1)
 			dprintf(logfd, "%s\n", msg);
 		if (log_to_syslog)
-			syslog(LOG_DAEMON | LOG_NOTICE, "%s", msg);
+			syslog(facility | LOG_NOTICE, "%s", msg);
 		break;
 	default:
 		return -1;
blob - cd3510d44bf943eeb6fd6ff702abb9ae2f4e3ca4
blob + 82c9cbcad81cfe5862d7a72478c994d368ee468f
--- parse.y
+++ parse.y
@@ -32,6 +32,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <syslog.h>
 
 #include "log.h"
 
@@ -126,7 +127,7 @@ typedef struct {
 %token	BLOCK
 %token	CA CERT CHROOT CLIENT COMBINED COMMON CONDENSED
 %token	DEFAULT
-%token	FASTCGI FOR_HOST
+%token	FACILITY FASTCGI FOR_HOST
 %token	INCLUDE INDEX IPV6
 %token	KEY
 %token	LANG LEGACY LISTEN LOCATION LOG
@@ -275,6 +276,42 @@ logopt		: ACCESS string		{
 		}
 		| STYLE LEGACY		{
 			conf->log_format = LOG_FORMAT_LEGACY;
+		}
+		| SYSLOG FACILITY string {
+			const char *str = $3;
+
+			conf->log_syslog = 1;
+
+			if (!strncasecmp(str, "LOG_", 4))
+				str += 4;
+
+			if (!strcasecmp(str, "daemon"))
+				conf->log_facility = LOG_DAEMON;
+#ifdef LOG_FTP
+			else if (!strcasecmp(str, "ftp"))
+				conf->log_facility = LOG_FTP;
+#endif
+			else if (!strcasecmp(str, "local1"))
+				conf->log_facility = LOG_LOCAL1;
+			else if (!strcasecmp(str, "local2"))
+				conf->log_facility = LOG_LOCAL2;
+			else if (!strcasecmp(str, "local3"))
+				conf->log_facility = LOG_LOCAL3;
+			else if (!strcasecmp(str, "local4"))
+				conf->log_facility = LOG_LOCAL4;
+			else if (!strcasecmp(str, "local5"))
+				conf->log_facility = LOG_LOCAL5;
+			else if (!strcasecmp(str, "local6"))
+				conf->log_facility = LOG_LOCAL6;
+			else if (!strcasecmp(str, "local7"))
+				conf->log_facility = LOG_LOCAL7;
+			else if (!strcasecmp(str, "user"))
+				conf->log_facility = LOG_USER;
+			else
+				yywarn("unknown syslog facility `%s'",
+				    $3);
+
+			free($3);
 		}
 		| SYSLOG OFF		{
 			conf->log_syslog = 0;
@@ -621,6 +658,7 @@ static const struct keyword {
 	{"common", COMMON},
 	{"condensed", CONDENSED},
 	{"default", DEFAULT},
+	{"facility", FACILITY},
 	{"fastcgi", FASTCGI},
 	{"for-host", FOR_HOST},
 	{"include", INCLUDE},