[Midnightbsd-cvs] src: usr.sbin/syslogd: Bring in several fixes for syslogd from FreeBSD.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Apr 28 00:21:38 EDT 2008


Log Message:
-----------
Bring in several fixes for syslogd from FreeBSD.

Modified Files:
--------------
    src/usr.sbin/syslogd:
        Makefile (r1.1.1.1 -> r1.2)
        pathnames.h (r1.1.1.1 -> r1.2)
        syslog.conf.5 (r1.1.1.1 -> r1.2)
        syslogd.8 (r1.1.1.1 -> r1.2)
        syslogd.c (r1.1.1.2 -> r1.2)

-------------- next part --------------
Index: syslogd.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L usr.sbin/syslogd/syslogd.c -L usr.sbin/syslogd/syslogd.c -u -r1.1.1.2 -r1.2
--- usr.sbin/syslogd/syslogd.c
+++ usr.sbin/syslogd/syslogd.c
@@ -40,7 +40,8 @@
 #endif /* not lint */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/usr.sbin/syslogd/syslogd.c,v 1.144.2.2 2006/01/15 17:50:37 delphij Exp $");
+/* $FreeBSD: src/usr.sbin/syslogd/syslogd.c,v 1.152 2006/09/29 17:36:38 ru Exp $ */
+__MBSDID("$MidnightBSD$");
 
 /*
  *  syslogd -- log system messages
@@ -286,6 +287,7 @@
 static int	send_to_all;	/* send message to all IPv4/IPv6 addresses */
 static int	use_bootfile;	/* log entire bootfile for every kern msg */
 static int	no_compress;	/* don't compress messages (1=pipes, 2=all) */
+static int	logflags = O_WRONLY|O_APPEND; /* flags used to open log files */
 
 static char	bootfile[MAXLINE+1]; /* booted kernel file */
 
@@ -350,7 +352,7 @@
 	socklen_t len;
 
 	bindhostname = NULL;
