From 02dfd2b299ef9e368a9acad907dc3a5d7ccf32b1 Mon Sep 17 00:00:00 2001 From: Suleiman Souhlal Date: Fri, 2 Sep 2005 14:58:26 +0000 Subject: [PATCH] - Do not allocate memory to entries in /var/rwho which have been down for more than 4 days - waste of memory. Obtained from: DragonFlyBSD (liamfoy) MFC after: 3 days --- usr.bin/ruptime/ruptime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.bin/ruptime/ruptime.c b/usr.bin/ruptime/ruptime.c index 045a1257f787..f0778ea3f4c2 100644 --- a/usr.bin/ruptime/ruptime.c +++ b/usr.bin/ruptime/ruptime.c @@ -63,7 +63,7 @@ struct hs { int hs_nusers; } *hs; struct whod awhod; -#define LEFTEARTH(h) (now - (h)->hs_wd->wd_recvtime > 4*24*60*60) +#define LEFTEARTH(h) (now - (h) > 4*24*60*60) #define ISDOWN(h) (now - (h)->hs_wd->wd_recvtime > 11 * 60) #define WHDRSIZE (sizeof (awhod) - sizeof (awhod.wd_we)) @@ -208,6 +208,8 @@ ruptime(const char *host, int aflg, int (*cmp)(const void *, const void *)) if (cc < WHDRSIZE) continue; + if (LEFTEARTH(((struct whod *)buf)->wd_recvtime)) + continue; if (nhosts == hspace) { if ((hs = realloc(hs, (hspace += 40) * sizeof(*hs))) == NULL) @@ -241,8 +243,6 @@ ruptime(const char *host, int aflg, int (*cmp)(const void *, const void *)) qsort(hs, nhosts, sizeof(hs[0]), cmp); for (i = 0; i < (int)nhosts; i++) { hsp = &hs[i]; - if (LEFTEARTH(hsp)) - continue; if (ISDOWN(hsp)) { (void)printf("%-12.12s%s\n", hsp->hs_wd->wd_hostname, interval(now - hsp->hs_wd->wd_recvtime, "down"));