Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Dec 2009 18:05:33 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r200954 - head/usr.sbin/syslogd
Message-ID:  <200912241805.nBOI5XPB037349@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Thu Dec 24 18:05:33 2009
New Revision: 200954
URL: http://svn.freebsd.org/changeset/base/200954

Log:
  Let syslogd use utmpx.
  
  Because strings are guaranteed to be null terminated, there is no need
  for excessive copying of strings, such as the line name.

Modified:
  head/usr.sbin/syslogd/Makefile
  head/usr.sbin/syslogd/syslogd.c

Modified: head/usr.sbin/syslogd/Makefile
==============================================================================
--- head/usr.sbin/syslogd/Makefile	Thu Dec 24 17:55:47 2009	(r200953)
+++ head/usr.sbin/syslogd/Makefile	Thu Dec 24 18:05:33 2009	(r200954)
@@ -9,8 +9,8 @@ PROG=	syslogd
 MAN=	syslog.conf.5 syslogd.8
 SRCS=	syslogd.c ttymsg.c
 
-DPADD=	${LIBUTIL}
-LDADD=	-lutil
+DPADD=	${LIBULOG} ${LIBUTIL}
+LDADD=	-lulog -lutil
 
 WARNS?=	3
 

Modified: head/usr.sbin/syslogd/syslogd.c
==============================================================================
--- head/usr.sbin/syslogd/syslogd.c	Thu Dec 24 17:55:47 2009	(r200953)
+++ head/usr.sbin/syslogd/syslogd.c	Thu Dec 24 18:05:33 2009	(r200954)
@@ -105,8 +105,9 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
+#define	_ULOG_POSIX_NAMES
+#include <ulog.h>
 #include <unistd.h>
-#include <utmp.h>
 
 #include "pathnames.h"
 #include "ttymsg.h"
@@ -171,7 +172,7 @@ struct filed {
 #define PRI_GT	0x4
 	char	*f_program;		/* program this applies to */
 	union {
-		char	f_uname[MAXUNAMES][UT_NAMESIZE+1];
+		char	f_uname[MAXUNAMES][MAXLOGNAME];
 		struct {
 			char	f_hname[MAXHOSTNAMELEN];
 			struct addrinfo *f_addr;
@@ -1342,29 +1343,20 @@ static void
 wallmsg(struct filed *f, struct iovec *iov, const int iovlen)
 {
 	static int reenter;			/* avoid calling ourselves */
-	FILE *uf;
-	struct utmp ut;
+	struct utmpx *ut;
 	int i;
 	const char *p;
-	char line[sizeof(ut.ut_line) + 1];
 
 	if (reenter++)
 		return;
-	if ((uf = fopen(_PATH_UTMP, "r")) == NULL) {
-		logerror(_PATH_UTMP);
-		reenter = 0;
-		return;
-	}
+	setutxent();
 	/* NOSTRICT */
-	while (fread((char *)&ut, sizeof(ut), 1, uf) == 1) {
-		if (ut.ut_name[0] == '\0')
+	while ((ut = getutxent()) != NULL) {
+		if (ut->ut_type != USER_PROCESS)
 			continue;
-		/* We must use strncpy since ut_* may not be NUL terminated. */
-		strncpy(line, ut.ut_line, sizeof(line) - 1);
-		line[sizeof(line) - 1] = '\0';
 		if (f->f_type == F_WALL) {
-			if ((p = ttymsg(iov, iovlen, line, TTYMSGTIME)) !=
-			    NULL) {
+			if ((p = ttymsg(iov, iovlen, ut->ut_line,
+			    TTYMSGTIME)) != NULL) {
 				errno = 0;	/* already in msg */
 				logerror(p);
 			}
@@ -1374,10 +1366,9 @@ wallmsg(struct filed *f, struct iovec *i
 		for (i = 0; i < MAXUNAMES; i++) {
 			if (!f->f_un.f_uname[i][0])
 				break;
-			if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
-			    UT_NAMESIZE)) {
-				if ((p = ttymsg(iov, iovlen, line, TTYMSGTIME))
-				    != NULL) {
+			if (!strcmp(f->f_un.f_uname[i], ut->ut_user)) {
+				if ((p = ttymsg(iov, iovlen, ut->ut_line,
+				    TTYMSGTIME)) != NULL) {
 					errno = 0;	/* already in msg */
 					logerror(p);
 				}
@@ -1385,7 +1376,7 @@ wallmsg(struct filed *f, struct iovec *i
 			}
 		}
 	}
-	(void)fclose(uf);
+	endutxent();
 	reenter = 0;
 }
 
@@ -2002,9 +1993,9 @@ cfline(const char *line, struct filed *f
 		for (i = 0; i < MAXUNAMES && *p; i++) {
 			for (q = p; *q && *q != ','; )
 				q++;
-			(void)strncpy(f->f_un.f_uname[i], p, UT_NAMESIZE);
-			if ((q - p) > UT_NAMESIZE)
-				f->f_un.f_uname[i][UT_NAMESIZE] = '\0';
+			(void)strncpy(f->f_un.f_uname[i], p, MAXLOGNAME - 1);
+			if ((q - p) >= MAXLOGNAME)
+				f->f_un.f_uname[i][MAXLOGNAME - 1] = '\0';
 			else
 				f->f_un.f_uname[i][q - p] = '\0';
 			while (*q == ',' || *q == ' ')



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