Commit Graph

2221 Commits

Author SHA1 Message Date
Jim Warner
d8a0ab8bc1 top: enable alternate '+' placement with collapsed pid
Currently, except for tasks that have no parents, when
a process' children are collapsed the '+' indicator is
shown in the first position within that COMMAND field.

This commit simply provides for indenting the '+' char
so it displays next to that program name/command line.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-01-03 08:01:25 +11:00
Jim Warner
664d2517da top: plug a minor hole in the vertical scrolling logic
In that commit referenced below, a few edge cases were
addressed regarding vertical positioning involving any
'hidden' tasks. But, 2 additional edge cases remained.

In a running top, if the user employed 'other filters'
(o/O) or 'user filters' (u/U) proper vertical position
was not ensured. And, while this could be easily fixed
by striking the home/end or up/down arrow keys, it was
very poor etiquette to shift this burden to the users.

So, this patch plugs that gap, automating the process.

Reference(s):
commit c6e68e2fed

Signed-off-by: Jim Warner <james.warner@comcast.net>
2019-01-03 08:01:25 +11:00
Jim Warner
b3b7a35050 top: a tweak to the forest view collapsed code (again)
From the outset, top has tried to provide some minimal
garbage collection in support of forest view collapse.
For example, with every 'v' keystroke, a check is made
of the currently targeted pids.  If all were negative,
which means expanded, that Hide_pid array was emptied.

Recently, yet another efficiency was added wherein the
continuing scan for a targeted pid was terminated when
a match was found. But, one more inefficiency existed.

When a task which was subject to collapse under forest
view mode has disappeared (ended), repeatedly scanning
for such a pid with each iteration makes little sense.

So this commit will negate such targeted pids and thus
avoid scanning every current task looking for a match.
Then, if 'v' is ever stuck at some point in the future
there will be a chance to empty that Hide_pid[] array.

[ hopefully this will be a final tweak of the forest ]
[ view collapse stuff, but cross your fingers anyway ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-09-12 21:27:46 +10:00
Jim Warner
2b82cbfc2a top: the '#define PRETEND2_5_X' was found to be broken
Our newlib branch has already dropped support for such
old kernels. However, the master branch still supports
them. So this patch will correct a broken #define that
is used to influence the top Summary Area information.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-09-12 21:27:46 +10:00
Jim Warner
86611b461f top: the '#define SCROLLVAR_NO' is bent but not broken
This patch simply avoids an 'unused' variable warning.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-09-12 21:27:46 +10:00
Jim Warner
5e1c339bef top: speed up the collapsed children forest view logic
In forest view mode, once a collapsible parent process
and all of its children (if any) have been identified,
there is no longer a need to scan the remaining tasks.

So this patch will just force a new scan for any other
'Hide_pid' entries which might remain to be identified
after a targeted parent has been completely processed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-13 20:50:01 +10:00
Jim Warner
cfe5b38a19 top: miscellaneous accumulated tweaks to code/comments
This patch includes the following miscellaneous stuff:

. ensure 1 space before any '*' ptr sizeof() reference

. explain the rather cryptic 'ioa' guy a little better

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-13 20:50:01 +10:00
Craig Small
bb272580a6 docs: Update ps.1 to warn about command name length
Previous versions of ps used to only match on the first 15 characters
because that's what the kernel used to provide. Newer kernels have a
longer length for this field so procps has been updated to suit.

References:
 procps-ng/procps#101
 https://bugzilla.suse.com/show_bug.cgi?id=1099091
2018-08-08 20:13:58 +10:00
Craig Small
2658b33900 Merge branch 'jrybar/procps-file2strvec-segfault-sanity'
References:
 procps-ng/procps!71
2018-08-08 20:00:33 +10:00
Jan Rybar
36e066df52 Possible segfault in file2strvec introduced by latest CVE fix
'rbuf' used before allocated.
Revealed by static analysis
2018-08-08 20:00:24 +10:00
Craig Small
c6a6b1ca1d Merge branch 'simonis/procps-master'
References:
 procps-ng/procps!70
 procps-ng/procps#105
2018-08-08 19:55:26 +10:00
simonis
45591f4f85 Build fails if not done from the source root directory (#105) 2018-08-08 19:55:02 +10:00
Jim Warner
f635d8a369 top: existing 'Inspect' pipe feature now more flexible
Currently, it isn't possible to establish an 'Inspect'
pipe that relies on SIGINT to end. That's because this
signal will also end the parent process (top) as well.

So this patch will temporarily ignore that signal when
processing any 'Inspect' pipe, allowing one like this:

. pipe ^I Trace Calls ^I /usr/bin/strace -r -p %d 2>&1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-01 21:27:44 +10:00
Jim Warner
1dd11af4c1 top: avoid unrecognized 'Inspect' entries memory leaks
Upon startup there exists the potential for some minor
memory leakage should some rcfile 'Inspect' entries be
invalid. By delaying any malloc/strdup until after the
entries are completely validated we will prevent that.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-01 21:27:44 +10:00
Jim Warner
4a44f9e3fa top: ensure collapsed children cpu reported accurately
Parent tasks with collapsed children should have their
cpu reflect any unseen tasks only under the following:

1) When built without TREE_VCPUOFF having been defined

2) Exclusively when 'Show_FOREST' display mode was set

