Commit Graph

2634 Commits

Author SHA1 Message Date
Craig Small
fdab991bb2 docs: Fix comment for priority
Adjust the pri field for ps.1 because a higher pri field means a
higher priority.

References:
 procps-ng/procps#115
2021-09-15 21:36:40 +10:00
Jan Rybar
08aa15ce4b sysctl: Return non-zero if param setting failed
Real usecase:
'sysctl -w user.max_uts_namespaces=2147483648; echo $?'
returns 0 even though it failed with EINVAL

The close_stream() realised there was an issue and printed an
error but didn't change the return value.

Slightly modified merge request.

References:
 procps-ng/procps!76

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2021-09-15 21:07:43 +10:00
Craig Small
e886010ef7 misc: Add NEWS for previous
References:
 procps-ng/procps!91
2021-09-15 20:54:30 +10:00
Tom Levy
2737850e66 pgrep: Add a newline after regex error messages
The message from 'regerror' does not include a newline.

Test with `pgrep '*'`.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2021-09-15 20:53:12 +10:00
Craig Small
4706f225c9 testsuite: Add sysctl test for directory checks
Adds a test to try to write a sysctl parameter above /proc
and passes if it gives an error message.

References:
 commit f25d462166
2021-09-15 20:16:06 +10:00
Craig Small
2a7c909a1b sysctl: Update previous patch for newlib
This change was cherry picked from old library branch but
missed the change to check the path.

References:
 commit 6389deca5b
2021-09-15 20:09:44 +10:00
Craig Small
6389deca5b sysctl: Support systemd glob patterns
systemd-sysctl handles glob patterns along with overrides and
exceptions. Now the procps sysctl does it too.

The return value for sysctl is consistently either 0 or 1.

Added tests to check sysctl functions.

References:
 procps-ng/procps#191

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2021-09-15 20:07:32 +10:00
Jim Warner
8c23dfdcd4 top: some minor tweaks supporting long cmdline options
This darn patch began as 1 correction to an extraneous
comma in the man document. Then, it grew to include an
adjustment for a couple of additional man page things.

After that, I figured I might as well tighten up logic
dealing with those awful gaps in the getopt_long code.

