summaryrefslogtreecommitdiff
path: root/usr.bin/rusers
diff options
context:
space:
mode:
authorAnthony J. Bentley <bentley@cvs.openbsd.org>2016-03-17 05:27:11 +0000
committerAnthony J. Bentley <bentley@cvs.openbsd.org>2016-03-17 05:27:11 +0000
commit8fcd372cac9eb2e1f5b77be5c644c16050a14ff5 (patch)
tree57ded33cc5e6839167ba569d1e58d6bb92f5bb85 /usr.bin/rusers
parent06ada816bc102f9194fd229056dd05d0a1c41409 (diff)
Switch (non-curses, non-ksh) programs that use COLUMNS to a single idiom.
Previously behaviors were all over the map. This changes them to use COLUMNS first, and either terminal width or a hardcoded value (typically 80) as appropriate. ok deraadt@; man bits ok jmc@
Diffstat (limited to 'usr.bin/rusers')
-rw-r--r--usr.bin/rusers/rusers.114
-rw-r--r--usr.bin/rusers/rusers.c24
2 files changed, 21 insertions, 17 deletions
diff --git a/usr.bin/rusers/rusers.1 b/usr.bin/rusers/rusers.1
index af5af77f727..3061be31ba1 100644
--- a/usr.bin/rusers/rusers.1
+++ b/usr.bin/rusers/rusers.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: rusers.1,v 1.15 2014/04/24 15:03:04 tedu Exp $
+.\" $OpenBSD: rusers.1,v 1.16 2016/03/17 05:27:10 bentley Exp $
.\"
.\" Copyright (c) 1983, 1990 The Regents of the University of California.
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" from: @(#)rusers.1 6.7 (Berkeley) 4/23/91
.\"
-.Dd $Mdocdate: April 24 2014 $
+.Dd $Mdocdate: March 17 2016 $
.Dt RUSERS 1
.Os
.Sh NAME
@@ -79,6 +79,16 @@ and the remote host they logged in from (if applicable).
.It Fl u
Sort by number of users logged in.
.El
+.Sh ENVIRONMENT
+.Bl -tag -width COLUMNS
+.It Ev COLUMNS
+If set to a positive integer,
+.Nm Ns 's
+output is formatted to the given width in columns.
+Otherwise,
+.Nm
+defaults to the terminal width, or 80 columns if the output is not a terminal.
+.El
.Sh DIAGNOSTICS
.Bl -tag -width indent
.It rusers: RPC: Program not registered
diff --git a/usr.bin/rusers/rusers.c b/usr.bin/rusers/rusers.c
index 33af706df8e..95b32f213aa 100644
--- a/usr.bin/rusers/rusers.c
+++ b/usr.bin/rusers/rusers.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rusers.c,v 1.36 2015/12/09 19:39:10 mmcc Exp $ */
+/* $OpenBSD: rusers.c,v 1.37 2016/03/17 05:27:10 bentley Exp $ */
/*
* Copyright (c) 2001, 2003 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -141,21 +141,15 @@ main(int argc, char **argv)
if (hflag + iflag + uflag > 1)
usage();
- if (isatty(STDOUT_FILENO)) {
- if ((cp = getenv("COLUMNS")) != NULL && *cp != '\0') {
- termwidth = strtol(cp, &ep, 10);
- if (*ep != '\0' || termwidth >= INT_MAX ||
- termwidth < 0)
- termwidth = 0;
- }
- if (termwidth == 0 &&
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
- win.ws_col > 0)
- termwidth = win.ws_col;
- else
- termwidth = 80;
- } else
+ termwidth = 0;
+ if ((cp = getenv("COLUMNS")) != NULL)
+ termwidth = strtonum(cp, 1, LONG_MAX, NULL);
+ if (termwidth == 0 && ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
+ win.ws_col > 0)
+ termwidth = win.ws_col;
+ if (termwidth == 0)
termwidth = 80;
+
setvbuf(stdout, NULL, _IOLBF, 0);
if (argc == optind) {