3) And only under the current window when in alternate
display mode (except if TREE_VWINALL has been defined)

So, this commit just ensures these objectives are met.

Reference(s):
. issue that began odyssey
https://gitlab.com/procps-ng/procps/issues/99
. original cpu implementation
commit 3da7318683

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-08-01 21:27:44 +10:00
Jim Warner
786bffc253 top: fix the collapsed children cpu segmentation fault
While that 'Hide_cpu' value will always be zero unless
there are collapsed children, the damn array will only
be present when a window's in 'Show_FOREST' view mode.

Reference(s):
https://www.freelists.org/post/procps/important-improvements-to-top,8

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-07-18 20:17:22 +10:00
Jim Warner
8626141d8f top: '^V' is now 'v' (collapse/expand children toggle)
Using Ctrl-V for the collapse children key now appears
as a mistake. First, it's too close to that Ctrl-C key
which would prematurely terminate top. Second, a lower
case 'v' was unused and perfectly compliments an upper
case 'V' which is used to toggle 'forest view' itself.

Reference(s):
https://gitlab.com/procps-ng/procps/issues/99

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-07-18 20:17:22 +10:00
Jim Warner
8c9daf45ab top: some minor renaming, reformatting and rearranging
This commit just addresses these miscellaneous issues:
. always use 'p' for pointers to that proc_t structure
. always match order of local #undef to parent #define
. forest_create use of array index made more efficient

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-07-18 20:17:22 +10:00
Jim Warner
38a668909f top: parent total cpu includes collapsed children, doc
Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-07-17 21:00:51 +10:00
Jim Warner
3da7318683 top: parent total cpu includes collapsed children, pgm
Now, when a parent's children have been collapsed, the
cpu used by those unseen tasks will disappear no more.
Instead such tics will be added to the parent's total.

[ if one wished a return to the 'land of lost tics', ]
[ the '#define TREE_VCPUOFF' directive is available. ]

------------------------------------------------------
Note: With collapsible parents now displaying children
cpu usage, it will eventually be noticed the cpu stats
for the summary area and task areas often vary widely.

It's worth a reminder that for top's summary area each
individual cpu and the cpu summary is limited to 100%,
regardless of how many tics a linux kernel may export.

An individual task is limited to 100% times the number
of threads. But, in no case will cpu usage ever exceed
100% times total number of processors. Such limits are
further reduced under 'Solaris' mode ('I' toggle off).
In this mode, a task cpu usage will never exceed 100%.
These limits will now also apply to collapsed parents.

In addition to those influences, results are subjected
to kernel timer sampling anomalies and the distortions
inherent in a small sample size, made worse by smaller
delay intervals. Often there is just 1 or 2 tics for a
few tasks at smaller intervals such as: 1/10th second.

Anyway, should questions on this subject arise, a good
starting point, beyond the reminders above, is the 1st
link listed below. Those other links were derivatives.

Reference(s):
. from the kernel documentation
https://www.kernel.org/doc/Documentation/cpu-load.txt
. as mentioned in the above kernel documentation
https://lkml.org/lkml/2007/2/12/6
. from above, with many more links on the subject
https://www.boblycat.org/~malc/apc/

Signed-off-by: Jim Warner <james.warner@comcast.net>

top: parent total cpu includes collapsed children, pgm
2018-07-17 21:00:51 +10:00
Jim Warner
e66c36794a top: a refactor to prepare for including collapsed cpu
So that the impact (minimal) of the next commit can be
isolated, this commit just involves a little renaming,
reformat plus a refactor of some proc_t pointer logic.

