<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.
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.
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>
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>
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.
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.
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>
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.
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>
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>
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>
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>
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>
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>
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>
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.
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>
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>
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>
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.
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>