From owner-freebsd-bugs Sun Mar 24 12:50:18 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id E145C37B417 for ; Sun, 24 Mar 2002 12:50:01 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2OKo1g25107; Sun, 24 Mar 2002 12:50:01 -0800 (PST) (envelope-from gnats) Received: from server.rucus.ru.ac.za (server.rucus.ru.ac.za [146.231.115.1]) by hub.freebsd.org (Postfix) with SMTP id F31F737B400 for ; Sun, 24 Mar 2002 12:41:54 -0800 (PST) Received: (qmail 78568 invoked from network); 24 Mar 2002 20:41:51 -0000 Received: from shell-fxp1.rucus.ru.ac.za (HELO shell.rucus.ru.ac.za) (10.0.0.1) by server.rucus.ru.ac.za with SMTP; 24 Mar 2002 20:41:50 -0000 Received: (qmail 80507 invoked by uid 2425); 24 Mar 2002 20:41:50 -0000 Message-Id: <20020324204150.80506.qmail@shell.rucus.ru.ac.za> Date: 24 Mar 2002 20:41:50 -0000 From: Jonathan Hitchcock Reply-To: Jonathan Hitchcock To: FreeBSD-gnats-submit@FreeBSD.org Cc: vhata@rucus.ru.ac.za X-Send-Pr-Version: 3.113 Subject: bin/36262: [PATCH] Fixed rusers idle-time reporting to use minutes instead of seconds Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 36262 >Category: bin >Synopsis: [PATCH] Fixed rusers idle-time reporting to use minutes instead of seconds >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Mar 24 12:50:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: Jonathan Hitchcock >Release: FreeBSD 4.5-STABLE i386 >Organization: >Environment: System: FreeBSD shell.rucus.ru.ac.za 4.5-STABLE FreeBSD 4.5-STABLE #0: Mon Mar 4 16:55:49 SAST 2002 drs@shell.rucus.ru.ac.za:/usr/build/obj/usr/build/src/sys/RUCUS i386 >Description: The rusers program currently reports the idle-time of a user in days, hours, minutes and seconds. However, the utmp entries work only in minutes - they are not as fine as seconds. Thus, an idle time of 60 hours will be reported as 1:00:00, and an idle time of (60*24) == 1440 hours will be reported as 1 day, 0:00:00. In addition, idle times that are greater than the time logged in are reported - programs like 'w' check this, and only report idle times less than, or equal to, the time logged in. >How-To-Repeat: Request a long list (rusers -l) from a host where a user has been idle for any length of time - this time will be reported in incorrect units, although this is only apparent if the time is longer than 24 hours, and only especially apparent if it is longer than 1440 hours... To test it, the following code will demonstrate the problem: perl -e '$t=`tty`; chomp $t; $i=time-86400; utime $i, $i, $t;' ; w $LOGNAME ; rusers -l `hostname` | grep $LOGNAME Where '86400' is replaced by the idle time desired, of course. >Fix: The patch included with this bug-report removes the "seconds" assumption, working only in days, hours and minutes (but keeping the original output format of rusers, etc). In addition, it compares the idle time reported in the utmp info with the length of time that utmp thinks the user has been logged in, and truncates the idle time if it is longer than the logged-in time. --- rusers.patch begins here --- --- usr.bin/rusers/rusers.c.orig Sun Mar 24 20:16:59 2002 +++ usr.bin/rusers/rusers.c Sun Mar 24 21:31:11 2002 @@ -92,11 +92,12 @@ rusers_reply(char *replyp, struct sockaddr_in *raddrp) { int x, idle; + time_t now; char date[32], idle_time[64], remote[64]; struct hostent *hp; utmpidlearr *up = (utmpidlearr *)replyp; char *host; - int days, hours, minutes, seconds; + int days, hours, minutes; if (search_host(raddrp->sin_addr)) return (0); @@ -120,27 +121,27 @@ sizeof(date) - 1); idle = up->utmpidlearr_val[x].ui_idle; + now = (time(NULL))/60; + if((now - idle) < (up->utmpidlearr_val[x].ui_utmp.ut_time / 60)) { + // idle time is longer than login time + idle = now - (up->utmpidlearr_val[x].ui_utmp.ut_time / 60); + } sprintf(idle_time, " :%02d", idle); if (idle == MAX_INT) strcpy(idle_time, "??"); else if (idle == 0) strcpy(idle_time, ""); else { - seconds = idle; - days = seconds / (60 * 60 * 24); - seconds %= (60 * 60 * 24); - hours = seconds / (60 * 60); - seconds %= (60 * 60); - minutes = seconds / 60; - seconds %= 60; + minutes = idle; + days = minutes / (60 * 24); + minutes %= (60 * 24); + hours = minutes / 60; + minutes %= 60; if (idle > 60) - sprintf(idle_time, "%d:%02d", minutes, seconds); - if (idle >= (60 * 60)) - sprintf(idle_time, "%d:%02d:%02d", - hours, minutes, seconds); - if (idle >= (24 * 60 * 60)) - sprintf(idle_time, "%d days, %d:%02d:%02d", - days, hours, minutes, seconds); + sprintf(idle_time, "%d:%02d", hours, minutes); + if (idle >= (24 * 60)) + sprintf(idle_time, "%d days, %02d:%02d", + days, hours, minutes); } strncpy(remote, up->utmpidlearr_val[x].ui_utmp.ut_host, --- rusers.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message