Deleted Added
full compact
43c43
< __FBSDID("$FreeBSD: head/usr.sbin/rwhod/rwhod.c 146940 2005-06-03 17:38:33Z ssouhlal $");
---
> __FBSDID("$FreeBSD: head/usr.sbin/rwhod/rwhod.c 201060 2009-12-27 21:14:55Z ed $");
69a70,71
> #define _ULOG_POSIX_NAMES
> #include <ulog.h>
71d72
< #include <utmp.h>
149c150
< int s, utmpf;
---
> int s;
234,238d234
< utmpf = open(_PATH_UTMP, O_RDONLY|O_CREAT, 0644);
< if (utmpf < 0) {
< syslog(LOG_ERR, "%s: %m", _PATH_UTMP);
< exit(1);
< }
386,391d381
< int utmptime;
< int utmpent;
< int utmpsize = 0;
< struct utmp *utmp;
< int alarmcount;
<
393,394c383
< onalrm(signo)
< int signo __unused;
---
> onalrm(int signo __unused)
396,398c385,386
< register struct neighbor *np;
< register struct whoent *we = mywd.wd_we, *wlast;
< register int i;
---
> struct neighbor *np;
> struct whoent *we = mywd.wd_we, *wend;
399a388,389
> struct utmpx *ut;
> static int alarmcount = 0;
402c392
< int cc;
---
> int i, cc;
408,439c398,409
< (void) fstat(utmpf, &stb);
< if ((stb.st_mtime != utmptime) || (stb.st_size > utmpsize)) {
< utmptime = stb.st_mtime;
< if (stb.st_size > utmpsize) {
< utmpsize = stb.st_size + 10 * sizeof(struct utmp);
< utmp = (struct utmp *)reallocf(utmp, utmpsize);
< if (utmp == NULL) {
< syslog(LOG_WARNING, "malloc failed");
< utmpsize = 0;
< goto done;
< }
< }
< (void) lseek(utmpf, (off_t)0, L_SET);
< cc = read(utmpf, (char *)utmp, stb.st_size);
< if (cc < 0) {
< syslog(LOG_ERR, "read(%s): %m", _PATH_UTMP);
< goto done;
< }
< wlast = &mywd.wd_we[1024 / sizeof(struct whoent) - 1];
< utmpent = cc / sizeof(struct utmp);
< for (i = 0; i < utmpent; i++)
< if (utmp[i].ut_name[0]) {
< memcpy(we->we_utmp.out_line, utmp[i].ut_line,
< sizeof(utmp[i].ut_line));
< memcpy(we->we_utmp.out_name, utmp[i].ut_name,
< sizeof(utmp[i].ut_name));
< we->we_utmp.out_time = htonl(utmp[i].ut_time);
< if (we >= wlast)
< break;
< we++;
< }
< utmpent = we - mywd.wd_we;
---
> wend = &mywd.wd_we[1024 / sizeof(struct whoent)];
> setutxent();
> while ((ut = getutxent()) != NULL && we < wend) {
> if (ut->ut_type != USER_PROCESS)
> continue;
> strncpy(we->we_utmp.out_line, ut->ut_line,
> sizeof(we->we_utmp.out_line));
> strncpy(we->we_utmp.out_name, ut->ut_user,
> sizeof(we->we_utmp.out_name));
> we->we_utmp.out_time =
> htonl(_time_to_time32(ut->ut_tv.tv_sec));
> we++;
440a411
> endutxent();
442,447c413
< /*
< * The test on utmpent looks silly---after all, if no one is
< * logged on, why worry about efficiency?---but is useful on
< * (e.g.) compute servers.
< */
< if (utmpent && chdir(_PATH_DEV)) {
---
> if (chdir(_PATH_DEV)) {
451,452c417,418
< we = mywd.wd_we;
< for (i = 0; i < utmpent; i++) {
---
> wend = we;
> for (we = mywd.wd_we; we < wend; we++) {
460c426
< cc = (char *)we - (char *)&mywd;
---
> cc = (char *)wend - (char *)&mywd;
488c454
< if (utmpent && chdir(_PATH_RWHODIR)) {
---
> if (chdir(_PATH_RWHODIR)) {
492d457
< done: