From owner-freebsd-bugs@FreeBSD.ORG Fri Jun 25 14:30:49 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3723416A4D2 for ; Fri, 25 Jun 2004 14:30:49 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1DA5543D1D for ; Fri, 25 Jun 2004 14:30:49 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i5PEUMu0071031 for ; Fri, 25 Jun 2004 14:30:22 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i5PEUMm0071026; Fri, 25 Jun 2004 14:30:22 GMT (envelope-from gnats) Resent-Date: Fri, 25 Jun 2004 14:30:22 GMT Resent-Message-Id: <200406251430.i5PEUMm0071026@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Rene de Vries Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D09BA16A4CE for ; Fri, 25 Jun 2004 14:24:28 +0000 (GMT) Received: from bastix.tunix.nl (bastix.tunix.nl [193.79.201.39]) by mx1.FreeBSD.org (Postfix) with ESMTP id D57AF43D31 for ; Fri, 25 Jun 2004 14:24:27 +0000 (GMT) (envelope-from rene@tunix.nl) Received: (from root@localhost) by bastix.tunix.nl (8.9.3c/8.6.12) id QAA03932 for ; Fri, 25 Jun 2004 16:23:55 +0200 (CEST) Received: by bastix.tunix.nl (TUNIX txp2/smap) for id sma003327; Fri, 25 Jun 04 16:22:48 +0200 Received: from upsilix.tunix.nl (upsilix.tunix.nl [172.16.2.22]) by fix.tunix.nl (8.10.2+Sun/8.10.2) with ESMTP id i5PEMmo25800 for ; Fri, 25 Jun 2004 16:22:48 +0200 (MEST) Received: from upsilix.tunix.nl (localhost.tunix.nl [127.0.0.1]) by upsilix.tunix.nl (8.12.8p2/8.12.6) with ESMTP id i5PEMmD2064802 for ; Fri, 25 Jun 2004 16:22:48 +0200 (CEST) (envelope-from rene@upsilix.tunix.nl) Received: (from rene@localhost) by upsilix.tunix.nl (8.12.8p2/8.12.6/Submit) id i5PEMlLN064801; Fri, 25 Jun 2004 16:22:47 +0200 (CEST) (envelope-from rene) Message-Id: <200406251422.i5PEMlLN064801@upsilix.tunix.nl> Date: Fri, 25 Jun 2004 16:22:47 +0200 (CEST) From: Rene de Vries To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/68328: enable configuration of extra listen sockets in syslog.conf X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Rene de Vries List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jun 2004 14:30:49 -0000 >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: