Commit Graph

92 Commits

Author SHA1 Message Date
Mike Karels
ae3353515b Fix address annotation in xml output from w
The libxo xml feature of adding an annotation with the "original"
address from the utmpx file if it is different than the final "from"
field was broken by r351379. This was pointed out by the gcc error
that save_p might be used uninitialized. Save the original address
as needed in each entry, don't just use the last one from the previous
loop.

Reviewed by:	marcel@
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21390
2019-08-29 02:44:18 +00:00
Bjoern A. Zeeb
fada51254f w: initialize save_p to silence 'may be used uninitilized'
After r351379 save_p may be used uninitialized.  Set it to NULL before
first assignment so that a later NULL check will work correctly.

Reported by:		CI system for gcc platforms
MFC after:		1 week
X-MFC with:		351379 (karels)
2019-08-22 07:52:06 +00:00
Mike Karels
ec9801de1e Change w(1) to compute FROM (host) field size dynamically
It's nice to be able to display a full IPv6 host address if
needed, but it's also nice to display more than 3 characters of a command
line. Compute the needed size for the FROM column in an earlier pass,
and determine the maximum, then print what fits for the command.

Reviewed by:	marcel@ (markm@ previous revision)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21211
2019-08-22 03:28:31 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Alexander Motin
ba86ca7c84 Fix singular/plural "users" output.
It was broken during libxo'fication.

PR:		221039
Submitted by:	timur@
MFC after:	1 week
2017-07-27 14:34:57 +00:00
Marcelo Araujo
807bd0d9f0 Use nitems() from sys/param.h.
Reviewed by:	ume
MFC after:	3 weeks.
Differential Revision:	https://reviews.freebsd.org/D9938
2017-03-10 04:30:31 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Hajimu UMEMOTO
2279a9a428 When -n is specified, don't make bogus DNS queries. Instead,
when -n is specified more than once, hostnames stored in utmp
are attempted to resolve to display them as network addresses.

PR:		212272
2016-09-02 18:28:14 +00:00
Xin LI
ab9cee11d6 w(1) is not setgid binary since r53279, so remove the setgid() call.
Reviewed By:	wollman
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D3541
2015-09-09 05:17:04 +00:00
Mark Murray
339ce033d2 Widen the host field so that a full IPv6 address will be seen. 2015-07-14 18:53:24 +00:00
Allan Jude
630a02daae Fix libxo output from uptime command
the libxo output for uptime returned multiple 'uptime' keys, one each for number of days, hours, and minutes of uptime.
This is invalid JSON.
This patch makes the output the raw number of seconds, as well as adding keys for the individual unit values
A string of the original output from the plain-text uptime command is also added

Differential Revision:	https://reviews.freebsd.org/D2063
Reviewed by:	jmg
Approved by:	marcel
Sponsored by:	ScaleEngine Inc.
2015-04-16 22:09:37 +00:00
Mark Johnston
10b92369a1 Call xo_finish(3) before exiting in usage(). 2015-03-09 03:31:26 +00:00
Michael Gmelin
441ee032a3 Add xo_finish() to w.c in case it's invoked as uptime
Reviewed by:	marcel
Approved by:	marcel
Differential Revision: https://reviews.freebsd.org/D1821
2015-02-10 22:23:52 +00:00
Marcel Moolenaar
bab0558297 Fix text output for the uptime command.
Reported by: "Max N. Boyarov" <zotrix@bsd.by>, ae@
2014-11-11 21:52:10 +00:00
Marcel Moolenaar
76c0abf129 Convert to use libxo.
Obtained from:  Phil Shafer <phil@juniper.net>
Sponsored by:   Juniper Networks, Inc.
2014-11-05 23:54:33 +00:00
Eitan Adler
920aa23dad don't reinvent the wheel: rely on basename(3)
Reviewed by:	nwhitehorn
2014-10-08 05:04:31 +00:00
Andriy Gapon
a29cc9a34b Revert r253748,253749
This WIP should not have been committed yet.

Pointyhat to:	avg
2013-07-28 18:44:17 +00:00
Andriy Gapon
c722ec3a51 remove needless inclusion of machine/cpu.h in userland
MFC after:	21 days
2013-07-28 18:35:43 +00:00
John Baldwin
9f0b6e5e27 - Move 'showthreads' check out of fmt.c.
- Update shadow copy of fmt_argv() prototype in w.c and fix calls for
  additional parameter.
2013-01-19 00:21:55 +00:00
Xin LI
c3a1bb32f4 Set showthread = 0 for w(1).
X-MFC:	together with r245610
2013-01-18 23:54:27 +00:00
Ed Maste
b6eec535d3 Use CLOCK_UPTIME to get the uptime. 2012-10-12 15:03:28 +00:00
Ed Schouten
d11cba9c89 Add missing static keywords to w(1) 2011-11-06 08:18:47 +00:00
Ed Schouten
21632754d6 Only print entries for which ut_host points to a character device.
Now that we use utmpx, we more often have entries for which the ut_line
is left blank. To prevent us from returning struct stat for "/dev/",
check that the resulting stat structure belongs to a character device.
2011-07-05 14:12:48 +00:00
Joel Dahl
da52b4caaf Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with:	imp, rwatson
2010-12-11 08:32:16 +00:00
Rebecca Cran
c08dcaf147 Initialize the execfile argument to NULL instead of _PATH_DEVNULL. This allows the -M option to be used without specifying -N.
PR:	bin/138146
Approved by:	rrs (mentor)
MFC after:	3 days
2010-02-08 21:23:48 +00:00
Ed Schouten
1131779fb3 Port w(1) to utmpx.
Let it print "-" when the TTY string is empty. In this case, it must
also make sure it doesn't match processes who also have no controlling
TTY. Otherwise it will print random kernel processes when trying to pick
the best matching process.

