Commit Graph

86 Commits

Author SHA1 Message Date
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
Jan Rybar
2a7d3f7d70 - Fixing incorrect memory usage assessment due to skipping vmflags parsing
- Resolves Red Hat Bugzilla #1262864, affecting upstream
2016-06-17 21:58:39 +10:00
Craig Small
25f655891f pmap: Minor fixes
Some reasource leaks and a bunch of flags not explictly set.

References:
 Coverity 99162, 99146, 99145
2016-05-17 21:55:14 +10:00
Jim Warner
591ae1746c pmap: finally silence a warning without creating a bug
The patch referenced below silenced an 'uninitialized'
compiler warning but it also created a bug where zeros
appeared under the Address column with that -x option.

So this commit swats that bug and avoids any warnings.

[ while yours truly created that bug, in his defense ]
[ let's at least acknowledge the god awful loop code ]
[ which was the root of the problem & wrong solution ]

[ so the ugliness of this most recent solution is in ]
[ perfect harmony with the *really* ugly loop itself ]

Reference(s):
commit 0299bd15b0

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-16 19:58:20 +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
Cristian Rodríguez
2dfab56755 pmap: Do not display error if shmctl(..IPC_RMID) returns EINVAL
The segment may have been destroyed by the kernel automagically
after shmdt(addr)

How to reproduce:

sysctl -w kernel.shm_rmid_forced=1
./pmap 1
shared memory remove: Invalid argument
[..]
2016-04-28 21:37:46 +10:00
Jim Warner
714ea69c6d misc: adapt others to a changed identifier, <pids> API
Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-19 20:38:18 +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
Emanuele Aina
b921e2e765 pmap: Fix detail parsing on long mapping lines
If the mapping descriptor is longer than 128 chars, the last parsed
character won't be a newline even if the current buffer contains it a
bit further than that. The current code always interprets it as a short
fgets() read instead, and thus keeps calling fgets() until it gets a
newline, dropping valid lines and failing with the following error:

pmap: ERROR: inconsistent detail field in smaps file, line:
 Rss:                 212 kB
2016-04-11 22:14:03 +10:00
Jim Warner
a7153fe49f pmap: adapt to normailzed <pids> select/fill interface
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-05 21:50:01 +11:00
Jim Warner
987f4f2e3e pmap: adapt to changes in <pids> API regarding address
This commit was prompted by that change from 'addr' to
'ul_int' in the <pids> interface. Along the way, KLONG
was removed as having long ago outlived its usefulness
as performance optimizations for weird configurations.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-09-21 22:36:36 +10:00
Jim Warner
e2898e213f pmap: modify to utilize that new procps_pids interface
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-31 17:48:33 +10:00
Jim Warner
0299bd15b0 pmap: silence a clang -Wuninitialized variable warning
Reference(s):
pmap.c:618:20: warning: variable 'start' is uninitialized when used here [-Wuninitialized]
                                               maxw1, start,
                                                      ^~~~~
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-31 17:47:53 +10:00
Jim Warner
8072b6aa84 pmap: correct heading misalignment of VmFlags with -XX
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-31 17:47:37 +10:00
Yuriy M. Kaminskiy
9ed623780f fix integer overflow on 2GiB+ maps on 32-bit platforms
Signed-off-by: Craig Small <csmall@enc.com.au>
2015-06-20 21:39:41 +10:00
Craig Small
92071e963e pmap: print process even if smaps unreadable
pmap would previously print the process name if
/proc/PID/smaps could be opened, even if subsequent
reads failed.  This actually occurs with other users
PIDs.

Kernel 3.18rc1 introduced a change where the file could
not been opened, meaning pmap -X 1 previously showed
the process name and nothing else but NOW shows nothing
make check failed because of this.

This change prints the process name even before trying to open
the file, returning it to previous behaviour.
Thanks to Vincent Bernat for some analysis.

References:
  https://bugs.debian.org/775624
  https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/?id=29a40ace841cba9b661711f042d1821cdc4ad47c

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-01-24 18:53:29 +11:00
Adam Sampson
1d212457f2 pmap: avoid depending on an uninitialised value.
It's possible for the first entry that this reads from /proc/*/smaps to
start with a map_desc-less line like this:

7fa71b77d000-7fa71c288000 rw-p 00000000 00:00 0

in which case sscanf will only read up to inode, and it won't set c; the
code below would then incorrectly discard the next ("Size:") line.

(With GCC 4.9.0, this bug causes the "pmap extra extended output" test
to fail for me.)
2014-08-19 18:59:28 +02:00
Jim Warner
bcbc3c5a02 misc: result after checking all files for misspellings
Reference(s):
https://github.com/lyda/misspell-check.git

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-08-08 22:14:21 +02:00
Craig Small
8e7ef322e2 Update help files
Benno Schulenberg suggested some changes to the help messages
to provide some consistency and clarity for both the users and
translators of procps.

The test needed to be updated as the pmap output changed too.

Signed-off-by: Craig Small <csmall@enc.com.au>
2014-02-02 18:13:01 +11:00
Craig Small
8a38cd5eb4 Split help lines to help translators
To assist translators, the help lines are split so that each translation
chunk has one option. This gives bonus of if we add or change an option,
only that option remains untranslated rather than the entire help block.

Reference:
  http://www.freelists.org/post/procps/procpsng-for-Translation-Project,1

Signed-off-by: Craig Small <csmall@enc.com.au>
2013-12-28 09:25:39 +11:00
Cristian Rodríguez
5a39544b21 Fix off-by-one in pmap
When procps is built with gcc 4.8 address sanitizer

static int one_proc(proc_t * p)..
..
char smap_key[20];
...
(sscanf(mapbuf, "%20[^:]: %llu", smap_key..

rightfully results in an overflow and the program aborts.
2013-05-22 18:22:37 -04:00
Craig Small
293b668d5f Merge commit 'refs/merge-requests/10' of git://gitorious.org/procps/procps into merge-requests/10 2013-04-07 17:58:06 +10:00
Gilles Espinasse
d164f47dd1 procps-ng : fix pmap uninitialized warnings
pmap.c: In function 'one_proc':
pmap.c:529: warning: 'maxw1' may be used uninitialized in this function
pmap.c:529: warning: 'maxw2' may be used uninitialized in this function
pmap.c:529: warning: 'maxw3' may be used uninitialized in this function
pmap.c:529: warning: 'maxw4' may be used uninitialized in this function
pmap.c:529: warning: 'maxw5' may be used uninitialized in this function

Without -d and -x option, that should be doable to trigger the issue but I haven't found how

Signed-off-by: Gilles Espinasse <g.esp@free.fr>
2013-03-26 21:23:28 +11:00
Gilles Espinasse
bccc2404b6 procps-ng : fix pmap unused variable warnings
pmap.c: In function 'print_extended_maps':
pmap.c:310: warning: unused variable 'value'
pmap.c: In function 'config_read':
pmap.c:792: warning: unused variable 'section'
pmap.c: In function 'get_default_rc_filename':
pmap.c:969: warning: unused variable 'ret'
pmap.c: In function 'main':
pmap.c:999: warning: unused variable 'default_rc_filename'

Signed-off-by: Gilles Espinasse <g.esp@free.fr>
2013-03-26 20:55:51 +11: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
Jaromir Capik
43bcb47007 pmap: Fixing -n,-N x -p,-q check
The -p,-q switches are mutually exclusive with -n,-N, but
not between each other. This commit changes the expression
to a correct one.
2013-03-19 10:47:36 +01:00
Jaromir Capik
5c513ce582 pmap: fixing the width measurement of extended_pmap with -q
This commit fixes the width measurement of the extended pmap
function to work correctly with the -q switch. With no header
and no footer only widths of the particular values matter.
2013-03-18 19:43:12 +01:00
Jim Warner
c80e93be47 pmap: a spade is a spade, so let's call a Flags a Perm
For some reason when the new -X/-XX options were added
what was always displayed as 'Mode' became 'Flags'. So
now a precious horizontal space is wasted because that
field's data has only 4 bytes whereas the header is 5.

Moreover, this created a conflict with the top program
which used that name in a column header already. Plus,
top emitted a 'Translation Hint' that suggests the max
chars should be 8 which is a limit pmap needn't share!

The xgettext program provides no way to keep identical
strings separate. This meant both top and pmap will be
sharing not only the msgid but a Translation Hint too.
So, the solution will now be two distinct field names.

Besides the kernel folks document it as 'perm' anyway!

Reference(s):
       new options for pmap
commit faec340719

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-18 18:42:07 +01:00
Jim Warner
0c0c543466 pmap: wield my machete, achieve width-wise nls support
The existing gettext nls support in pmap exposed users
to some potentially ugly misalignments should the text
that's used in headers someday actually be translated.

The length issue had been addressed already for -X/-XX
modes, but the column headers weren't nls translatable
as yet. This commit makes any header (not literally in
/proc/#/smaps) nls aware. It provides translated width
protection to all modes except one that's header-less!

As part of this effort, the occasional two spaces that
preceeded the Mapping column have been reduced to one.

Reference(s):
       new usage & fix coding style
commit d50884788d
       improve translations
commit 0022b6ec5d
       add gettext support
commit d59cf08c9d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-18 18:42:07 +01:00
Jim Warner
3262143a29 pmap: trade inept width approach for printf's built-in
When the new -X/-XX options were introduced, the width
and justification requirements were satisfied with a 2
step approach. First, format strings would dynamically
be built and then employed in the subsequent printf().

This was a total waste of time and resources since the
printf family of functions provide for the '*' width &
precision conventions to meet this need via arguments.

But even more importantly that foolish endeavor always
hides the potential warnings like the one shown below.

Henceforth this pmap will printf in the proper manner!

Reference(s):
       new options for pmap
commit faec340719
pmap.c:459:4: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long unsigned int' [-Wformat]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-18 18:42:07 +01:00
Jim Warner
9db537503d pmap: formatting only changes, for minimum consistency
This patch just adjusts miscellaneous indentation etc.
so we can begin the odious task of addressing the pmap
nls needs with at least a consistently formatted base.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-18 18:42:07 +01:00
Jim Warner
f85439e42d pmap: restore a proper response when arguments missing
Ever since pmap was refactored via the reference below
(and sprinkled with those damn tabs), the response for
the absence of any argument has been an error message.

This patch restores the proper behavior ('usage' text)
and updates the dejagnu 'no arguments' expect pattern.

Reference(s):
commit d50884788d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-18 18:42:07 +01:00
Jaromir Capik
088d77c3ae pmap: New switches - RC support (-n/-N,-c/C) & ShowPath (-p)
This commit introduces 4 new switches for the RC support
and 1 more switch for toggling the path printing
in the mapping field. the configuration file can be used
for a selection of columns to be displayed and for toggling
the path printing in the mapping field.
2013-03-18 16:05:44 +01:00
Jaromir Capik
12ee64c8a3 pmap: fixing pidlist allocation & disabling vmflags in -X
This commit fixes allocation of the pid list so that it
is sufficient for storing the list terminator.

Additionally the vmflags printing in the -X mode is disabled
because it's too long. From now the vmflags are displayed
in the -XX mode only.
2013-02-15 18:51:28 +01:00
Jaromir Capik
d454bfe902 pmap - removing the column width constraints in the -X/-XX modes
This commit changes the width measurement principle in the -X/-XX
modes so that a width of totals is measured instead of the width
of summands. The value of totals is always higher than the value
of summands. That additionally prevents the totals from having
a wrong indentation.

This commit also removes the minimum column width constraints
hardcoded to 7 characters.
2013-02-15 18:51:24 +01:00
Jaromir Capik
20ce346ebd pmap: fixing broken indentation in the -X/-XX modes
This commit changes the processing principle of the -X/-XX modes
from 1-pass to 2-pass. A separate width measurement stage has been
added, so that the real maximum widths can be measured and used
for correct indentation.

The firstmapping variable now has a new value (2) used for the
width measurement stage (1st pass). The printing is disabled
in this stage. The file position is reset to the beginning
of the file once the end of file is reached and the printing stage
(2nd pass) begins.
It's questionable if this approach is sensitive to Read-after-Write
race conditions. Anyway, this feature is a good candidate for
a complete redesign in the future.

Additionally this commit introduces a final cleaning of the list
used for the evaluation of totals in the -X/-XX modes.
2013-02-15 18:51:13 +01:00
Jaromir Capik
365a5fa517 pmap: empty output or crashes on ppc/s390 caused by wrong pidlist type
Previously the pidlist variable was defined as unsigned long *
whilst the openproc function accepts pid_t *.
Both target types differ in size (8 != 4) and therefore the issue
mainly affects big endian architectures.

This commit changes the pidlist type to pid_t * so that it's
compatible with openproc.
2013-02-05 22:10:18 +11:00
Craig Small
dca3c6d08f pmap vmflags support
Some new kernel version added a line in /proc/pid/smaps listing a processes vmflags. This broke pmap such that pmap -X and pmap -XX would always fail.

This patch adds support for the vmflags field so that -X and -XX work again AND they display the flags.

Merge commit 'refs/merge-requests/8' of git://gitorious.org/procps/procps into merge-requests/8
2013-01-24 22:39:42 +11:00
Andrey Bondarenko
bffb097ba0 pmap -x has RSS and Dirty summary
This is largely Andrey's patch based upon merge request #7
If KLONG != 8 the summary didn't print for RRS and Dirty, this commit
restores this behavour for both sizes.

Ref: https://gitorious.org/procps/procps/merge_requests/7

Signed-off-by: Craig Small <csmall@enc.com.au>
2013-01-24 22:26:27 +11:00
William Orr
b9b3d02dac Added support for vmflags in pmap 2013-01-22 22:46:24 -05:00
Jim Warner
7e8ee148d7 pmap avoid SEGV potential with new X/XX detail options
While permissions suggests that /proc/#/smaps contents
are world-readable, in practice this file might not be
available to a non-root process. Whether this is a bug
in the kernel or an intentional design decision really
makes no difference. This commit will protect pmap -X.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit faec340719
Author: Dimitrios Apostolou <jimis@gmx.net>
Date:   Thu Sep 27 22:08:04 2012 +1000

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-12-23 06:48:36 +11:00
Sami Kerola
22ceeca4a6 pmap: fix compiler warnings
pmap.c:80:7: warning: declaration of 'mapbuf' shadows a global declaration [-Wshadow]
pmap.c:63:13: warning: shadowed declaration is here [-Wshadow]
pmap.c:137:37: warning: declaration of 'mapbuf' shadows a global declaration [-Wshadow]
pmap.c:63:13: warning: shadowed declaration is here [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:30:01 +11:00
Sami Kerola
e677476aea pmap: remove memory leaks
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:26:55 +11:00
Sami Kerola
c043c47ddd pmap: use correct types for memory allocation
Fixes error which did not happen always.  Changes of being affected by
the bug where greater the more there where pids defined as pmap argument.
The debian bug referral can almost certainly reproduce the problem,
especially when tried multiple times in row.

pmap: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr)
(((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >=
(unsigned long)((((__builtin_offsetof (struct malloc_chunk,
fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) -
1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) ==
0)' failed.

Reported-by: lee <lee@yun.yagibdah.de>
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=688180
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:22:11 +11:00
Dimitrios Apostolou
faec340719 Two new options for pmap, -X and -XX
Both options provide more information about a process using -X and -XX
flags. The data comes from /proc/PID/smaps so it may vary.

Signed-off-by: Craig Small <csmall@enc.com.au>
2012-09-27 22:08:04 +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
d5c760ee07 pmap: use only address start to range determination
Fix to an edge case.  When user defined begining of address range to
be at between two allocations the previous allocation which ended to
that address was included to printout.  After this commit one will
see only allocations that are within range definition.

$ pmap -A00007f4e0df08000,00007f4e0df08000 895
895:   bash
00007f4e0dd08000   2048K -----  /lib/libreadline.so.6.2
00007f4e0df08000      8K r----  /lib/libreadline.so.6.2
 total             2056K

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-04 12:13:18 +01:00