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