Commit Graph

72 Commits

Author SHA1 Message Date
A. Wilcox
3c1fed7d65 w: Use POSIX <utmpx.h> functions where available
<utmp.h> has been deprecated since 2001 in favour of <utmpx.h>.

On glibc systems, utmp is just an alias to utmpx, so there is no
functional change using one over the other.

However, on the musl libc, a library (utmps) can be used to provide
utmpx functionality - but not utmp.  This means that procps either
doesn't work properly (`w` shows nothing under musl with default no-op
implementation), or fails to build (utmps provides utmpx.h but no
utmp.h).

This commit will use utmpx.h where available, which allows `w` to work
correctly with utmps and has no change on glibc systems.
2020-12-22 14:59:15 +11:00
Qualys Security Advisory
2503ec3630 w: Clamp maxcmd to the MIN/MAX_CMD_WIDTH range.
The current checks allow out-of-range values (for example, if
getenv/atoi returns ~-2GB, maxcmd becomes ~+2GB after the subtraction).
This is not a security problem, none of this is under an attacker's
control.
2018-06-13 22:05:18 +10:00
Qualys Security Advisory
3a437012f0 w: Prevent out-of-bounds reads in print_display_or_interface().
They occur if disp or tmp reaches host + len: add checks. Also, constify
everything.
2018-06-13 22:04:58 +10:00
Qualys Security Advisory
0151441e15 w: Check return values in print_logintime(). 2018-05-19 07:33:16 +10:00
Qualys Security Advisory
ed3cf6988a w: Replace printf() with fprintf(fout) in print_time_ival7().
This has currently no impact, because print_time_ival7() is always
called with fout = stdout, but fix it anyway.
2018-05-19 07:33:16 +10:00
Wayne Porter
eea5e467ae Added Cygwin build support
strverscmp is included to satisfy a dependency in Cygwin.
Excluded utmp and prctl functions that are not supported currently.
2016-03-10 15:04:27 -08:00
Craig Small
151c05b497 w: Adjust command width
w would error out if the window size was smaller than 71 or some
other fields through environment grew too big. The code was a little
convoluted as well. The minimum length for command was 3, which is
pretty useless.

This change does the following:
 w doesn't care by default the window size
 w will adjust the command length up and down, to a minimum of 7
characters.
 if the fields don't fit, w will line-wrap each line.

The idea being its better the line-wrap than it is to error out.

References: https://bugs.debian.org/183394

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-07-21 22:45:02 +10:00
Craig Small
857bb39d31 w: Fix choice of current process
If there is a PID wrap-around w will choose the wrong process.
For example:
$ ps x -o pgrp,tpgid,start,tty,cmd | grep pts/3
 3834  3834 21:50:26 pts/3    ssh server
 4461  4461 21:57:14 pts/2    grep pts/3
23410  3834 21:07:17 pts/3    mutt
26071  3834   Jul 13 pts/3    /bin/bash

w will show the user as:
csmall   pts/3    my-laptop:S.1   13Jul15  5:54   1.36s  1.13s /bin/bash

So why?
w scans the process table and has two ways of finding the best match.
 #1 match things like terminal,username and process group, find oldest
 #2 match utmp pid to process tgid

The problem is that #2 trumped #1, which is fine when your login process
is numerically lower than your other processes. However in this case
26071 is larger and appears later in the readdir() than the correct
process, which is 3834.

The fix is not not overwrite best if it already exists.

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-07-21 22:25:06 +10:00
Jaromir Capik
f71405b44d w: fixing missing '-' in the FROM field when empty
With 99bebff06a a configurable
width of the FROM column was introduced. Unfortunately this
caused a regression in the dash printing. Hopefully fixed
with this commit.
2015-03-02 18:41:07 +01:00
Craig Small
6437aa08d4 Update options to single strings
To assist the translators, each option is a separate string.
This means if we add/change/delete an option the remaining ones
will just keep working and only the impacted option needs some
translation work on it.
2013-10-11 10:07:10 +11:00
Craig Small
5e4d9d5a92 Merge commit 'refs/merge-requests/2' of git://gitorious.org/procps/procps into merge-requests/2
Conflicts:
	uptime.c
2013-09-11 20:50:48 +10:00
Jaromir Capik
151e4f21da sysctl, w: miscelaneous usage/man fixes
This commit is a result of RH man page mass scan, that failed.
All the broken/missing switches should be fixed now.
2013-07-19 14:50:02 +02:00
Jim Warner
7888f6a679 miscellaneous: clean up trailing whitespace once again
An earlier commit attempted to cleanse our environment
of all useless trailing whitespace. But the effort did
not catch 'empty' lines with a single space before ^J.

This commit hopefully finishes off the earlier effort.
In the meantime, let's pray that contributors' editors
are configured so that such wasted crap is disallowed!

Reference(s):
commit fe75e26ab6

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-04-07 18:05:01 +10:00
Rainer Müller
042776e04c configure: check for program_invocation_name
For portabiliy, check for program_invocation_name during configure and
define HAVE_PROGRAM_INVOCATION_NAME accordingly. Use of this symbol is
now enclosed with the appropriate #ifdef block.

The symbol program_invocation_name is only used for error message
handling using error(), so it's safe to omit this if it is not
available.
2013-03-20 16:32:06 +01:00
Jim Warner
fac3b34ff9 miscellaneous: fixed current misspell-check's findings
Reference(s):
https://github.com/lyda/misspell-check

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-14 12:36:47 +01:00
Jim Warner
fe75e26ab6 miscellaneous: clean up trailing whitespace throughout
The entire tree's polluted with inappropriate trailing
whitespace. This commit rids our environment of all of
those useless keystrokes. Unfortunately, it sure ain't
a permanent solution and requires every contributor to
instruct their editor(s) to prevent or eliminate them.

Plus it's strongly recommended we all insert something
like what's shown below to our '.gitconfig' file so as
to provide at least some warnings when we try to apply
any patches (git am) that do contain the #@!%& things!

References(s):
~/.gitconfig excerpt ---------------------------------
[core]
  whitespace = trailing-space, space-before-tab, blank-at-eof
[apply]
  whitespace = warn
--------------------------------- ~/.gitconfig excerpt

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-14 12:36:47 +01:00
Sami Kerola
d958f1c0fc w: do not truncate command when width is not known
This change also adds a definition, which is in control of all command
buffer size related operations.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-15 12:49:22 +02:00
Jaromir Capik
dcd8cf0b4b Rework of the -i feature
This version detects IPv6 address in the host field
and also IPv6 link interface separated by % sign.
It also handles unprintable characters and spaces better
than the previous one.

Signed-off-by: Craig Small <csmall@enc.com.au>
2012-06-20 22:19:14 +10:00
Jaromir Capik
ca03e0280f Applied corrected patch for w -i
I checked the second patch, saved it, it looked ok.
And then applied the first (wrong) patch. Jaromik gave this correction.

Signed-off-by: Craig Small <csmall@enc.com.au>
2012-05-30 21:37:13 +10:00
Jaromir Capik
2b58862421 Add -i option to w
w can now show IP address for the from field with the -i option
2012-05-29 22:20:36 +10:00
Mike Frysinger
2320dc9cdb w: fix printf compile warning
Building w on an x86_64 system triggers:
w.c:404:4: warning: format '%zu' expects argument of type 'size_t',
                    but argument 4 has type 'int' [-Wformat]

Since we're comparing UT_NAMESIZE to an int, cast it to that type
(since it can't exceed it) and update the printf.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-05-22 20:18:51 +10:00
Craig Small
9af478c13d Remove trailing - from w from column
Jaromir Capik discovered that the from column for w would print
a trailing - for some types of hosts.
2012-04-25 10:21:07 +10:00
Sami Kerola
52269d22f3 all: check stdout and stderr status at exit
If stream status is not checked at the end of execution below problem
would not report error, or non-zero exit code.  The uptime is just an
example same was true with all commands of the project.

$ uptime >&- ; echo $?
uptime: write error: Bad file descriptor
1
$ uptime >/dev/full ; echo $?
uptime: write error: No space left on device
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-23 15:57:53 +01:00
Sami Kerola
031afacb48 w: align header when from lenght is defined
Before this commit header and output was not in sync if
PROCPS_FROMLEN environment variable where defined.  Example of wrong
behavior is below where the last four fields which are skewed.

$ PROCPS_FROMLEN=18 w -f | cat
 12:31:34 up  1:25,  1 user,  load average: 0.03, 0.06, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
sake     tty1     -                  11:06    1:25m  3.76s  0.00s xinit /ho[...]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-04 12:12:42 +01:00
Sami Kerola
c459346303 w: make date string abbreviations nls aware
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-04 11:56:25 +01:00
Sami Kerola
abd9e0f6e2 w: use utmp headers to determine host size as well
Completes change in commit ddd15211e0

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-04 11:53:29 +01:00
Sami Kerola
ddd15211e0 w: use utmp definitions to determine array sizes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>

Conflicts:

	w.c
2012-03-04 08:20:39 +11:00
Sami Kerola
ce61089059 docs: clarification to license headers in files
Add license header to all files.  The summary of licensing is below,
taken from Craig Small's email which is referred in commit message
tail.

sysctl and pgrep are GPL 2+
The rest is LGPL 2.1+

Reference: http://www.freelists.org/post/procps/Incorrect-FSF-address-in-the-license-files,8
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=797962
CC: Craig Small <csmall@enc.com.au>
CC: Jaromir Capik <jcapik@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:41:11 +11:00
Sami Kerola
2347521bb5 w: fix compiler warnings
w.c:409:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
w.c:325:42: warning: unused variable 'args' [-Wunused-variable]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:36:29 +11:00
Craig Small
502a79e02f Merge remote-tracking branch 'sami/to-craig' into sami-merge
Conflicts:
	pgrep.c
	w.c
2012-03-03 13:56:32 +11:00
David Cantrell
3e7f78d296 Add -p|--pretty option to uptime(1) for pretty output.
This patch adds the -p option to the uptime(1) command, which changes
the uptime displayed from something like:

 10:35:52 up  2:33,  1 user,  load average: 1.69, 1.65, 1.63

to:

 up 2 hours, 33 minutes

I originally implemented this as the up(1) program about 14 years ago.
In 2008 or 2009, I created a patch for procps to add this functionality
to uptime and submitted it to the project.  Never heard from the
project and no new releases of procps had been made.  Then I found out
about this project and decided to port my patch to it.  So here it is.

This is really just for fun.  There is no real technical reason to
have this functionality.  But even now, 14 years later, I still get
emails asking where the source code for up is.  So I thought it would
be nice for the uptime command on Linux to sport the up functionality
by default.
2012-02-22 10:35:12 -05:00
Mike Frysinger
0da6537c5f fix printf format warnings
pgrep.c: In function 'main':
pgrep.c:793:4: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long int' [-Wformat]

vmstat.c: In function 'diskpartition_format':
vmstat.c:382:9: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'long long unsigned int' [-Wformat]
vmstat.c:408:10: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'long long unsigned int' [-Wformat]

w.c: In function 'main':
w.c:394:4: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int' [-Wformat]

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-01-26 21:15:42 +01:00
Sami Kerola
79ceb30b5c ps: unify cases and remove trailing dots in messages
Strings with lower caps & no trailing dots have greater change to
have multiple occurences, meaning less effort for translators, than
strings with them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-15 20:52:58 +01:00
Sami Kerola
6241e9d545 w: indicate unknown host when -f is used
The option -f used too print `-' to FROM column when host was not
known. This commit changes behaviour back to what it was earlier.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-08 21:31:56 +01:00
Craig Small
fb11e1fe0a Changed the err and warns to macros
err and warn are BSD format but they are not recommended by library
developers.  However their consiseness is useful!

The solution is to use some macros that create xerr etc which then
just map to the error() function.  The next problem is error() uses
program_invocation_name so we set this to program_invovation_short_name

This is a global set but seems to be the convention (or at least errors
are on the short name only) used everywhere else.
2012-01-03 18:48:43 +11:00
Sami Kerola
c3405fab1a translations: group usage texts
Reference: http://www.freelists.org/post/procps/backporting,5
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-02 16:29:03 +11:00
Jim Warner
94468ac0b3 w: fix broken -o (old-style) short form option 2012-01-02 16:27:38 +11:00
Sami Kerola
0022b6ec5d nls: improve translations and provide translator help comments
Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:54 +01:00
Sami Kerola
c862a4caa5 nls: add functions which take translations to be used
Add the following three functions to most of the commands.

setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);

Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:53 +01:00
Sami Kerola
76841eda26 w: add gettext support
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:04 +01:00
Sami Kerola
7af14af685 w: new usage & fix coding style
Coding style fixed and more readable help output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:02 +01:00
Craig Small
99bebff06a w: use environment to set user and from/host column widths
A patch from Debian.

Bug-Debian: http://bugs.debian.org/396423
Bug-Debian: http://bugs.debian.org/341439
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:57:35 +11:00
Craig Small
88f485e20a w: use COLUMNS environment if TIOCGWINSZ fails
A patch from Debian.

Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:56:59 +11:00
Craig Small
a0a51eb921 w: bassman emulation with -o option
A patch from Debian.

Bug-Debian: http://bugs.debian.org/414906
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:56:41 +11:00
Craig Small
3f59ff5a16 Revert -n flag for w 2011-07-15 08:52:45 +10:00
Craig Small
a26c3bfa39 top hotplug memory support
Another patch from Jim for top to support hot-pluggable memory. Not
fully tested on real hot-pluggable memory because neither of us have
it
2011-07-14 21:16:02 +10:00
Werner Fink
4736dad559 Do not let sysctl abort due a missed file or directory under /proc.
Include signal.h for compiling w.

Signed-off-by: Werner Fink <werner@suse.de>
2011-01-19 12:26:01 +01:00
Jan Görig
63b6a8fcbf Make w make better guesses for user process
Based on suggestion by Herbert Xu <herbert@gondor.apana.org.au>
Bug-Debian: http://bugs.debian.org/187808
Author: Craig Small <csmall@debian.org>
2010-12-16 10:15:35 +01:00
albert
87eb7ec462 w: stale utmp entries snuck in via uninitialized var -- thanks Robert A Basch 2006-06-17 06:14:33 +00:00
albert
7767733812 dietlibc needs termios.h for struct winsize -- thanks Thomas Ogrisegg 2005-10-30 00:04:21 +00:00