From owner-svn-src-head@FreeBSD.ORG Thu Dec 24 18:05:33 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C39E9106566B; Thu, 24 Dec 2009 18:05:33 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B2AB58FC15; Thu, 24 Dec 2009 18:05:33 +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 nBOI5XPL037352; Thu, 24 Dec 2009 18:05:33 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBOI5XPB037349; Thu, 24 Dec 2009 18:05:33 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200912241805.nBOI5XPB037349@svn.freebsd.org> From: Ed Schouten Date: Thu, 24 Dec 2009 18:05:33 +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: r200954 - head/usr.sbin/syslogd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 18:05:34 -0000 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 #include #include +#define _ULOG_POSIX_NAMES +#include #include -#include #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 == ' ')