summaryrefslogtreecommitdiffstats
path: root/usr.bin/wall/wall.c
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2009-12-05 20:05:25 +0000
committered <ed@FreeBSD.org>2009-12-05 20:05:25 +0000
commit149e4bd942f929cb574d41bd15602213d9b892c5 (patch)
tree780631d6b9e787100ffd0fd3d0693ba557ee34d2 /usr.bin/wall/wall.c
parenta5eb90bf99d33893ee9c2c5b107bd8efac34f0bb (diff)
downloadFreeBSD-src-149e4bd942f929cb574d41bd15602213d9b892c5.zip
FreeBSD-src-149e4bd942f929cb574d41bd15602213d9b892c5.tar.gz
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.
Diffstat (limited to 'usr.bin/wall/wall.c')
-rw-r--r--usr.bin/wall/wall.c29
1 files changed, 11 insertions, 18 deletions
diff --git a/usr.bin/wall/wall.c b/usr.bin/wall/wall.c
index be5329a..dc63116 100644
--- a/usr.bin/wall/wall.c
+++ b/usr.bin/wall/wall.c
@@ -64,8 +64,9 @@ static const char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93";
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#define _ULOG_POSIX_NAMES
+#include <ulog.h>
#include <unistd.h>
-#include <utmp.h>
#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);
OpenPOWER on IntegriCloud