-	while ((ch = getopt(argc, argv, "46Aa:b:cdf:kl:m:nop:P:sS:uv")) != -1)
+	while ((ch = getopt(argc, argv, "46Aa:b:cCdf:kl:m:nop:P:sS:uv")) != -1)
 		switch (ch) {
 		case '4':
 			family = PF_INET;
@@ -373,6 +375,9 @@
 		case 'c':
 			no_compress++;
 			break;
+		case 'C':
+			logflags |= O_CREAT;
+			break;
 		case 'd':		/* debug */
 			Debug++;
 			break;
@@ -689,9 +694,9 @@
 {
 
 	fprintf(stderr, "%s\n%s\n%s\n%s\n",
-		"usage: syslogd [-46Acdknosuv] [-a allowed_peer]",
-		"               [-b bind address] [-f config_file]",
-		"               [-l log_socket] [-m mark_interval]",
+		"usage: syslogd [-46ACcdknosuv] [-a allowed_peer]",
+		"               [-b bind_address] [-f config_file]",
+		"               [-l [mode:]path] [-m mark_interval]",
 		"               [-P pid_file] [-p log_socket]");
 	exit(1);
 }
@@ -837,7 +842,8 @@
  * based on the specification.
  */
 static int
-skip_message(const char *name, const char *spec, int checkcase) {
+skip_message(const char *name, const char *spec, int checkcase)
+{
 	const char *s;
 	char prev, next;
 	int exclude = 0;
@@ -1149,12 +1155,19 @@
 	f->f_time = now;
 
 	switch (f->f_type) {
+		int port;
 	case F_UNUSED:
 		dprintf("\n");
 		break;
 
 	case F_FORW:
-		dprintf(" %s\n", f->f_un.f_forw.f_hname);
+		port = (int)ntohs(((struct sockaddr_in *)
+			    (f->f_un.f_forw.f_addr->ai_addr))->sin_port);
+		if (port != 514) {
+			dprintf(" %s:%d\n", f->f_un.f_forw.f_hname, port);
+		} else {
+			dprintf(" %s\n", f->f_un.f_forw.f_hname);
+		}
 		/* check for local vs remote messages */
 		if (strcasecmp(f->f_prevhost, LocalHostName))
 			l = snprintf(line, sizeof line - 1,
@@ -1222,11 +1235,18 @@
 		v->iov_base = lf;
 		v->iov_len = 1;
 		if (writev(f->f_file, iov, 7) < 0) {
-			int e = errno;
-			(void)close(f->f_file);
-			f->f_type = F_UNUSED;
-			errno = e;
-			logerror(f->f_un.f_fname);
+			/*
+			 * If writev(2) fails for potentially transient errors
+			 * like the * filesystem being full, ignore it.
+			 * Otherwise remove * this logfile from the list.
+			 */
+			if (errno != ENOSPC) {
+				int e = errno;
+				(void)close(f->f_file);
+				f->f_type = F_UNUSED;
+				errno = e;
+				logerror(f->f_un.f_fname);
+			}
 		} else if ((flags & SYNC_FILE) && (f->f_flags & FFLAG_SYNC)) {
 			f->f_flags |= FFLAG_NEEDSYNC;
 			needdofsync = 1;
@@ -1646,6 +1666,7 @@
 	Initialized = 1;
 
 	if (Debug) {
+		int port;
 		for (f = Files; f; f = f->f_next) {
 			for (i = 0; i <= LOG_NFACILITIES; i++)
 				if (f->f_pmask[i] == INTERNAL_NOPRI)
@@ -1664,7 +1685,14 @@
 				break;
 
 			case F_FORW:
-				printf("%s", f->f_un.f_forw.f_hname);
+				port = (int)ntohs(((struct sockaddr_in *)
+				    (f->f_un.f_forw.f_addr->ai_addr))->sin_port);
+				if (port != 514) {
+					printf("%s:%d",
+						f->f_un.f_forw.f_hname, port);
+				} else {
+					printf("%s", f->f_un.f_forw.f_hname);
+				}
 				break;
 
 			case F_PIPE:
@@ -1869,13 +1897,32 @@
 
 	switch (*p) {
 	case '@':
-		(void)strlcpy(f->f_un.f_forw.f_hname, ++p,
-			sizeof(f->f_un.f_forw.f_hname));
+		{
+			char *tp;
+			/*
+			 * scan forward to see if there is a port defined.
+			 * so we can't use strlcpy..
+			 */
+			i = sizeof(f->f_un.f_forw.f_hname);
+			tp = f->f_un.f_forw.f_hname;
+			p++;
+
+			while (*p && (*p != ':') && (i-- > 0)) {
+				*tp++ = *p++;
+			}
+			*tp = '\0';
+		}
+		/* See if we copied a domain and have a port */
+		if (*p == ':')
+			p++;
+		else
+			p = NULL;
+		
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_family = family;
 		hints.ai_socktype = SOCK_DGRAM;
-		error = getaddrinfo(f->f_un.f_forw.f_hname, "syslog", &hints,
-				    &res);
+		error = getaddrinfo(f->f_un.f_forw.f_hname,
+				p ? p: "syslog", &hints, &res); 
 		if (error) {
 			logerror(gai_strerror(error));
 			break;
@@ -1885,7 +1932,7 @@
 		break;
 
 	case '/':
-		if ((f->f_file = open(p, O_WRONLY|O_APPEND, 0)) < 0) {
+		if ((f->f_file = open(p, logflags, 0600)) < 0) {
 			f->f_type = F_UNUSED;
 			logerror(p);
 			break;
Index: syslogd.8
===================================================================
RCS file: /home/cvs/src/usr.sbin/syslogd/syslogd.8,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/syslogd/syslogd.8 -L usr.sbin/syslogd/syslogd.8 -u -r1.1.1.1 -r1.2
--- usr.sbin/syslogd/syslogd.8
+++ usr.sbin/syslogd/syslogd.8
@@ -26,7 +26,8 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)syslogd.8	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD: src/usr.sbin/syslogd/syslogd.8,v 1.60 2005/04/13 03:19:41 hrs Exp $
+.\" $FreeBSD: src/usr.sbin/syslogd/syslogd.8,v 1.61 2006/03/06 10:36:32 pjd Exp $
+.\" $MidnightBSD$
 .\"
 .Dd April 13, 2005
 .Dt SYSLOGD 8
@@ -36,7 +37,7 @@
 .Nd log systems messages
 .Sh SYNOPSIS
 .Nm
-.Op Fl 46Acdknosuv
+.Op Fl 46ACcdknosuv
 .Op Fl a Ar allowed_peer
 .Op Fl b Ar bind_address
 .Op Fl f Ar config_file
@@ -157,6 +158,9 @@
 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 Fl C
+Create log files that do not exist (permission is set to
+.Li 0600 ) .
 .It Fl c
 Disable the compression of repeated instances of the same line
 into a single line of the form
@@ -283,7 +287,9 @@
 .Pp
 For security reasons,
 .Nm
-will not append to log files that do not exist;
+will not append to log files that do not exist (unless
+.Fl C
+option is specified);
 therefore, they must be created manually before running
 .Nm .
 .Sh FILES
Index: Makefile
===================================================================
RCS file: /home/cvs/src/usr.sbin/syslogd/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/syslogd/Makefile -L usr.sbin/syslogd/Makefile -u -r1.1.1.1 -r1.2
--- usr.sbin/syslogd/Makefile
+++ usr.sbin/syslogd/Makefile
@@ -1,5 +1,6 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
 # $FreeBSD: src/usr.sbin/syslogd/Makefile,v 1.12 2004/02/05 22:44:25 ru Exp $
+# $MidnightBSD$
 
 .PATH: ${.CURDIR}/../../usr.bin/wall
 
Index: syslog.conf.5
===================================================================
RCS file: /home/cvs/src/usr.sbin/syslogd/syslog.conf.5,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/syslogd/syslog.conf.5 -L usr.sbin/syslogd/syslog.conf.5 -u -r1.1.1.1 -r1.2
--- usr.sbin/syslogd/syslog.conf.5
+++ usr.sbin/syslogd/syslog.conf.5
@@ -26,7 +26,8 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)syslog.conf.5	8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/usr.sbin/syslogd/syslog.conf.5,v 1.39.2.1 2005/08/18 15:01:27 keramida Exp $
+.\" $FreeBSD: src/usr.sbin/syslogd/syslog.conf.5,v 1.44 2006/10/12 01:59:34 trhodes Exp $
+.\" $MidnightBSD$
 .\"
 .Dd June 9, 1993
 .Dt SYSLOG.CONF 5
@@ -47,7 +48,7 @@
 .Em program
 and
 .Em hostname
-specifications (separations appear along on the line),
+specifications (separations appear alone on their lines),
 with each line containing two fields: the
 .Em selector
 field which specifies the types of messages and priorities to which the
@@ -94,9 +95,13 @@
 The
 .Em facility
 describes the part of the system generating the message, and is one of
-the following keywords: auth, authpriv, console, cron, daemon, ftp, kern,
-lpr, mail, mark, news, ntp, security, syslog, user, uucp and local0 through
-local7.
+the following keywords:
+.Cm auth , authpriv , console , cron , daemon , ftp , kern , lpr ,
+.Cm mail , mark , news , ntp , security , syslog , user , uucp ,
+and
+.Cm local0
+through
+.Cm local7 .
 These keywords (with the exception of mark) correspond to
 similar
 .Dq Dv LOG_
@@ -132,8 +137,10 @@
 The
 .Em level
 describes the severity of the message, and is a keyword from the
-following ordered list (higher to lower): emerg, alert, crit, err,
-warning, notice, info and debug.
+following ordered list (higher to lower):
+.Cm emerg , alert , err , warning , notice , info
+and
+.Cm debug .
 These keywords correspond to
 similar
 .Dq Dv LOG_
@@ -337,6 +344,10 @@
 Selected messages are forwarded to the
 .Xr syslogd 8
 program on the named host.
+If a port number is added after a colon
+.Pq Ql :\&
+then that port will be used as the destination port
+rather than the usual syslog port.
 .It
 A comma separated list of users.
 Selected messages are written to those users
Index: pathnames.h
===================================================================
RCS file: /home/cvs/src/usr.sbin/syslogd/pathnames.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.sbin/syslogd/pathnames.h -L usr.sbin/syslogd/pathnames.h -u -r1.1.1.1 -r1.2
--- usr.sbin/syslogd/pathnames.h
+++ usr.sbin/syslogd/pathnames.h
@@ -28,6 +28,7 @@
  *
  *	@(#)pathnames.h	8.1 (Berkeley) 6/6/93
  * $FreeBSD: src/usr.sbin/syslogd/pathnames.h,v 1.2 2004/08/07 04:28:55 imp Exp $
+ * $MidnightBSD$
  */
 
 #include <paths.h>


More information about the Midnightbsd-cvs mailing list