[ renaming, relocation and changes to 'user_matched' ]
[ wasn't strictly necessary, but now mirrors newlib. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-07-17 21:00:51 +10:00
Jim Warner
c6e68e2fed top: a few tweaks for those scrolling (mostly) changes
This patch just addresses some edge cases with respect
to 'unseen' tasks. Given the ability to preserve other
filters in the rcfile, it's entirely possible the very
first task(s) may not be visible at top startup. Also,
when switching between windows ('a'/'w') we should try
to always position its row #1 on some visible process.

Lastly, a window might have *NO* visible tasks at all.
Therefore, protect 'window_hlp' from an infinite loop.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-26 21:22:12 +10:00
Craig Small
2c2d86e6cc misc: Remove build badge
GitLab now has a separate spot for build status badges outside the
README.

References:
 procps-ng/procps#95

Signed-off-by: Craig Small <csmall@enc.com.au>
2018-06-23 22:51:12 +10:00
Robert Bowmaker
463ed0049c Fix error in vmstat documentation.
Inspection of vmstat.c and experimentation with the binary itself
both confirm that the units of the swap (si/so) fields are
controlled by the --unit option.

References:
 procps-ng/procps!69
 procps-ng/procps#100

Signed-off-by: Craig Small <csmall@enc.com.au>
2018-06-23 22:15:33 +10:00
Jim Warner
95df5a06f4 top: normalize vertical scrolling for hidden processes
To my knowledge, nobody has ever complained about some
anomalies when scrolling vertically if tasks should be
hidden from view. This can happen with the user filter
('u/U') or other filter ('o/O') features. And although
some tasks are not shown, they still impact scrolling.

This is most apparent when that scroll coordinates msg
is on ('C') & up/down arrow keys used (vs. pgup/pgdn).

Now that we can collapse/expand forked children, there
is a potential for yet more of those hidden processes.

So this commit normalizes vertical scrolling providing
an expected behavior. In other words, the up/down keys
skip the unseen tasks to reposition on a visible task.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:57 +10:00
Jim Warner
78dcaffad7 top: refactor the 'scroll coordinates' message support
This patch is simply preparation for upcoming vertical
scrolling enhancements. With those changes, it will be
impossible to predict what the beginning task position
should be at the time the message is currently issued.

This patch will allow such a message to be shown after
the individual windows' tasks have all been displayed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:57 +10:00
Jim Warner
3943b185a9 top: allow collapsible forest view children, documents
Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:57 +10:00
Jim Warner
14eb7275d9 top: allow collapsible forest view children, pgm logic
The issue cited below really dealt with preserving the
'Other filter' criteria in the rcfile. But as an aside
the htop 'F6' feature (collapsed children) was raised.

I took that as an implied challenge and decided to try
implementing a similar feature in top. So, this commit
will now provide a brand new forest view toggle ('^V')
which will be used to collapse/expand forked children.

[ this patch will also lead to additional patches in ]
[ support of more rational vertical scrolling, since ]
[ many more tasks might now be hidden in some window ]

Reference(s):
. where this secondary issue was raised
https://gitlab.com/procps-ng/procps/issues/99

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
57f0ff367c top: to prepare for collapse, move forest view support
In anticipation of a new collapsible child feature, we
will have to make some forest view variables available
to that 'keys_task()' function. This commit just moves
the forest view logic ahead of tertiary input support.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
06d4d985a6 top: 'other filters' saved with config file, documents
Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
a6f86732f2 top: 'other filters' saved with config file, pgm logic
Well, after the rearranging and refactoring, all those
active 'other filter' entries for each window will now
be preserved in the user's configuration file via 'W'.

For raising the issue below, thanks to Marco Ippolito.

Reference(s):
https://gitlab.com/procps-ng/procps/issues/99

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
993d22211f top: refactored some more peripheral 'inspect' support
These modifications are being made now in anticipation
of some coming 'other filter' config file changes. Our
entries must be written last to the rc file since that
is where the users have been told to 'echo' additions.

Therefore, that 'config_insp' function must be adapted
to anticipate a passed buffer that was already primed.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
80057ec06f top: refactored some of that 'other filtering' support
If we are to support preserving 'other filter' entries
in the rcfile, then the current logic setting up those
osel entries for a WIN_t must be shareable for startup
and when interacting with a user. So, this commit just
repositions this current code in a shareable function.

[ along the way, we give the prior guy a proper name ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
1fe5a5415f top: reposition some of that 'other filtering' support
When we get around to saving that 'Other Filter' stuff
in the rcfile, we'll need access to the Fieldstab plus
the justify_pad() function. So this commit repositions
two 'osel' functions in anticipation of adding 1 more.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
2b7779fdeb top: refactor some of that configuration files support
The 'config_file()' function was getting a little long
in the tooth, so this commit simply renames/rearranges
some stuff anticipating 'other filters' in the rcfile.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
e691f75b81 top: let's honor <Esc> key on color mapping screen too
Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
291d98ee50 top: make rcfile duplicate fields check more efficient
Jeeze, there was no need to employ *both* strchr() and
strrchr() when ensuring fields hadn't been duplicated.

So let's avoid one of those function calls completely.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-23 22:03:56 +10:00
Jim Warner
949a3c9c2e top: a tweak to the recent 256-color termninal support
We now use the actual terminfo 'max_colors' value with
the 'color mapping' screen, not that hard coded '256'.

Reference(s):
https://gitlab.com/procps-ng/procps/issues/96
. introduced 256 color support
commit cf057d2fe5

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-13 22:11:29 +10:00
Jim Warner
9ea85bc653 top: treat all of those vertical scroll keys uniformly
When not displaying all tasks (the 'i' toggle is off),
the concept of vertical scrolling has no real meaning.

However, only 2 keys (up/down) impacting that vertical
position were currently being disabled with this mode.

This patch will extend such treatment to the following
additional vertical impact keys: pgup,pgdn,home & end.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-13 22:11:28 +10:00
Jim Warner
9dd7a97c4a top: force return to row 1 for thread mode transitions
This program does a good job of policing that vertical
scrolled position, ensuring that total tasks are never
exceeded. However, during transitions from thread mode
to normal task mode (the 'H' toggle) that wasn't true.

And while there was no real harm done, it did make the
use of up/down arrow keys "appear" disabled especially
if that scroll message was not displayed ('C' toggle).

This patch simply forces a return to row #1 whenever a
user toggles that display between thread & task modes.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-13 22:11:28 +10:00
Jim Warner
42f0a341ba top: fix 'iokey()' flaw preventing proper translations
As it turns out, the very first entry in the 'iokey()'
tinfo_tab was preventing the proper translation of the
simulated PgUp/PgDn keys (ctrl+meta+k/j). Ignoring the
tortured history behind the most recent change to that
entry, this patch restores the previous value and once
again properly translates these particular keystrokes.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-13 22:11:28 +10:00
Qualys Security Advisory
0bfe708c4b 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).
2018-06-13 22:06:51 +10:00
Qualys Security Advisory
0b55f0dc80 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).
2018-06-13 22:06:30 +10:00
Qualys Security Advisory
b4f4718481 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).
2018-06-13 22:06:14 +10:00
Qualys Security Advisory
4ce81d4dcc vmstat: getopt*() returns -1 when done, not EOF.
Luckily, EOF is usually -1, but this is not guaranteed by the standard.
2018-06-13 22:05:57 +10:00
Qualys Security Advisory
2503ec3630 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-13 22:05:18 +10:00
Qualys Security Advisory
3a437012f0 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-13 22:04:58 +10:00
Craig Small
e1eaf83b34 misc: Tell po4a to handle email macros
References:
 https://www.freelists.org/post/procps/newlib-Qualys-patches
2018-06-07 21:52:46 +10:00
Jim Warner
cf057d2fe5 top: provide the means to exploit a 256-color terminal
With the Qualys security audit, we began to harden our
treatment of the top rcfile. In particular, the values
read were checked so as to prevent some malicious user
from editing it in order to achieve an evil objective.

However when it came to colors I was surprised to find
that at least one user edited the rcfile for 256-color
support. Unfortunately, our new checks prevented this.

So this commit will provide the means to exploit those
extra colors with no need to manually edit the rcfile.

Reference(s):
https://gitlab.com/procps-ng/procps/issues/96

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-07 21:35:59 +10:00
Jim Warner
3352bddba5 library: tweak that change to 'supgrps_from_supgids()'
It's good that those Qualys folks were looking over my
shoulder. They suggested a change to that commit shown
below. This improvement was obviously a better choice.

Reference(s):
. original change
commit f9a8009e27

Signed-off-by: Jim Warner <james.warner@comcast.net>
2018-06-07 21:35:59 +10:00