Commit Graph

87 Commits

Author SHA1 Message Date
Jim Warner
831bd8cf29 w: responded to those library changes for 'TIME' stuff
The library refactored 'TIME' items for consistency so
we must adapt to some new data types and calculations.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-02-27 21:27:02 +11:00
Craig Small
15c8b8e2cf w: Remove unreachable l option code
@ruihongw quite rightly pointed out we removed the l option
from the man page and getopt but the iunreachable case statement
remained.

References:
 commit 94468ac0b3
 #162

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2021-03-11 21:48:14 +11:00
Jim Warner
423297c9db all: make buildable again for new 'misc.h' header file
With the 4 header files removed in the previous patch,
this commit just changes all those obsolete references
to that new consolidated 'misc.h' header file instead.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-01-21 17:30:25 +11:00
Craig Small
68f0941433 Merge branch 'awilfox/procps-utmpx-support'
References:
 procps-ng/procps!67
2020-12-22 15:09:08 +11:00
Jim Warner
1aa8b16441 library: eliminated the questionable 'procps.h' header
There was a time when that procps.h file served a more
traditional role. Prior to the commit referenced below
it held just macros plus manifest constants. But, with
that change, such items were replaced with a series of
includes embracing all the library exported functions.

That approach was known to disguise errors which would
have otherwise yielded a compiler warning. And without
such a warning, there was no way to address the error.

So this patch will trade the all inclusive header file
approach for individual includes only where necessary.

Reference(s):
. April 2016, procps.h header file revamped
commit ccb6ae8de1
. Sept 2018, top abandoned use of procps.h
commit a6dfc2382e

Signed-off-by: Jim Warner <james.warner@comcast.net>
2020-07-05 21:13:01 +10:00
Qualys Security Advisory
eaec2d0977 0121-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-23 21:59:14 +10:00
Qualys Security Advisory
e24804a9de 0120-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-23 21:59:14 +10:00
Jim Warner
105058ae2d related: fix inconsistencies in result type references
This patch is a response to errors found in those type
references now that our library allows for validation.

In two cases, former assignments to a result structure
could no longer employ that VAL macro if validation is
active. Thus, direct reference to some stack was used.

For the record, those instances were to be found here:
. ps - uses PIDS_extra to store the cooked pcpu values
. top - uses PIDS_extra to store the forest view level

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-07 21:40:48 +10:00
Jim Warner
e0515e23e7 related: respond to VAL macro addition of context parm
Since the VAL macro now requires a 4th parameter, this
commit simply adds the 'info' context structure to it.

In some cases, that context structure needed to become
global, since it was referenced in multiple functions.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-07 21:40:48 +10:00
Jim Warner
612f36189e related: change for lost 'PROCPS_' enumerator prefixes
With this patch we've completed a progression toward a
standard approach to naming conventions which follows:

* Only functions will begin with that 'procps_' prefix
. ........................................... examples
. procps_vmstat_get ()
. procps_diskstats_select ()
- ----------------------------------------------------

* Exposed structures begin with the module/header name
. ........................................... examples
. struct pids_info
. struct stat_reaped
- ----------------------------------------------------

* Item enumerators begin like structs, but capitalized
. ........................................... examples
. VMSTAT_COMPACT_FAIL
. MEMINFO_DELTA_ACTIVE

[ slabinfo varies slightly due to some item variants ]
. SLABINFO_extra
. SLABS_SIZE_ACTIVE
. SLABNODE_OBJS_PER_SLAB
[ could cure with a prefix of SLABINFO, but too long ]
- ----------------------------------------------------

* Other enumerators work exactly like item enumerators
. ........................................... examples
. PIDS_SORT_ASCEND
. STAT_REAP_CPUS_AND_NODES
- ----------------------------------------------------

* Macros and constants begin just like the enumerators
. ........................................... examples
. #define SLABINFO_GET
. #define DISKSTATS_TYPE_DISK
- ----------------------------------------------------

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-26 20:49:44 +10:00
Jim Warner
d7cbf3448f related: adapt to changes in 'context' structure names
Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-26 20:47:50 +10:00
Jim Warner
a2c79b6237 misc: adapt others to struct layout change, <PIDS> api
With the change to struct pids_fetch, we'll just trade
some dot ('.') code for some pointer to ('->') syntax.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-28 21:11:25 +10:00
Jim Warner
56def1cbac misc: adapt others to changes in interface, <PIDS> api
I've got nothing to add to the commit message but that
doesn't mean I won't produce perfectly justified text.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-16 19:58:20 +10:00
Craig Small
ccb6ae8de1 library: cleanup of library includes
The includes used to define a lot of things a library include
should not. It was also a bit messy what was exposed in the library
and what was not.

get_pid_digits -> procps_pid_length and exported correctly

MALLOC attribute move into relevant .c files
NORETURN attribute moved to relevant .c, not used in library
PURE attribute removed, it wasn't used
KLONG/KLF/STRTOUKL were fixed for long, so now just use long

HIDDEN attribute removed. It was for 3 functions. The PROCPS_EXPORT
seems to do the same (opposite) thing.

likely/unlikely removed from most places, its highly debateable
this does anything useful as CPUs have gotten smarter about branches.

Re-arranged the includes, ALL external programs should just #include
<proc/procps.h> then proc/procps.h includes headers for files that
have exported functions. procps.h and the headers it includes should
not use items that are not exportable (e.g. hidden functions or
macros) they go in procps-private.h
2016-04-16 17:03:57 +10:00
Wayne Porter
e50ad77997 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-12 15:07:30 +11:00
Craig Small
7b08ad19cc 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>

Ported-by: Jim Warner <james.warner@comcast.net>
From original:
commit 151c05b497
2015-10-14 21:34:22 +11:00
Jim Warner
4c31bb49e5 w: correct program help & man page regarding arguments
This commit is an outgrowth of the research into a bug
involving the recently added enum 'PROCPS_PIDS_extra'.

Since this program is not equipped to filter more than
one user, the help text and man document were updated.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-09-07 18:11:48 +10:00
Jim Warner
14359a0afe w: eliminate inappropriate cmdline padding with spaces
This commit is an outgrowth of the research into a bug
involving the recently added enum 'PROCPS_PIDS_extra'.

The WHAT portion of output is being padded with spaces
since the printf field width format specifier was used
in combination with a precision specifier. This commit
reduces the format string to just that precision part.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-09-07 18:11:48 +10:00
Craig Small
a02911c1ea w: use the new procps_pids library interface
w using the new procps_pids calls from the library. There are
some clean-ups of the code within w as well.
2015-08-31 22:49:11 +10:00
Jim Warner
336748ecc0 misc: remove yet more darn trailing whitespace buildup
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-01 21:28:22 +10:00
Craig Small
639daf5468 library: Update uptime calls to standard format
Changed all the uptime related functions to use the
standard naming procps_uptime_*
2015-06-29 22:09:59 +10:00
Craig Small
cbf25b93e3 library: more mem and stat fixes
Make distcheck now succeeds.
Changed some of the binaries to use the new API.
2015-06-26 22:37:29 +10:00
Craig Small
d7932b9a13 library: uptime API changes
Removed the printf_uptime, binaries can do printf easily enough.
sprint_uptime split into two as there wasn't a lot of common
code
 sprint_uptime(): old style uptime line
 sprint_uptime_short(): short new style "uptime -p"

Hertz_hack needed this, no sane system uses the code (I think)
so just assume 100 like we do in FreeBSD.
2015-06-26 22:37:28 +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