Eventually it should look at the value of ut_pid as well.
2010-01-13 18:09:21 +00:00
David Malone
02f563767b Shuffle parens to avoid type-punning warning. 2010-01-05 21:00:23 +00:00
Xin LI
821df508e8 Revert most part of 200420 as requested, as more review and polish is
needed.
2009-12-13 03:14:06 +00:00
Xin LI
6f2d322192 Remove unneeded header includes from usr.bin/ except contributed code.
Tested with:	make universe
2009-12-11 23:35:38 +00:00
Ed Schouten
dc65bcacb2 Let w(1) use utmpx.
We don't have UT_*SIZE anymore. One of the reasons for that is because
all strings are null terminated, there is no need for apps to copy
strings out of the utmpx structure. This means we can define W_DISP*SIZE
lengths for all columns.

While there, adjust the sizes a little. Steal some bytes from the
username column, while extending the hostname column quite a bit.
2009-12-06 01:10:30 +00:00
Hajimu UMEMOTO
b94f6865f9 When -n is specified, attempt to turn hostnames found in utmp into IP
addresses, again.  However, change a hostname into an IP address, only
when a host has just one A/AAAA RR.

Requested by:	candy__at__kgc.co.jp
MFC after:	2 weeks
2009-11-22 16:51:44 +00:00
Hajimu UMEMOTO
34903a55c3 Fix the problem that the entry broke into two lines with multi-byte
AM/PM format.

Reported by:	takawata
2009-08-30 11:17:42 +00:00
Poul-Henning Kamp
bec1fa8607 Use sysctlbyname 2006-05-11 17:25:36 +00:00
Andre Oppermann
a21cbcb876 Obtain true uptime through clock_gettime(CLOCK_MONOTONIC, struct *timespec)
instead of subtracting 'bootime' from 'now'.

Sponsored by:	TCP/IP Optimization Fundraise 2005
2005-10-17 15:37:22 +00:00
Garance A Drosehn
b8eb1eccee Use the ki_udata field that was recently-added to kinfo_proc, instead of
stealing ki_spare[0] to hold a pointer.
2005-06-04 23:40:09 +00:00
Philippe Charnier
69fe77ce99 Do not print the result of strftime() in case of failure, the content is
indeterminate in such a case. The correct value for 2nd argument is
sizeof(buf). Do not NUL-terminate the result string, strftime() will do it
for us.
2003-09-07 16:31:32 +00:00
Peter Wemm
c76b41b7b5 utmp.ut_time is not a time_t, do not pass a pointer to it to pr_attime(). 2003-06-28 19:11:42 +00:00
Sean Chittenden
d0d0355e4d Fix warning when calling w(1) when logged in via xdm/kdm. This is
really a problem with utmp/wtmp, but takes the same approach as who(1).

Reviewed by:	knu (mentor), mini, silence on -audit
Approved by:	knu (mentor), mini
2002-08-23 04:31:58 +00:00
Juli Mallett
e8e649cc5d ANSI style function declarations. 2002-06-07 01:41:54 +00:00
Warner Losh
3f330d7d1a remove __P 2002-03-22 01:42:45 +00:00
David E. O'Brien
716ced0b62 Back out part of rev 1.51. The lesser impact fix is to just remove
the unused global var.
2002-03-07 22:36:56 +00:00
Mark Murray
8b56c58be4 WARNS=2 fix, use __FBSDID() and sort includes.
WARNS=2 not added to Makefile as it is to become default.
2001-12-11 22:18:47 +00:00
Bruce Evans
6eabd84580 Compensate for "Compensate for header dethreading" by backing it out. 2001-10-10 17:48:44 +00:00
Crist J. Clark
cfd848db6f Fixing a bug that causes very short uptimes (less than one minute) to
be 30 seconds off. (Thanks to Vladimir B.Grebenschikov
<vova@express.ru> for the PR and ru for a more elegant fix.)

PR:		bin/30680
Approved by:	ru
2001-09-22 09:33:00 +00:00
Brian Somers
5b718312b7 When -n is specified, don't attempt to turn hostnames found in utmp
into addresses as we have no idea what address family they belong to.

When -n is not specified, resolve IPv6 as well as IPv4 addresses found
in the host field of utmp.  Use realhostname_sa() to resolve addresses
(the old code was wrong).

Rename ``x'' to ``x_suffix'' to avoid confusion.

Hard code the host column width to 16 (against the imminent increase
of UT_HOSTSIZE in utmp.h).
2001-07-26 19:20:13 +00:00
Poul-Henning Kamp
c59c7f97ad Call kvm_close() before exit for consistency.
PR:		24654
Submitted by:	Daniel Hemmerich zartik@yahoo.com
2001-05-28 21:30:31 +00:00
Thomas Moestl
af943f55f7 Fix the error buffer passed to kvm_openfiles to have a correct length
of _POSIX2_LINE_MAX.

MFC after:	1 week
2001-05-26 00:02:13 +00:00
Mark Murray
6e547eabb8 Compensate for header dethreading. 2001-05-01 08:46:02 +00:00
Andrey A. Chernov
2742fc8eb2 Preserve comma as separator when it is not equal to radix character 2001-03-03 16:47:07 +00:00
Andrey A. Chernov
e25fd27cd1 Don't use "," as load avg. separator because it can be precision point in some
locales, so leads to confusion
2001-03-03 01:32:46 +00:00