Commit Graph

108 Commits

Author SHA1 Message Date
Jim Warner
30e27d48e9 misc: adapted programs impacted by header file changes
Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-03-26 19:55:30 +11:00
Qualys Security Advisory
7e55bff63b 0125-vmstat: Prevent out-of-bounds writes in new_header() and diskheader().
This does not happen with the default string (" -----timestamp-----"),
but this string is translated (to unknown lengths).

Signed-off-by: Craig Small <csmall@enc.com.au>
2018-06-23 21:59:14 +10:00
Qualys Security Advisory
aca26df501 0124-vmstat: Check return values of localtime() and strftime().
Otherwise it leads to NULL-pointer dereferences (in case of localtime()
errors) and indeterminate contents of timebuf (in case of strftime()
errors).

Signed-off-by: Craig Small <csmall@enc.com.au>
2018-06-23 21:59:14 +10:00
Qualys Security Advisory
c7e17f4439 0123-vmstat: Replace memcmp() with strncmp().
Otherwise this may read out-of-bounds (there is no guarantee that 5
bytes are actually available at partition/optarg).

Signed-off-by: Craig Small <csmall@enc.com.au>
2018-06-23 21:59:14 +10:00
Qualys Security Advisory
e37e4528d0 0122-vmstat: getopt*() returns -1 when done, not EOF.
Luckily, EOF is usually -1, but this is not guaranteed by the standard.

Signed-off-by: Craig Small <csmall@enc.com.au>
2018-06-23 21:59:14 +10:00
Jim Warner
108ac50039 vmstat: respond to enhanced <slabinfo> parameter check
Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-12-20 21:18:54 +11:00
Jim Warner
2d5b7e580f vmstat: eliminate some printf format/argument warnings
In the commit referenced below, we lost several format
string qualifiers which produced several new warnings.

Reference(s):
commit ccbd818cb4

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-12-20 21:18:53 +11:00
Craig Small
ccbd818cb4 vmstat: Fix alignment for disk partition format
The disk partition format translation hint, the actual text and the
printf statements were all diagreeing with each other. This meant
the disk partition output from vmstat was a mess.

Now all the titles and values line up and everything is right-aligned
which looks better than some half-hearted attempt at center-aligned
for titles and right-aligned for values.

Thanks to @goeran for the heads-up in #69
2017-09-25 09:24:42 +10:00
Jim Warner
105de6264c misc: adapt 3 programs to some enum changes, <meminfo>
That preceding commit corrected a little mismanagement
regarding the MEMINFO_MEM_CACHED enumerator, which was
used in the following programs: free, top plus vmstat.

This patch simply adapts those programs to use the new
MEMINFO_MEM_CACHED_ALL enumerator, which reflects both
the 'Cached' plus 'SReclaimable' values they expected.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-06-04 21:36:23 +10:00
Jim Warner
41f7a90afd misc: use 'VAL' macros to benefit from type validation
These 2 programs accessed newlib stacks directly which
meant incorrect result type specifications couldn't be
detected using our new result type validation feature.

And, while the usage was correct, to put each on a par
with all of our other programs, they now rely on those
newlib offered VAL macros for accessing stack results.

[ the ps and top programs retain direct stack access ]
[ when assignment to some result struct is necessary ]