[ the error_exit mentioned in the associated comment ]
[ will only be taken when '=' ends the argv vectors! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-09-08 21:35:20 +10:00
Jim Warner
2d75b2eb96 NEWS: update to acknowledge top's long cmdline options
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-09-07 08:02:43 +10:00
Jim Warner
922696eb65 top: update man document with new long cmdline options
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-09-07 08:02:43 +10:00
Jim Warner
c91b371485 top: utilize getopt and introduce long cmdline options
For quite some time now, top has stood out like a sore
thumb regarding the approach to cmdline options & help
text.  Only short options were used and that same help
text was displayed for '-h' (help) plus 'v' (version).

[ also, top 'rolled his own' when it came to parsing ]
[ options while avoiding that getopt implementation. ]

Well, with this commit all of that has changed and top
now has added a long form of his options. Additionally
he employs getopt_long() for the bulk of that parsing.

[ however, top will still avoid separate fputs calls ]
[ characteristic of other procps-ng programs when it ]
[ comes to help. rather all such text is one string. ]

Along the way, the following major getopt deficiencies
were addressed, assuming the absence of a new #define:

* an equals sign ('=') is allowed on both option forms

* whitespace is allowed before & after the equals sign

* optional arguments needn't abut their related option
for short form nor is an '=' required with either form

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-09-07 08:02:43 +10:00
Jim Warner
b8118b9fee top: some minor organizational tweaks for man document
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-09-07 08:02:43 +10:00
Jim Warner
9a5a155e75 library: trade 2 strstr & atoi calls for 1 sscanf call
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-24 20:52:10 +10:00
Jim Warner
2a539477b7 library: just eliminate a couple of unnecessary braces
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-24 20:52:10 +10:00
Jim Warner
1c00486728 top: and just eliminate a couple of unnecessary braces
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-24 20:52:10 +10:00
Jim Warner
40cf72b7b9 top: reposition call to cpus_refresh() for consistency
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-24 20:52:10 +10:00
Jim Warner
01fd743d86 top: corrected single man document typographical error
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-24 20:52:10 +10:00
Jim Warner
95294d6e4c top: man page now reflects change for the 'select' i/f
Reference(s):
https://www.freelists.org/post/procps/important-extension-to-newlib,4
. 'select' i/f top response
commit 23776571a7
. 'select' i/f library change
commit af34cc964a

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-17 22:04:51 +10:00
Jim Warner
96e2220068 library: address major bug in the 'listed_nextpid' guy
Ever since 2003, the 'listed_nextpid' routine has been
misrepresenting its duties. Far from finding processes
in a list given to openproc, it just inserted the next
pid in that list into the passed proc_t as BOTH a tgid
and tid. There was no attempt to validate such values.

The net result is that tid & tgid were valid only with
a thread group leader. When called with a pid for some
sibling thread, the resulting tgid would be incorrect.

With this commit, our little function will now attempt
to validate both the tid and tgid. If this should fail
then the fallback position will be the same as what we
inherited. So we're no worse off & likely much better.

[ note that calling the function with a thread's pid ]
[ likely stems from 2011 when a 'readeither' routine ]
[ was added which dealt with both tasks and threads! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-12 21:34:11 +10:00
Jim Warner
f1aad95cd1 library: disabled some code that now serves no purpose
In the patch shown below, two lines involving the flag
PROC_UID were uncommented (enabled). However given the
construct of the readeither function, it is impossible
for the simple_readtask guy to be called when its TGID
leader has already been ignored. So, let's disable it.

[ it's only now true that the lines serve no purpose ]
[ after the commit shown below tweaked readeither to ]
[ access the base directory of the tgid leader. but, ]
[ before that, the 2 lines should have been enabled! ]

Reference(s):
. two lines uncommented
commit af34cc964a
. tweaked readeither
commit a375262609

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-12 21:34:11 +10:00
Jim Warner
243bca8ab0 top: thread mode transitions should remove focus ('F')
The commit referenced below forced a return to row one
whenever there was a thread mode transition. Now, with
our new focus ('F') feature, we should adopt a similar
philosophy so as to avoid potential display anomalies.

Reference(s)
. Jun 2018, force row 1 w/ thread mode transition
commit 19ec80bd41

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:03:23 +10:00
Jim Warner
23776571a7 top: respond to that preceding fix in the 'select' i/f
This patch makes it possible to honor our '-H' threads
switch even when operating under that '-p' switch used
to select/filter only certain pids. Of course, what we
have done is just exploit the new library enhancement.

[ and we're pretending we don't know the enumerators ]
[ PIDS_FETCH_THREADS_TOO + PIDS_SELECT_PID are equal ]
[ to that PIDS_SELECT_PID_THREADS enumerator itself. ]

[ thankfully, those dependencies can be assured with ]
[ a 'make check-lib' which exploits ITEMTABLE_DEBUG! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:03:23 +10:00
Jim Warner
af34cc964a library: repair <pids> api boo-boo in the 'select' i/f
The patch referenced below corrected some flaws in the
procps_pids_select implementation. But, there remained
one flaw which this commit will now hopefully address.

Rather than assume callers wished to select only tasks
and not threads meant a command like 'top -H -p 10329'
works differently under newlib than release 3.3.17. It
fails to honor the '-H' (threads) switch under newlib.

So, to fix that oops, we'll allow that select function
to get threads or tasks depending on its 'which' parm.

Reference(s):
. Oct 2015, some flaws corrected
commit bc616b3615

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:03:23 +10:00
Jim Warner
a375262609 library: ensure thread group leader retrieval accuracy
With that recent addition of the autogroup provisions,
it became apparent that '/proc/<pid>/task' information
is sometimes incomplete. In fact, there's no autogroup
file at all in any '/proc/<pid>/task/<pid>' directory!

As a result, when the top -H mode was invoked, all the
processes showed a -1 for AGID, even the group leader.

So, this commit will ensure that for every TGID leader
its basic '/proc/<pid>' directory will always be used.
The 'task' subdirectory is now only used for siblings.

[ and it's time that readeither prologue was updated ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:03:23 +10:00
Jim Warner
949382afe5 NEWS: announce changes for displaying autogroup values
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
6c426c995e ps: document new items for displaying autogroup values
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
c5d1bdd083 ps: added 2 new fields for displaying autogroup values
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
70566acf34 top: document 2 fields for displaying autogroup values
[ we'll also eliminate a couple of references to the ]
[ repurposed 'F' command which should have gone away ]
[ with the introduction of that new 'focus' feature! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
b789b46f84 top: exploit new items for displaying autogroup values
Ordinarily, whenever a new field is added to top, that
RCF_VERSION_ID should be bumped which then prevents an
older version of top from reading the expanded rcfile.

With this change, however, we'll keep the existing 'k'
version since we've yet to release the newlib version.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
631e5d91f3 library: add provision for displaying autogroup values
In the link referenced below there's an explanation of
the linux autogroup feature which has been around ever
since linux-2.6.38. With that explanation there's also
surprising (maybe shocking) revelations about the nice
and renice commands if CONFIG_SCHED_AUTOGROUP was set.

When autogroups are active, such programs are rendered
mostly useless because the nice value will only affect
scheduling priority relative to other processes in the
same autogroup. In order to accomplish what we thought
of as renice, that nice value in /proc/<pid>/autogroup
must be changed. Altering any single member of a group
will also affect every other member of that autogroup.

So, this commit will set the stage for users of newlib
to display autogroup identifiers plus their associated
nice values (now that their importance is understood).

Reference(s):
https://github.com/nlburgin/reallynice

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
93c0a6cedf ps: eliminated an overlooked obsoleted <pids> API item
When several obsolete linux-2.6 fields were eliminated
and ps responded in the commit referenced below, there
was one reference overlooked. So, with this commit the
reference to PIDS_ALARM has been whacked at long last.

Reference(s):
. Sep 2016, ps response to removal
commit 86992bb58f

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
ece2394be7 top: eliminate all field numbers from the man document
As far back as release 3.2.8 (maybe even farther) this
man page used a number with each field's descriptions.

That practice caused no real harm when top was limited
to a grand total of 26 fields (thru lower case letters
of the alphabet). However, now we've reached 70 fields
and, depending on the name that's chosen, adding a new
field could result in a massive renumbering of fields.

Thus, this patch eliminates such potential by removing
all numbers from section '3a. DESCRIPTIONS of Fields'.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
0360f64027 library: refactor all the readproc.h 'PROC_FILL' flags
The 'PROC_FILL' flags, found in readproc.h, had become
almost unmanageable. The hex values were scattered all
over the map as new flags had been introduced. So this
commit resets all of them and will help ensure any new
flags don't duplicate some already existing hex value.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-09 22:00:23 +10:00
Jim Warner
6318010dab top: document summary area changes involving 2 abreast
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-06 20:17:51 +10:00
Jim Warner
178acafb8a top: allow the summary memory lines to print 2 abreast
The commit shown below introduced two abreast printing
for %Cpu statistics. But, the Memory & Swap lines have
always been printed on separate lines when '4' was on.

With this commit, those lines will now be treated just
like %Cpu stats, either separate lines or two abreast.

Reference(s):
. May 2020, added '4' toggle for 2 abreast
commit 59f5a37a24

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-06 20:17:51 +10:00
Jim Warner
6eb9d4b586 top: add a visual separator to lines printed 2 abreast
When the '4' toggle is on, and Summary Area %Cpu lines
are shown two abreast, it's not always clear where the
separation is between the two processors. So with this
patch we'll now print a vertical bar separator between
them (looking similar to the existing field headings).

We will also reduce that 'GRAPH_suffix' constant to 1,
reflecting the the trailing ']' bracket only, so as to
maximize top's exploitation of available screen width.

[ plus a superfluous double '+ +' has now been fixed ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-06 20:17:51 +10:00
Jim Warner
2e11351b6f top: TREE_FOCUS_X works properly with multiple windows
As promised, this commit will ensure that TREE_FOCUS_X
impacts only the window under which an 'F' was issued.

Previously, when 'F' was invoked it would impact every
window that was displaying forest view. Now, only that
window where 'F' was applied will show the indentation
losses whenever multiple windows were being displayed.

[ each of the 4 windows can now have different focus ]
[ pids active and not impact any other forest views! ]

Reference(s):
. 'TREE_FOCUS_X' introduction
commit c23d2708d4

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-01 20:36:55 +10:00
Jim Warner
38eeba364a top: trade most pids_stack pointers for a WIN_t ppt ix
For every function whose parameters consist of a WIN_t
pointer and a pointer to a pids_stack, we will instead
pass the WIN_t pointer and index to that window's ppt.

This change will save six instructions per invocation,
and converts the index once in those called functions.

[ you can consider this an efficiency change, but it ]
[ is really being implemented so that 'TREE_FOCUS_X' ]
[ #define can be made to behave as one should expect ]
[ when running under top's 'alternate display' mode! ]

[ stay tuned for the very next commit to be pushed!! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-01 20:36:55 +10:00
Jim Warner
335ec18774 top: restored a function prologue lost a long time ago
For some reason, when top was modified to exploit that
<pids> api, one function prologue was removed. So this
commit just restores it to the 'window_show' function.

Reference(s):
. Aug, 2015 - adapted to new <pids> api
commit 77dc22b910

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-08-01 20:36:55 +10:00
Jim Warner
c23d2708d4 top: new #define added for focus ('F') toggle tweaking
Just to see if I could, the new #define will force the
indentation of a parent task to be reset to zero while
maintaining the proper child indentation relationship.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Jim Warner
37a4601882 top: introduced new focus toggle ('F'), man doc & NEWS
[ i also corrected an unrelated typographical error! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Jim Warner
3e922e671d top: introduced new focus toggle ('F'), program source
Sometimes, it might be useful to isolate a parent task
and its forked children from other system activity. As
an example, a user might want to examine workload in a
specific lxc container. Or maybe there is some need to
question what's happening under the same tmux session.

Since forest view mode tends to be a relatively stable
display, it will sometimes satisfy the above need. But
that mode can't currently guarantee the target process
always remains as the topmost task or even is visible.

So, this patch will enable focusing on any parent task
and keeping it as the topmost process while displaying
it and its forked children only. It then appears as if
there is no other activity in that system by virtue of
the blank lines which follow that final child process.

To implement this new feature, top's redundant 'F' key
has been repurposed. It made little sense devoting two
keys to the Fields Management screen (especially since
the key we've taken required two separate keystrokes).

[ and while we're at it, i also added punctuation to ]
[ the prologue for that renamed 'forest_display' guy ]
[ since all other forest functions used punctuation. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Jim Warner
8c2622aea8 top: make eu_TREE_LVL a signed int not an unsigned int
Since the internally kept nesting 'level' under forest
view is limited to a maximum of 101, we will now treat
it as signed to avoid any potential conversion issues.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Jim Warner
fca8bcbd40 library: standardize 'pointer-to-thing' whitespace use
When declaring a pointer there's usually a space after
the thing-pointed-to and no space between the asterisk
and the pointer-thingy itself. So this commit enforces
such conventions where needed on old library elements.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Jim Warner
1c1dd02862 top: whack a label & branch in 'summary_show' function
If there are zero numa nodes then the View_CPUNOD flag
cannot possibly be set. So it was unnecessary to check
both the numa total and View_CPUNOD in 'summary_show'.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Jim Warner
6a8d8ff80b top: added a new #define to test absence of numa nodes
This new #define will produce top results identical to
the results achieved for './configure --disable-numa'.

However it keeps the change entirely local to our top.

[ it has been introduced to test the following patch ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Jim Warner
963d8ad52f NEWS: just play catch up with some top implementations
These changes were already implemented for this newlib
version, but not in the the master branch top version.

[ and we also add the missing 3.3.17 ps 'exe' change ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-07-27 21:17:18 +10:00
Craig Small
db4455cfc9 testsuite: Add test for previous sysctl change
Add a check for path traversal to sysctl.

References:
 commit f25d462166

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2021-07-20 22:45:17 +10:00
Craig Small
f25d462166 sysctl: Check path is under /proc/sys
sysctl would try to read/write any path you gave it either on
the command line or configuration file. It would append /proc/sys
on the path but not check for any sneaky path traversal with ../

This commit means it first resolves all paths using realpath(3)
and then checks the path starts with "/proc/sys/"

At first I thought this might be a non-issue, but perhaps someone
could put a file into the sysctl configuration path and.. do
something? Anyway its a 8-line fix and makes things more correct.

References:
 #179

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2021-07-20 22:36:15 +10:00
Jim Warner
05a720fdba doc: updated NEWS plus top(1) for IO accounting fields
Signed-off-by: Jim Warner <james.warner@comcast.net>
2021-06-25 15:25:51 +10:00