From owner-svn-src-all@FreeBSD.ORG Fri Dec 25 11:12:05 2009 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 A01901065692; Fri, 25 Dec 2009 11:12:05 +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 7652A8FC1A; Fri, 25 Dec 2009 11:12:05 +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 nBPBC5oC059631; Fri, 25 Dec 2009 11:12:05 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBPBC5oP059628; Fri, 25 Dec 2009 11:12:05 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <200912251112.nBPBC5oP059628@svn.freebsd.org> From: Ed Schouten Date: Fri, 25 Dec 2009 11:12:05 +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: r200983 - head/libexec/talkd 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: Fri, 25 Dec 2009 11:12:05 -0000 Author: ed Date: Fri Dec 25 11:12:05 2009 New Revision: 200983 URL: http://svn.freebsd.org/changeset/base/200983 Log: Let talkd use utmpx instead of utmp. Because strings are null terminated now, there is no need to copy ut_line into a separate buffer first. Also enable WARNS. Modified: head/libexec/talkd/Makefile head/libexec/talkd/process.c Modified: head/libexec/talkd/Makefile ============================================================================== --- head/libexec/talkd/Makefile Fri Dec 25 10:30:54 2009 (r200982) +++ head/libexec/talkd/Makefile Fri Dec 25 11:12:05 2009 (r200983) @@ -6,6 +6,10 @@ SRCS= talkd.c announce.c process.c table .PATH: ${.CURDIR}/../../usr.bin/wall MAN= talkd.8 CFLAGS+=-I${.CURDIR}/../../usr.bin/wall -WFORMAT=0 + +WARNS?= 6 + +DPADD= ${LIBULOG} +LDADD= -lulog .include Modified: head/libexec/talkd/process.c ============================================================================== --- head/libexec/talkd/process.c Fri Dec 25 10:30:54 2009 (r200982) +++ head/libexec/talkd/process.c Fri Dec 25 11:12:05 2009 (r200983) @@ -59,6 +59,8 @@ static const char rcsid[] = #include #include #include +#define _ULOG_POSIX_NAMES +#include #include "extern.h" @@ -181,55 +183,46 @@ do_announce(CTL_MSG *mp, CTL_RESPONSE *r } } -#include - /* * Search utmp for the local user */ int find_user(const char *name, char *tty) { - struct utmp ubuf; + struct utmpx *ut; int status; - FILE *fd; struct stat statb; time_t best = 0; - char line[sizeof(ubuf.ut_line) + 1]; - char ftty[sizeof(_PATH_DEV) - 1 + sizeof(line)]; + char ftty[sizeof(_PATH_DEV) - 1 + sizeof(ut->ut_line)]; - if ((fd = fopen(_PATH_UTMP, "r")) == NULL) { - warnx("can't read %s", _PATH_UTMP); - return (FAILED); - } -#define SCMPN(a, b) strncmp(a, b, sizeof (a)) + setutxent(); status = NOT_HERE; (void) strcpy(ftty, _PATH_DEV); - while (fread((char *) &ubuf, sizeof ubuf, 1, fd) == 1) - if (SCMPN(ubuf.ut_name, name) == 0) { - strncpy(line, ubuf.ut_line, sizeof(ubuf.ut_line)); - line[sizeof(ubuf.ut_line)] = '\0'; + while ((ut = getutxent()) != NULL) + if (ut->ut_type == USER_PROCESS && + strcmp(ut->ut_user, name) == 0) { if (*tty == '\0' || best != 0) { if (best == 0) status = PERMISSION_DENIED; /* no particular tty was requested */ (void) strcpy(ftty + sizeof(_PATH_DEV) - 1, - line); + ut->ut_line); if (stat(ftty, &statb) == 0) { if (!(statb.st_mode & 020)) continue; if (statb.st_atime > best) { best = statb.st_atime; - (void) strcpy(tty, line); + (void) strcpy(tty, ut->ut_line); status = SUCCESS; continue; } } } - if (strcmp(line, tty) == 0) { + if (strcmp(ut->ut_line, tty) == 0) { status = SUCCESS; break; } } - fclose(fd); + endutxent(); return (status); }