[ PIDS_extra is used by top to store the forest view ]
[ level, while ps uses it for cooked cpu percentages ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-16 21:06:18 +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
5c857b865e misc: tweaks (mostly cosmetic) to several source files
. a more appropriate error return code was substituted
. a safer form of comparison is utilized in two places
. a STAT_VAL macro replaced by more proper MEMINFO_VAL
. several of the silly 'xerrx' formats had been missed
. a few whitespace changes have also been incorporated

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-28 20:46:18 +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
69557ac9dc vmstat: adapted for changes in an i/f, <DISKSTATS> api
This patch is a response to changes to the <diskstats>
interface. And the following represents the summary of
significant unrelated alterations that were also made.

+ corrected that 'milli weighted IO' output, which has
been wrong since that original patch referenced below.
as implemented, it duplicated 'milli spent IO' output.

+ restored original commit intent regarding disks with
a partition switch as represented in references below.

+ moved all item enumerators up near the source start.

+ removed all remaining tabs and inconsistent indents.

+ reformatted the silly style applied to 'xerrx' uses.

Reference(s):
. disallowed 'disks' under 'partition' switch
commit 7df7795b92
. original commit with disk/partition rational
commit e445f7e6c5

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-26 20:46:36 +10:00
Jim Warner
7df7795b92 vmstat: disallow 'disks' under that 'partition' switch
Emulating the presumed proper behavior of the original
program, when the -p switch is used we will now report
an error if that provided name matches some disk name.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-17 08:49:48 +10:00
Jim Warner
dfedcdd883 vmstat: correct that wide-format when displaying disks
Back in July of last year, when vmstat was modified to
exploit the 2nd gen <slabinfo> alloc & sort provision,
yours truly introduced this bug (in the commit below).

Reference(s):
commit 8d9612f782

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-17 08:49:48 +10:00
Jim Warner
428ef496a6 misc: adapt others to the changes in 'get' return type
Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-21 20:58:09 +10:00
Jim Warner
8a7fcc02d1 misc: adapted other pgms to changes in, <SLABINFO> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-09 20:51:06 +10:00
Jim Warner
acb83a2b74 vmstat: adapted to the interface changes, <VMSTAT> api
This commit just eliminates all the procps_vmstat_read
calls since the interface now handles that requirement
as needed when the 'get' and 'select' guys are called.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 21:04:43 +10:00
Jim Warner
fa0d983a7d vmstat: fix 1st time enumerators so zeros aren't shown
Some DELTA versions were used where raw totals needed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 21:04:43 +10:00
Craig Small
c1a3b45755 vmstat: sys variables are unsigned longs
When the API changed for the use_format the type changed for the
system variables out of stat, but the printf format was not changed
along with it.

vmstat.c:868:14: warning: format ‘%lld’ expects argument of type ‘long
long int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
     printf(_("%13lld interrupts\n"), SYSv(sstat_INT));

References:
 commit 2e6435a39d

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2016-05-16 20:03:11 +10:00
Craig Small
2e6435a39d vmstat: use_format use new stat select
While new_format was using the new stat select feature the
use_format did not. This type of format now uses the select setup
for both the meminfo and stat set of information.
2016-05-14 16:28:47 +10:00
Craig Small
d8d375fce2 vmstat: use new API for meminfo and stat
Update vmstat to use the select functions for both the stat and
memory information.
2016-05-12 22:40:32 +10:00
Jim Warner
7364e3ea89 vmstat: interface change separate patch, <MEMINFO> api
In view of Craig's work with the vmstat <STAT> change,
adaptation to <MEMINFO> changes is offered separately.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-12 07:51:10 +10:00
Jim Warner
21360027e5 misc: adapt additional programs to changes, <STAT> api
This patch brings the ps program (very small impact) &
that vmstat program (major impact) into agreement with
the new <stat> API. In the case of the latter guy, the
many separate calls to 'get' should be replaced by one
single 'select' call obtaining all data in one stroke.

[ but, i was too tired to undertake that enhancement ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-08 21:12:22 +10:00
Craig Small
55f7dd0648 vmstat: free before return
Previous commit the free was added after the return. That doesn't
work as planned.

References:
 commit 6151b794c6
2016-05-03 21:57:00 +10:00
Craig Small
6151b794c6 vmstat: Various resource_leak fixes
Using *_unref to free up the memory. Most of these are one-shot
so not terribly important anyhow.
2016-05-01 16:18:10 +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
Jim Warner
88daa89883 miscellaneous: silence a whole bunch of clang warnings
[ but most definitely not all of them by a long shot ]

Reference(s):
proc/diskstat.c:186:17: warning: unused variable 'is_disk' [-Wunused-variable]
    int retval, is_disk;
                ^
proc/namespace.c:110:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
proc/readproc.c:1131:50: warning: address of array 'ent->d_name' will always evaluate to 'true' [-Wpointer-bo
    if(unlikely(unlikely(!ent) || unlikely(!ent->d_name))) return 0;
                                           ~~~~~~^~~~~~
proc/readproc.c:1158:50: warning: address of array 'ent->d_name' will always evaluate to 'true' [-Wpointer-bo
    if(unlikely(unlikely(!ent) || unlikely(!ent->d_name))) return 0;
                                           ~~~~~~^~~~~~
proc/sysinfo.c:45:12: warning: unused variable 'stat_fd' [-Wunused-variable]
static int stat_fd = -1;
           ^
proc/sysinfo.c:49:12: warning: unused variable 'meminfo_fd' [-Wunused-variable]
static int meminfo_fd = -1;
           ^
proc/sysinfo.c:51:12: warning: unused variable 'vminfo_fd' [-Wunused-variable]
static int vminfo_fd = -1;
           ^
proc/sysinfo.c:53:12: warning: unused variable 'vm_min_free_fd' [-Wunused-variable]
static int vm_min_free_fd = -1;
           ^
proc/uptime.c:157:12: warning: unused variable 'realseconds' [-Wunused-variable]
    time_t realseconds;
           ^
proc/uptime.c:158:16: warning: unused variable 'realtime' [-Wunused-variable]
    struct tm *realtime;
               ^
vmstat.c:574:20: warning: format specifies type 'unsigned int' but the argument has type 'unsigned long' [-Wformat]
                   DSTAT(PROCPS_DISKSTAT_READ_TIME),
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vmstat.c:578:20: warning: format specifies type 'unsigned int' but the argument has type 'unsigned long' [-Wformat]
                   DSTAT(PROCPS_DISKSTAT_WRITE_TIME),
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watch.c:230:7: warning: variable 'endptr' is uninitialized when used here [-Wuninitialized]
        if (*endptr == '\0') set_ansi_attribute(0); /* [m treated as [0m */
             ^~~~~~

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-09-21 22:34:27 +10:00
Jim Warner
ae4b686745 library: eliminate extra stack header space provisions
With the new perspective on potential uses of a 'noop'
enumerator (or whatever we decide to call it) there is
no longer a need to provide for any extra 'user' space
in the stack header structures used by slab & meminfo.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-23 22:31:50 +10:00
Jim Warner
2ceb4c31da library: readstat redesigned using 'stack' vs. 'chain'
In addition to that text shown below the line which is
common to several commit messages, this patch contains
several minor changes with lessor impact upon the API:

. A call to procps_stat_read_jiffs() has been added to
those jiffs functions carrying the 'fill' nomenclature
to parallel like functions in some of our other files.

. The #include header files are ordered alphabetically
now, with all those <sys/??> types separately grouped.

. Standard copyright boilerplate was added in .c file.

. The header file follows the conventions of indenting
(by 4 spaces) those parameters too lengthy for 1 line.

------------------------------------------------------
. The former 'chains' have now become 'stacks' without
the 'next' pointer in each result struct. The pointers
initially seemed to offer some flexibility with memory
allocations and benefits for the library access logic.
However, user access was always via displacement and a
a statically allocated chain was cumbersome to define.

. An enumerator ending in '_noop' will no longer serve
as a fencepost delimiter. Rather, it has become a much
more important and flexible user oriented tool. Adding
one or more such 'items' in any items list passed into
the library becomes the means of extending the 'stack'
to also include user (not just library) data. Any such
data is guaranteed to never be altered by the library.

. Anticipating PID support, where many different types
must be represented in a result structure, we'll adopt
a common naming standard. And, while not every results
structure currently needs to reflect disparate types a
union will be employed so the same dot qualifier ('.')
can be used consistently when accessing all such data.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-23 22:31:39 +10:00
Jim Warner
6aa36717c4 library: slab is redesigned to use 'stack' vs. 'chain'
In addition to that text shown below the line which is
common to several commit messages, this patch contains
several minor changes with lessor impact upon the API:

. A 'read' was added to function procps_slabnode_count
(but only when necessary, i.e. info->nodes_used == 0).

. The #include header files are ordered alphabetically
now, with all those <sys/??> types separately grouped.

------------------------------------------------------
. The former 'chains' have now become 'stacks' without
the 'next' pointer in each result struct. The pointers
initially seemed to offer some flexibility with memory
allocations and benefits for the library access logic.
However, user access was always via displacement and a
a statically allocated chain was cumbersome to define.

. An enumerator ending in '_noop' will no longer serve
as a fencepost delimiter. Rather, it has become a much
more important and flexible user oriented tool. Adding
one or more such 'items' in any items list passed into
the library becomes the means of extending the 'stack'
to also include user (not just library) data. Any such
data is guaranteed to never be altered by the library.

. Anticipating PID support, where many different types
must be represented in a result structure, we'll adopt
a common naming standard. And, while not every results
structure currently needs to reflect disparate types a
union will be employed so the same dot qualifier ('.')
can be used consistently when accessing all such data.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-23 22:31:32 +10:00
Jim Warner
8d9612f782 vmstat: adapted to exploit the alloc & sort interfaces
In addition to exploiting the new interface, a warning
for a meminfo variable 'used uninitialized' was fixed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-14 22:37:09 +10:00
Craig Small
cf6c2155dc library: rebase & make current initial slabinfo effort
This was Craig's original patch, referenced below, but
it was never pushed to newlib. It has now been rebased
on top of some diskstat stuff to serve as a beginning.

The original effort was perfectly serviceable (after a
memory leak was fixed) but the approach would not have
served future PID needs when that proc_t went bye bye.

The slabtop requirements are similar to those of PIDs.
One must accommodate the variable number of slab nodes
(PIDs) while also accepting different data (char * and
unsigned long). Furthermore, some generalized means to
sort all that acquired stuff must somehow be provided.

So I wanted to try a different approach that seemed to
hold potential for satisfying future top and ps needs.
Subsequent commits will make that attempt, building on
Craig's original patch whose commit msg appears below.
------------------------------------------------------

All of the /proc/slabinfo related calls have been changed
here. They follow the same procps_slabinfo_* format.

Made both the slabtop and vmstat programs use the new
API as one was using the old one and one was just sort
of trying to do its own thing.

Sorting of slabnodes is also possible via the library.

Reference(s):
http://www.freelists.org/post/procps/Sorting-slabsprocesses,3
http://www.freelists.org/post/procps/library-rework-slabinfo-calls

Signed-off-by: Craig Small <csmall@enc.com.au>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-14 22:31:16 +10:00
Craig Small
e445f7e6c5 library: Update diskstat API
The calls for reading diskstat have been moved out of
sysinfo and into new files diskstat.[ch] These new
library calls follow the standard pattern for the
new libprocps.

vmstat is updated to use the new API and also got
the weighted IO time added.

vmstat -p previously would only show partitions, not
disks. There does not appear to be any good reason to
artifically deny a user to use this command on a disk,
rather than a partition so this restriction was lifted.

I also realised using int for devid means you can send
the library negative numbers, the index uses unsigned int.
Other similiar calls will need to be fixed too.

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-07-07 22:42:06 +10:00
Craig Small
855a6a7055 library: remove getpartitions_num from library
getpartitions_num was only used in vmstat and basically counted
partitions in disks, this is now moved to vmstat.
2015-07-01 22:14:30 +10:00
Jim Warner
e88b11f176 library: normalize the readstat context structure name
The new library meminfo & vmstat modules use structure
names for their context which exactly mirror the names
of the very /proc/ files whose particulars they yield.

The one exception to this rule was the readstat module
whose struct was named statinfo yet the file was stat.

This commit simply renames that structure (only) so as
to hopefully establish such a naming convention as our
standard going forward. And, it's makes good symmetry.

[ this module's name itself is just perfect as it is ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-01 21:30:58 +10:00
Jim Warner
6bb1a033b4 library: tweak formatting for readstat header and code
This patch mostly just eliminates darn tab characters.

Plus the library function declarations and definitions
have been standardized. Most visibly, the input params
now have all been indented on their own separate line.

The following names were changed to more closely match
meminfo.c or provide a certain symmetry. Unfortunately
that also impacted some other pgms which were updated.

. 'procps_stat_get' evolved into 'procps_stat_get_sys'
. 'procps_stat_info' is now known as 'procps_statinfo'

[and just a little trailing whitespace was eliminated]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-29 21:29:49 +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
05efbebb66 library: Fix up stat API
Adjusted vmstat to use the new API for memory and CPU statistics
2015-06-26 22:37:28 +10:00
Craig Small
ca4a09c432 library: memory and vmstat API changes
Created new set of functions for meminfo related calls. Liked the
format of that better so changed vmstat around so the look similar.
Missed the makefile change for uptime so added it in now.
2015-06-26 22:37:28 +10:00
Craig Small
a410e236ab library: sysstat and vmstat api changes
Use the standard libc declarations.
For protecting the headers for C++ procps used to have its
own defines, this change makes them use the standard libc ones.

getstat() -> procps_stat_*
vminfo() -> procps_vmstat_*
These two components of the library now use the newer version of
the API with less exposed global variables. The old methods are
there for now.

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-06-26 22:37:28 +10:00
Fredrik Fornwall
00279d692a Use <dirent.h> instead of <sys/dir.h>
Using <dirent.h> and struct dirent instead of <sys/dir.h> and struct direct
is preferred and works on Android which lacks sys/dir.h.

See:
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
2014-08-26 16:01:57 +02:00
Jaromir Capik
dc072aced7 vmstat: Fixing format-security flaws
Previously the headers were printed directly without
the format specifier. That way is considered insecure
and leads to build errors with -Werror=format-security
flag set.
2014-02-05 17:09:45 +01:00
Jaromir Capik
4fcd56bf58 vmstat: Support for timestamps with '-t' & fix for '-wd'
From now the vmstat can append a timestamp to each line in the
VMSTAT and DISKSTAT mode. You can achieve that with the '-t'
switch.
The '-w' switch now works in the DISKSTAT mode too.
2014-02-04 19:10:42 +01:00
Jaromir Capik
1baf31be9b vmstat: wide output still not wide enough?
8 digits per memory column is apparently still too low
for systems with 128TB of RAM. Anyway, setting the limit
to 999TB (12 digits) must be sufficient for now as it
produces wide gaps on "regular" computers.
This commit also increases the number of digits per cpu
columns from 2 to 3 as some of them can hit the 100%
maximum in corner cases.
2014-01-20 19:59:39 +01:00
Jaromir Capik
a8a4a4f595 vmstat: support for time stolen from virtual machines
Surprisingly the code for the 'st' column was added in the past,
but wasn't enabled. The vmstat manual already contains the 'st'
column and this commit finally enables the feature.
2013-11-25 17:39:14 +01:00
Jaromir Capik
1b97942c8e vmstat: -w switch for wider output
This is a rework of the merge request #5 that unconditionally
forced the output to cross the 80 chars border.
With this commit users can switch to the wide output mode
with the -w option.
2013-11-25 16:56:10 +01:00