Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Jun 2004 16:22:47 +0200 (CEST)
From:      Rene de Vries <rene@tunix.nl>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/68328: enable configuration of extra listen sockets in syslog.conf
Message-ID:  <200406251422.i5PEMlLN064801@upsilix.tunix.nl>
Resent-Message-ID: <200406251430.i5PEUMm0071026@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         68328
>Category:       bin
>Synopsis:       enable configuration of extra listen sockets in syslog.conf
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jun 25 14:30:22 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Rene de Vries
>Release:        FreeBSD 4.8 i386
>Organization:
Tunix Internet Security & Training
>Environment:
System: FreeBSD upsilix.tunix.nl 4.8 FreeBSD 4.8-RELEASE-p16 #7: Wed Mar 3 15:00:31 CET 2004 rene@upsilix.tunix.nl:/usr/obj/usr/src/sys/UPSILIX i386

>Description:
	Allow the user to configure extra listen sockets in
	/etc/syslog.conf. Upon soft restart (SIGHUP) these lines
	are read and new sockets are created (and old ones removed).
	Each line starting with a '=' defines a socket.

Example "/etc/syslog.conf":

# syslog.conf
=/jail/one/var/run/log
*.err;kern.debug;auth.notice;mail.crit          /dev/console
*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err /var/log/messages

Diff against 4.8:

Index: usr.sbin/syslogd/syslogd.c
===================================================================
RCS file: usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.1.1.6
retrieving revision 1.3
diff -u -r1.1.1.6 -r1.3
--- usr.sbin/syslogd/syslogd.c	2003/04/17 15:45:56	1.1.1.6
+++ usr.sbin/syslogd/syslogd.c	2004/04/05 12:51:34	1.3
@@ -128,9 +128,10 @@
 
 #define MAXUNAMES	20	/* maximum number of user names */
 
-#define MAXFUNIX       20
+#define MAXFUNIX       64
 
 int nfunix = 1;
+int nfunix_cmdline = 1;
 const char *funixn[MAXFUNIX] = { _PATH_LOG };
 int funix[MAXFUNIX];
 
@@ -366,9 +367,10 @@
 			KeepKernFac = 1;
 			break;
 		case 'l':
-			if (nfunix < MAXFUNIX)
-				funixn[nfunix++] = optarg;
-			else
+			if (nfunix < MAXFUNIX) {
+				funixn[nfunix++] = strdup(optarg);
+				nfunix_cmdline = nfunix;
+			} else
 				warnx("out of descriptors, ignoring %s",
 					optarg);
 			break;
@@ -379,7 +381,7 @@
 			resolve = 0;
 			break;
 		case 'p':		/* path */
-			funixn[0] = optarg;
+			funixn[0] = strdup(optarg);
 			break;
 		case 'P':		/* path for alt. PID */
 			PidFile = optarg;
@@ -1117,7 +1119,12 @@
 					    f->f_un.f_pipe.f_pname);
 			f->f_un.f_pipe.f_pid = 0;
 			errno = e;
-			logerror(f->f_un.f_pipe.f_pname);
+			/* if the error is EAGAIN, writev() failed to write to
+			 * the non-blocking pipe, which is a rather harmless
+			 * situation: silently ignore this.
+			 */
+			if ( errno != EAGAIN )
+				logerror(f->f_un.f_pipe.f_pname);
 		}
 		break;
 
@@ -1407,6 +1414,15 @@
 	Files = NULL;
 	nextp = &Files;
 
+	/* close nfunix syslog.conf sockets */
+	for (i = nfunix_cmdline; i < nfunix; i++) {
+		dprintf("closing log socket on %s\n", funixn[i]);
+		unlink(funixn[i]);
+		close(funix[i]);
+		free(funixn[i]);
+	}
+	nfunix = nfunix_cmdline;
+
 	/* open the configuration file */
 	if ((cf = fopen(ConfFile, "r")) == NULL) {
 		dprintf("cannot open %s\n", ConfFile);
@@ -1478,6 +1494,45 @@
 				prog[i] = p[i];
 			}
 			prog[i] = 0;
+			continue;
+		}
+		if (*p == '=') {
+			/* listen on */
+			if (nfunix < MAXFUNIX) {
+				char *e;
+				struct sockaddr_un sunx;
+				for (e = p; *e != '\0'; e++) {
+					if ((*e == '\r') || (*e == '\n')) {
+						*e = '\0';
+						break;
+					}
+				}
+				dprintf("opening log socket on %s\n", p+1);
+				funixn[nfunix] = strdup(p+1);
+				(void)unlink(funixn[nfunix]);
+				memset(&sunx, 0, sizeof(sunx));
+				sunx.sun_family = AF_UNIX;
+				(void)strlcpy(sunx.sun_path,
+					funixn[nfunix], sizeof(sunx.sun_path));
+				funix[nfunix] = socket(AF_UNIX, SOCK_DGRAM, 0);
+				if (funix[nfunix] < 0 ||
+				    bind(funix[nfunix],
+					 (struct sockaddr *)&sunx,
+					 SUN_LEN(&sunx)) < 0 ||
+				    chmod(funixn[nfunix], 0666) < 0) {
+					char line[256];
+					(void)snprintf(line, sizeof line,
+						"cannot create %s",
+						funixn[nfunix]);
+					logerror(line);
+					free(funixn[nfunix]);
+				} else nfunix++;
+			} else {
+				char line[256];
+				(void)snprintf(line, sizeof line,
+					"out of descriptors, ignoring %s", p);
+				logerror(line);
+			}
 			continue;
 		}
 		for (p = strchr(cline, '\0'); isspace(*--p);)
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200406251422.i5PEMlLN064801>