summaryrefslogtreecommitdiff
path: root/usr.bin/rusers
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-11-07 00:02:59 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-11-07 00:02:59 +0000
commita225e0777bbc01cc109e9a3b9e870a3dedb910b8 (patch)
tree4bcbbb036d8bb6274d0325c1966d31aae576d653 /usr.bin/rusers
parent622b3c79012df892537a84831bb118f16af4400f (diff)
When mixing the -l and -i flags sort on each individual user's
idle time, not the minimum idle tiem of all users on the host. This makes the -i option much more useful...
Diffstat (limited to 'usr.bin/rusers')
-rw-r--r--usr.bin/rusers/rusers.111
-rw-r--r--usr.bin/rusers/rusers.c35
2 files changed, 43 insertions, 3 deletions
diff --git a/usr.bin/rusers/rusers.1 b/usr.bin/rusers/rusers.1
index ee474e6ca24..709c483ab63 100644
--- a/usr.bin/rusers/rusers.1
+++ b/usr.bin/rusers/rusers.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: rusers.1,v 1.11 2001/11/06 20:51:19 millert Exp $
+.\" $OpenBSD: rusers.1,v 1.12 2001/11/07 00:02:58 millert Exp $
.\"
.\" Copyright (c) 1983, 1990 The Regents of the University of California.
.\" All rights reserved.
@@ -65,6 +65,15 @@ Print all machines responding even if no one is currently logged in.
Sort alphabetically by hostname.
.It Fl i
Sort by idle time in ascending order.
+Unlike other implementations, when the
+.Fl i
+and
+.Fl l
+flags are mixed the output is sorted by the idle time of each individual user.
+If the
+.Fl l
+flag is not specified, the idle time for a machine is considered to be
+the lowest idle time of a user on that host.
.It Fl l
Print a long format listing.
This includes the user name, host name,
diff --git a/usr.bin/rusers/rusers.c b/usr.bin/rusers/rusers.c
index 5e950117562..a94d5feaaa5 100644
--- a/usr.bin/rusers/rusers.c
+++ b/usr.bin/rusers/rusers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rusers.c,v 1.18 2001/11/06 20:51:19 millert Exp $ */
+/* $OpenBSD: rusers.c,v 1.19 2001/11/07 00:02:58 millert Exp $ */
/*
* Copyright (c) 2001 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -55,7 +55,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: rusers.c,v 1.18 2001/11/06 20:51:19 millert Exp $";
+static const char rcsid[] = "$OpenBSD: rusers.c,v 1.19 2001/11/07 00:02:58 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -97,6 +97,7 @@ void fmt_idle(int, char *, size_t);
void onehost(char *);
void allhosts(void);
void sorthosts(void);
+void expandhosts(void);
void alarmclock(int);
char *estrndup(const char *, size_t);
struct host_info *add_host(char *);
@@ -672,11 +673,41 @@ print_entry(struct host_info *entry)
}
void
+expandhosts()
+{
+ struct host_info *new_hostinfo, *entry;
+ u_int count;
+ int i, j;
+
+ for (i = 0, count = 0; i < nentries; i++)
+ count += hostinfo[i].count;
+
+ new_hostinfo = (struct host_info *)malloc(sizeof(*entry) * count);
+ if (new_hostinfo == NULL)
+ err(1, NULL);
+ for (i = 0, entry = new_hostinfo; i < nentries; i++) {
+ for (j = 0; j < hostinfo[i].count; j++) {
+ memcpy(entry, &hostinfo[i], sizeof(*entry));
+ entry->users = &hostinfo[i].users[j];
+ entry->idle = entry->users->ut_idle;
+ entry->count = 1;
+ entry++;
+ }
+ }
+ free(hostinfo);
+ hostinfo = new_hostinfo;
+ nentries = maxentries = count;
+}
+
+void
sorthosts()
{
int i;
int (*compar)(const void *, const void *);
+ if (iflag && lflag)
+ expandhosts();
+
if (hflag)
compar = hcompare;
else if (iflag)