From owner-svn-src-head@FreeBSD.ORG Sat Dec 5 20:05:26 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 EC7671065670; Sat, 5 Dec 2009 20:05:25 +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 C30A38FC0A; Sat, 5 Dec 2009 20:05:25 +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 nB5K5PaN098415; Sat, 5 Dec 2009 20:05:25 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nB5K5PoZ098412; Sat, 5 Dec 2009 20:05:25 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200912052005.nB5K5PoZ098412@svn.freebsd.org> From: Ed Schouten Date: Sat, 5 Dec 2009 20:05:25 +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: r200156 - head/usr.bin/wall 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: Sat, 05 Dec 2009 20:05:26 -0000 Author: ed Date: Sat Dec 5 20:05:25 2009 New Revision: 200156 URL: http://svn.freebsd.org/changeset/base/200156 Log: Let wall(1) use utmpx. Because our implementation guarantees the strings inside struct utmpx to be null terminated, we don't need to copy everything out, which makes the code nicer to read. Also set WARNS to 6 and add $FreeBSD$ to keep SVN silent. Modified: head/usr.bin/wall/Makefile head/usr.bin/wall/wall.c Modified: head/usr.bin/wall/Makefile ============================================================================== --- head/usr.bin/wall/Makefile Sat Dec 5 19:55:26 2009 (r200155) +++ head/usr.bin/wall/Makefile Sat Dec 5 20:05:25 2009 (r200156) @@ -1,8 +1,14 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 +# $FreeBSD$ PROG= wall SRCS= ttymsg.c wall.c BINGRP= tty BINMODE=2555 +WARNS?= 6 + +DPADD= ${LIBULOG} +LDADD= -lulog + .include Modified: head/usr.bin/wall/wall.c ============================================================================== --- head/usr.bin/wall/wall.c Sat Dec 5 19:55:26 2009 (r200155) +++ head/usr.bin/wall/wall.c Sat Dec 5 20:05:25 2009 (r200156) @@ -64,8 +64,9 @@ static const char sccsid[] = "@(#)wall.c #include #include #include +#define _ULOG_POSIX_NAMES +#include #include -#include #include "ttymsg.h" @@ -82,12 +83,12 @@ int mbufsize; char *mbuf; static int -ttystat(char *line, int sz) +ttystat(char *line) { struct stat sb; char ttybuf[MAXPATHLEN]; - (void)snprintf(ttybuf, sizeof(ttybuf), "%s%.*s", _PATH_DEV, sz, line); + (void)snprintf(ttybuf, sizeof(ttybuf), "%s%s", _PATH_DEV, line); if (stat(ttybuf, &sb) == 0) { return (0); } else @@ -98,17 +99,14 @@ int main(int argc, char *argv[]) { struct iovec iov; - struct utmp utmp; + struct utmpx *utmp; int ch; int ingroup; - FILE *fp; struct wallgroup *g; struct group *grp; char **np; const char *p; struct passwd *pw; - char line[sizeof(utmp.ut_line) + 1]; - char username[sizeof(utmp.ut_name) + 1]; (void)setlocale(LC_CTYPE, ""); @@ -145,20 +143,17 @@ main(int argc, char *argv[]) makemsg(*argv); - if (!(fp = fopen(_PATH_UTMP, "r"))) - err(1, "cannot read %s", _PATH_UTMP); iov.iov_base = mbuf; iov.iov_len = mbufsize; /* NOSTRICT */ - while (fread((char *)&utmp, sizeof(utmp), 1, fp) == 1) { - if (!utmp.ut_name[0]) + while ((utmp = getutxent()) != NULL) { + if (utmp->ut_type != USER_PROCESS) continue; - if (ttystat(utmp.ut_line, UT_LINESIZE) != 0) + if (ttystat(utmp->ut_line) != 0) continue; if (grouplist) { ingroup = 0; - strlcpy(username, utmp.ut_name, sizeof(utmp.ut_name)); - pw = getpwnam(username); + pw = getpwnam(utmp->ut_user); if (!pw) continue; for (g = grouplist; g && ingroup == 0; g = g->next) { @@ -168,7 +163,7 @@ main(int argc, char *argv[]) ingroup = 1; else if ((grp = getgrgid(g->gid)) != NULL) { for (np = grp->gr_mem; *np; np++) { - if (strcmp(*np, username) == 0) { + if (strcmp(*np, utmp->ut_user) == 0) { ingroup = 1; break; } @@ -178,9 +173,7 @@ main(int argc, char *argv[]) if (ingroup == 0) continue; } - strncpy(line, utmp.ut_line, sizeof(utmp.ut_line)); - line[sizeof(utmp.ut_line)] = '\0'; - if ((p = ttymsg(&iov, 1, line, 60*5)) != NULL) + if ((p = ttymsg(&iov, 1, utmp->ut_line, 60*5)) != NULL) warnx("%s", p); } exit(0);