From owner-svn-src-all@FreeBSD.ORG Sat Aug 7 16:20:13 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 595801065677; Sat, 7 Aug 2010 16:20:13 +0000 (UTC) (envelope-from olli@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 47EA48FC1A; Sat, 7 Aug 2010 16:20:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o77GKDpF091346; Sat, 7 Aug 2010 16:20:13 GMT (envelope-from olli@svn.freebsd.org) Received: (from olli@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o77GKDBb091327; Sat, 7 Aug 2010 16:20:13 GMT (envelope-from olli@svn.freebsd.org) Message-Id: <201008071620.o77GKDBb091327@svn.freebsd.org> From: Oliver Fromme Date: Sat, 7 Aug 2010 16:20:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211023 - head/usr.sbin/syslogd X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Aug 2010 16:20:13 -0000 Author: olli Date: Sat Aug 7 16:20:12 2010 New Revision: 211023 URL: http://svn.freebsd.org/changeset/base/211023 Log: syslogd(8) already supports *sending* log messages to non- standard ports, but it can't *receive* them (port 514 is hardcoded). This commit adds that missing feature. (NB: I actually needed this feature for a server farm where multiple jails run with shared IP addresses, and every jail should have its own syslogd process.) As a side effect, syslogd now compiles with WARNS=6. Approved by: des (mentor) MFC after: 3 weeks Modified: head/usr.sbin/syslogd/Makefile head/usr.sbin/syslogd/syslogd.8 head/usr.sbin/syslogd/syslogd.c Modified: head/usr.sbin/syslogd/Makefile ============================================================================== --- head/usr.sbin/syslogd/Makefile Sat Aug 7 16:14:40 2010 (r211022) +++ head/usr.sbin/syslogd/Makefile Sat Aug 7 16:20:12 2010 (r211023) @@ -12,7 +12,7 @@ SRCS= syslogd.c ttymsg.c DPADD= ${LIBUTIL} LDADD= -lutil -WARNS?= 3 +WARNS?= 6 .if ${MK_INET6_SUPPORT} != "no" CFLAGS+= -DINET6 Modified: head/usr.sbin/syslogd/syslogd.8 ============================================================================== --- head/usr.sbin/syslogd/syslogd.8 Sat Aug 7 16:14:40 2010 (r211022) +++ head/usr.sbin/syslogd/syslogd.8 Sat Aug 7 16:20:12 2010 (r211023) @@ -171,10 +171,29 @@ The options are ignored if the .Fl s option is also specified. -.It Fl b Ar bind_address -Specify one specific IP address or hostname to bind to. -If a hostname is specified, -the IPv4 or IPv6 address which corresponds to it is used. +.It Xo +.Fl b +.Sm off +.Ar bind_address Op : Ar service +.Sm on +.Xc +.It Xo +.Fl b +.Sm off +.Li : Ar service +.Sm on +.Xc +Bind to a specific address and/or port. +The address can be specified as a hostname, +and the port as a service name. +If an IPv6 address is specified, it should be enclosed with +.Ql \&[ +and +.Ql \&] . +The default +.Ar service +is +.Ql syslog . .It Fl C Create log files that do not exist (permission is set to .Li 0600 ) . Modified: head/usr.sbin/syslogd/syslogd.c ============================================================================== --- head/usr.sbin/syslogd/syslogd.c Sat Aug 7 16:14:40 2010 (r211022) +++ head/usr.sbin/syslogd/syslogd.c Sat Aug 7 16:20:12 2010 (r211023) @@ -317,7 +317,7 @@ static void dodie(int); static void dofsync(void); static void domark(int); static void fprintlog(struct filed *, int, const char *); -static int *socksetup(int, const char *); +static int *socksetup(int, char *); static void init(int); static void logerror(const char *); static void logmsg(int, const char *, const char *, int); @@ -345,7 +345,8 @@ main(int argc, char *argv[]) struct sockaddr_storage frominet; fd_set *fdsr = NULL; char line[MAXLINE + 1]; - const char *bindhostname, *hname; + char *bindhostname; + const char *hname; struct timeval tv, *tvp; struct sigaction sact; struct funix *fx, *fx1; @@ -2605,16 +2606,47 @@ log_deadchild(pid_t pid, int status, con } static int * -socksetup(int af, const char *bindhostname) +socksetup(int af, char *bindhostname) { struct addrinfo hints, *res, *r; + const char *bindservice; + char *cp; int error, maxs, *s, *socks; + /* + * We have to handle this case for backwards compatibility: + * If there are two (or more) colons but no '[' and ']', + * assume this is an inet6 address without a service. + */ + bindservice = "syslog"; + if (bindhostname != NULL) { +#ifdef INET6 + if (*bindhostname == '[' && + (cp = strchr(bindhostname + 1, ']')) != NULL) { + ++bindhostname; + *cp = '\0'; + if (cp[1] == ':' && cp[2] != '\0') + bindservice = cp + 2; + } else { +#endif + cp = strchr(bindhostname, ':'); + if (cp != NULL && strchr(cp + 1, ':') == NULL) { + *cp = '\0'; + if (cp[1] != '\0') + bindservice = cp + 1; + if (cp == bindhostname) + bindhostname = NULL; + } +#ifdef INET6 + } +#endif + } + memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_PASSIVE; hints.ai_family = af; hints.ai_socktype = SOCK_DGRAM; - error = getaddrinfo(bindhostname, "syslog", &hints, &res); + error = getaddrinfo(bindhostname, bindservice, &hints, &res); if (error) { logerror(gai_strerror(error)); errno = 0;