--- qbiff.c.orig Tue Aug 5 01:54:33 1997 +++ qbiff.c Wed Aug 6 18:07:05 1997 @@ -29,6 +29,7 @@ struct utmp ut; char line[sizeof(ut.ut_line) + 1]; +char leastidleline[sizeof(ut.ut_line) + 1]; stralloc woof = {0}; stralloc tofrom = {0}; stralloc text = {0}; @@ -56,6 +57,7 @@ char *sender; char *userext; struct stat st; + time_t leastidle; int i; if (chdir("/dev") == -1) _exit(0); @@ -70,6 +72,7 @@ if (!stralloc_cats(&tofrom,"> FROM <")) _exit(0); if (!stralloc_cats(&tofrom,sender)) _exit(0); if (!stralloc_cats(&tofrom,">")) _exit(0); + if (tofrom.len > 78) tofrom.len = 78; for (i = 0;i < tofrom.len;++i) if ((tofrom.s[i] < 32) || (tofrom.s[i] > 126)) @@ -92,6 +95,7 @@ if (fdutmp == -1) _exit(0); substdio_fdbuf(&ssutmp,read,fdutmp,bufutmp,sizeof(bufutmp)); + leastidle = 0; while (substdio_get(&ssutmp,&ut,sizeof(ut)) == sizeof(ut)) if (!str_diffn(ut.ut_name,user,sizeof(ut.ut_name))) { @@ -105,9 +109,19 @@ if (fstat(fdtty,&st) == -1) { close(fdtty); continue; } if (!(st.st_mode & 0100)) { close(fdtty); continue; } if (st.st_uid != getuid()) { close(fdtty); continue; } - substdio_fdbuf(&sstty,write,fdtty,buftty,sizeof(buftty)); - substdio_putflush(&sstty,woof.s,woof.len); + if(st.st_atime > leastidle) + { + leastidle = st.st_atime; + byte_copy(leastidleline,sizeof(line),line); + line[sizeof(leastidleline)] = 0; + } close(fdtty); } + if(leastidle == 0) _exit(0); + fdtty = open_append(leastidleline); + if (fdtty == -1) _exit(0); + substdio_fdbuf(&sstty,write,fdtty,buftty,sizeof(buftty)); + substdio_putflush(&sstty,woof.s,woof.len); + close(fdtty); _exit(0); }