Commit Graph

2940 Commits

Author SHA1 Message Date
Jim Warner
6b24d11b07 doc: add variable width data display without scrolling
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-05-03 19:21:21 +10:00
Jim Warner
fb32021eeb top: add variable width data display without scrolling
There are times when one might want to see some task's
particular variable width data. However, prior to this
commit, the only way was to first turn on a field then
scroll through it via repeated right arrow keystrokes.

[ this also required that field to be displayed last ]

Needless to say, given the potential length of some of
that variable data this could be extremely cumbersome.

Now with this patch, a Ctrl keystroke combination will
create a separate window at the bottom of the terminal
screen where such variable width data is seen in full.

[ the targeted task is the 1st task displayed, which ]
[ is a convention employed in some existing commands ]

[ the targeted data was determined by these Ctrl key ]
[ combinations: CtrlG = ctrl group; CtrlK = cmdline; ]
[ CtrlU = supplementary groups; plus CtrlV = environ ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-05-03 19:21:21 +10:00
Jim Warner
27f5904edd top: eliminate the 'keys_global' redundant definitions
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-05-03 19:21:21 +10:00
Craig Small
9c5397a941 testsuite: Add check for shared memory
Created a test process test_shm that allocates a shared memory
segment and prints the segment ID. pmap testsuite runs pmap to
check that the segment is found.

The value returned by shmget() is the same value that is printed
in the fifth column /proc/<PID>/maps

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-04-26 22:04:05 +10:00
Craig Small
1f085f5a9f pmap: Don't reopen stdin for reading file
pmap uses freopen to read /proc/self/maps. There doesn't
seem to be a good reason to do this and if pmap has its
stdin previously closed then it fails.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-04-26 21:18:03 +10:00
Craig Small
581ed4bcab Merge branch 'time-river/procps-newlib' into newlib
References:
 procps-ng/procps!155
 procps-ng/procps#236
2022-04-26 20:25:00 +10:00
liutie
e9445a07cf signal: fix suspending ps when receving SIGTERM or SIGHUP
Call trace:
  #0 __lll_lock_wait_private () at
     ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
  #1 0x00007f95c059f9d7 in _L_lock_638 () from /lib64/libc.so.6
  #2 0x00007f95c059f8b6 in _nl_expand_alias
  #3 0x00007f95c059dad8 in _nl_find_domain
  #4 0x00007f95c059d22e in __dcigettext
  #5 0x00007f95c059c05f in __GI___dcgettext
  #6  0x00000000004032b3 in signal_handler (signo=15) at display.c:54
  #7  <signal handler called>
  #8  __memcpy_sse2 () at ../sysdeps/x86_64/memcpy.S:104
  #9  0x00007f95c05d9934 in __GI__IO_getline_info
  #10 0x00007f95c05d99b8 in __GI__IO_getline
  #11 0x00007f95c05e2a5d in __GI_fgets_unlocked
  #12 0x00007f95c059f478 in read_alias_file
  #13 0x00007f95c059f97a in _nl_expand_alias
  #14 0x00007f95c059dad8 in _nl_find_domain
  #15 0x00007f95c059d22e in __dcigettext
  #16 0x00007f95c059c05f in __GI___dcgettext
  #17 0x0000000000403a8d in reset_global () at global.c:410
  #18 0x0000000000402605 in main at display.c:650

The above call trace happens when the ps process is suspending, and the
signal SIGTERM is sent to the ps process at the same time.
Just cancel the SIGTERM and SIGHUP handler when suspending to prevent
the problem.

Signed-off-by: liutie <liutie4@huawei.com>
Signed-off-by: fu.lin <fulin10@huawei.com>
2022-04-26 20:24:42 +10:00
Jim Warner
df4d2dc570 doc: added provision for autogroup nice (AGNI) changes
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-26 20:18:15 +10:00
Jim Warner
e18981ec0a top: added provision for autogroup nice (AGNI) changes
When autogroups are active programs such as renice and
nice are basically useless because the nice value will
only affect the target task priority relative to other
processes in the same autogroup. So to accomplish what
we thought of as renice, /proc/<pid>/autogroup must be
changed. Altering a single member in an autogroup will
also affect every other member of that same autogroup.

Since top's renice provision ('r') suffers constraints
like those of the stand alone nice/renice programs, we
will now provide a means to manipulate that nice value
found within some process' /proc/<pid>/autogroup file.

[ to alter this file for other user's tasks requires ]
[ root privileges, as does setting a negative value. ]

[ however, unlike that 'r' command, this new command ]
[ allows raising *and* lowering all positive values. ]

Reference(s):
. Aug 2021, autogroups added to librady
commit 631e5d91f3
. Aug 2021, autogroups added to top
commit b789b46f84

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-26 20:18:15 +10:00
Jim Warner
71d7cc512a top: the '%CUC' column must be just a little bit wider
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-22 12:02:30 +10:00
Jim Warner
a2c1abb136 ps: that '%CUC' column must be just a little bit wider
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-22 12:02:30 +10:00
Jim Warner
c130f45ec7 library: fix some 'origin' header comments, <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-22 12:02:30 +10:00
Jim Warner
fb093914a5 library: annotate header with tics/jiffies, <pids> api
To avoid potential user confusion, like that reflected
in the previous commit message, a short narrative will
be included in the header file as programmer comments,

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-17 10:43:19 +10:00
Jim Warner
20e44569f5 ps: improved three elapsed 'jiffies/tics' calculations
With openSUSE's tumbleweed release of procps-ng-4.0.0,
their source rpm contained a questionable patch. It is
ostensibly devoted to increasing the accuracy for %cpu
calculations in the ps program. However, in my opinion
it goes too far and is quite flawed for these reasons:

1. Six separate files were impacted instead of just 1.
2. While ps was the object, libproc-2 was changed too.
3. A header file's alphabetic item order was violated.
4. The library API and ABI were altered unnecessarily.

It should be noted that all the <pids> TIME items were
made 'real' when representing seconds so that they can
be converted into jiffies/tics if multiplied by hertz.
Thus, there was absolutely no justification for adding
a new PIDS_TICS_ELAPSED ull_int item to the interface.

As an example, assuming a hertz value of 100, there is
enough capacity in all of those 'TIME' seconds to hold
nearly 3 million years worth of tics without a loss of
precision whenever they are changed back into jiffies.

[ that's nine quadrillion seven trillion one hundred ]
[ ninety-nine billion two hundred fifty-four million ]
[ seven hundred forty thousand nine hundred ninety + ]
[ one! or more concisely, as: 9,007,199,254,740,991. ]

So, any need for increased accuracy in that ps program
can be realized within the single output.c file alone.

That's what will be accomplished with this new commit.

And for any doubters here's a 'double' capacity proof:

beg ------ 9007199254740991.000000000000000000000 tic|
 d /= 100, 90071992547409.90625000000000000000000 sec
 d /=  60, 1501199875790.165039062500000000000000 min
 d /=  60, 25019997929.83608245849609375000000000 hrs
 d /=  24, 1042499913.743170142173767089843750000 day
 d /=   7, 148928559.1061671674251556396484375000 wks
 d /=  52, 2864010.752041676081717014312744140625 yrs
 d *=  52, 148928559.1061671674251556396484375000 wks
 d *=   7, 1042499913.743170142173767089843750000 day
 d *=  24, 25019997929.83608245849609375000000000 hrs
 d *=  60, 1501199875790.165039062500000000000000 min
 d *=  60, 90071992547409.90625000000000000000000 sec
 d *= 100, 9007199254740991.000000000000000000000 tic
end ------ 9007199254740991.000000000000000000000  " |

[ who knows, maybe we'll even convince openSUSE that ]
[ the original sledgehammer 'dif' should be dropped. ]

Reference(s):
. openSUSE equivalent: 'procps-ng-4.0.0-accuracy.dif'

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-17 10:43:19 +10:00
Jim Warner
9fbe9be45e library: tighten up some TIME calculations, <pids> api
This patch trades some recurring per-task calculations
for calculations performed once at get, select or reap
time. It was prompted by the openSUSE dif named below.

[ my next commit will deal more thoroughly with that ]

Reference(s)
. openSUSE patch named: 'procps-ng-4.0.0-accuracy.dif'

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-17 10:43:19 +10:00
Jim Warner
af443770e3 library: eliminate redundant assignment, <meminfo> api
With the memset to zero of a 'new' meminfo_data struct
near the beginning of the meminfo_read_failed function
there's never a need to later set anything in it to 0.

[ who knows, our patch might even coax opensuse into ]
[ reevaluating that 4.0.0 'overflow' guy named below ]

Reference(s):
. overflow: 'procps-ng-4.0.0-integer-overflow.patch'

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-17 10:43:19 +10:00
Jim Warner
5edeabbd4a ps: that restored aix behavior gets its ultimate tweak
Now that this 'c' variable initial assignment has been
moved outside the looping code, there is no longer any
need to specifically check for space/comma when 'c' is
not '%'. So, let us eliminate those two lines of code.

[ i promise not to change this algorithm ever again! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-17 10:43:19 +10:00
Jim Warner
ef8d1cb6e3 top: remove those winflags which restricted 'x' toggle
On occasion, even as the top author, I wonder why that
'x' toggle has stopped working. Of course, it actually
was working but a locate request ('L') or other filter
('O') operation was active and thus temporarily turned
if off. Such behavior is documented in top's man page.

Well, with this patch that 'x' suppression is no more.

[ the original justification, however, remains true. ]

[ but there's really only one character which causes ]
[ any potential trouble & i'm gonna' keep it secret. ]

[ besides, if a display is corrupted, there's always ]
[ that '=' key which restores things back to normal. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-17 10:43:19 +10:00
Craig Small
4939a1da8d p/version.c: osrelease for Cygwin
On Cygwin systems use a different file and format to get the
OS version.

Thanks to procps Cygwin maintainer Achim!

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-04-11 17:30:25 +10:00
Craig Small
cb5fa94982 build-sys:
While the previous commit checked for a GNU environment so Hurd
compilied ok, this tripped up Cygwin. configure now explicitly tests
for the structure field rather than trying to guess through compilier
flags about what the environment tells us about signals.h

References:
 commit d39d9db079

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-04-11 17:09:53 +10:00
Jim Warner
9e77e138c1 library: fix 'smaps' bug preventing a build with clang
As a result of the issue referenced below, we'll trade
our homegrown offset generator for an 'offsetof' macro
found in the stddef.h header file. This pleases clang.

[ and thanks to Daniel Kolesa for the report and fix ]

Reference(s):
. bug report & recommended solution
https://gitlab.com/procps-ng/procps/-/issues/235

. clang error message
proc/readproc.c:673:9: error: initializer element is not a compile-time constant
        mkENT(Rss),
        ^~~~~~~~~~
proc/readproc.c:661:34: note: expanded from macro 'mkENT'
  #define mkENT(F) { #F ":", -1, (int)((void*)&q->smap_ ## F - (void*)&q->fZERO) }
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-11 16:41:12 +10:00
Jim Warner
7279cd8e4d top: raise %CPU maximum if large numbers of processors
It would appear that openSUSE was the first to release
procps-ng version 4.0.0 (in the tumbleweed distro). As
a result I checked their source rpm and found a couple
of patches I'm porting to newlib for the next release.

This particulate patch, with some changes, is openSUSE
patch 'procps-ng-3.3.10-large_pcpu.patch'. The changes
were strictly cosmetic. They involved whitespace only.

[ it should be noted that the net effect for raising ]
[ the maximum is to produce a '?' in the %CPU field. ]
[ that's because its width is fixed at five columns. ]
[ but at least the '?' won't distort actual results. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-11 16:41:12 +10:00
Jim Warner
6aec3ec93a top: ignore the SIGHUP signal if running in batch mode
It would appear that openSUSE was the first to release
procps-ng version 4.0.0 (in the tumbleweed distro). As
a result I checked their source rpm and found a couple
of patches I'm porting to newlib for the next release.

This particulate commit was a refactor of the openSUSE
patch 'procps-ng-3.3.8-bnc634840.patch'. Unfortunately
their original patch did not have the intended effect.

That was because the amended signal handling logic was
performed well before the command line parameters were
parsed. So the global 'Batch' flag was in its 0 state.

. what follows is the original openSUSE commit message
------------------------------------------------------
Do not setup SIGHUP signal handler if we are in the batch mode

Top enables a signal handler for the SIGHUP signal (loss of terminal).  While
this makes sense for top's default interactive mode, it doesn't make any sense
for batch mode. If you run top in nohup just to collect data over time and
disconnect top finishes which is not what one would expect.
------------------------------------------------------

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-11 16:41:12 +10:00
Craig Small
7597aaf7f9 testsuite: Add AIX field checks for ps
AIX fields (generally %char) have had some love now but
are parsed slightly differently to other fields, so they
have some tests.

References:
 commit 4fbf8d22a9
 https://www.freelists.org/post/procps/some-procpsn4400-fixes,7
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-04-09 14:50:53 +10:00
Craig Small
b159c198c9 sysctl: print dotted keys again
When the globbing update was put into sysctl, you could no longer
simply use the keys because one key could potentially be
multiple paths once the glob expansion occured.  Using the path
instead gave a unique output.

Except certain programs, such as salt, expected the output to use
the dotted path "kernel.hostname" and not "kernel/hostname".

We can no longer use the original key, so now for each path:
  Copy the path
  strip off /proc/
  convert all / to .

The sysctl testsuite was also updated to check for a few different
types of conversion failures.

References:
 commit 6389deca5b
 https://www.freelists.org/post/procps/some-procpsn4400-fixes,4
 https://repo.saltproject.io/

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2022-04-09 14:18:28 +10:00
Jim Warner
4fbf8d22a9 ps: that restored aix behavior is now even more robust
With the commit referenced below a nasty bug affecting
aix parsing was swatted. Beyond the bug, the logic was
enhanced to disallow commas in the format string since
they would otherwise be shown with their field's data.

However, there remained many characters other than ','
that could survive the edits to then be shown adjacent
to the data. Well, with this patch they won't anymore!

[ along the way we will no longer try to forgive the ]
[ use of a double '%%' prefix since that resulted in ]
[ display of one '%' and field code instead of data. ]

Reference(s):
. March, 2022 - restored aix bahavior
commit 8cb646bdfc

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-09 12:57:39 +10:00
Jim Warner
197728491a NEWS: update with 2 ps related release 4.0.0 bug fixes
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-09 12:56:36 +10:00
Craig Small
4f55ee227d NEWS: Mention elogind merge
Reference:
 procps-ng/procps!151
2022-04-01 17:28:53 +11:00
Sven Eden
d014c5c9f2 Add support for elogind
A session manager similar to logind from systemd.
See https://github.com/elogind/elogind

Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
2022-04-01 06:24:38 +00:00
Jim Warner
e914f4b068 ps: restore thread display when using a pidlist option
This commit will once again display threads when using
the -L option along with any of those pidlist options.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-01 17:13:25 +11:00
Jim Warner
8cb646bdfc ps: restore aix behavior while keeping an original fix
The commit shown below broke the aix behavior that Dr.
Fink recently reported. However, in the proposed patch
the old behavior, showing garbage when '%cpu' was used
with an invalid formatting option, would appear again.

So this patch, based on Werner's patch, goes the extra
distance to prevent that. Along the way we'll disallow
commas in the aix format str to prevent their display.

Reference(s):
https://www.freelists.org/post/procps/Procpsng-400-released-with-newlib,2
. Mar, 2022 - where aix bug was introduced
commit 81df85a1b5

Prototyped-by: Dr. Werner Fink <werner@suse.de>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-01 17:13:25 +11:00
Jim Warner
28c50b8564 top: update one function prologue after rcfile changes
When top's rcfile was reorganized, trading that 'char'
based field representation for the 'int' scheme, there
was a function prologue that should have been changed.

Thus, this patch will correct that original oversight.

Reference(s):
. Mar, 2022 - rcfile reorganized
commit 46aa96e438

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-04-01 17:13:25 +11:00
Craig Small
5343716d99 nls: man-po fixes
Add update-po target, to update the manpage po files run
make -C man-po update-po

Updated the po files.

References:
 procps-ng/procps#230
2022-03-23 17:56:20 +11:00
Craig Small
ed5fe5f8b3 misc: Add v4.0.0 to NEWS 2022-03-23 17:56:11 +11:00
Craig Small
61825a5cc5 nls: Update translations 2022-03-22 21:40:10 +11:00
Craig Small
b98e5657ee testsuite: ps out tests more lenient
Sometimes due to race conditions or the way dejagnu gates the
output, or even there is another interesting process, the ps tests
sometimes fail. These changes make it a little more lenient without
losing the purpose of the test.

Replaces Debian patch ps_tests

References:
 https://salsa.debian.org/debian/procps/-/blob/debian/2%253.3.17-7/debian/patches/ps_checks
2022-03-22 20:20:53 +11:00
Craig Small
d557ad8a6e testsuite: Return error if tty is TTY
In some build systems, such as the Debian pbuilders, the
environment is strange. The tty is called "TTY" which causes
some of the ps tests to fail.

This commit checks for that specific result and returns ""
so the tests can be bypassed.

Replaces Debian patch fix_checks.

References:
 https://salsa.debian.org/debian/procps/-/blob/debian/2%253.3.17-7/debian/patches/fix_checks
2022-03-22 19:53:28 +11:00
Jim Warner
a5e12e768b library: fixed some header inconsistencies, <pids> api
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-22 19:49:03 +11:00
Jim Warner
8502c49619 top: why not maximize usage of some manifest constants
Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-22 19:49:03 +11:00
Craig Small
7fede95f8a nls: Remove incorrect Romanian file
This is for psmisc
2022-03-21 22:01:53 +11:00
Craig Small
6744c9d257 nls: Add Romanian (ro) translation 2022-03-21 22:01:29 +11:00
Craig Small
3fb2ce456e nls: Update translation files 2022-03-21 21:55:01 +11:00
Craig Small
b800d3f1a7 build-sys: check depends on programs
For some unknown reason, make check doesn't depend on either
the check programs or the actual programs under test. This means
if you try to run make check right off the bat from a clean git
repositorty, it will fail as it won't be able to run the unbuilt
binaries.
2022-03-21 21:37:17 +11:00
Craig Small
79949b18ef build-sys: Repeat man pages into man-po Makefile
I'm not sure why this is needed, but if the dist_man_MANS
variable is not copied from the top-level Makefile down to the
man-po one then make dist from a clean archive will not work.

I'm sure someone with better automake magic than me can make
this more elegant but for now it works if a little ugly.

References:
  https://www.freelists.org/post/procps/important-newlib-patches,8
2022-03-21 21:33:11 +11:00
Jim Warner
8a5f3f7b26 top: fix initial cursor position for fields management
When we transitioned from 'char' based fields to 'int'
proper initial cursor positioning (highlight) was lost
in the 'fields_utility' function. The highlight should
appear on the current sort field. Instead, however, it
was often positioned on the first field listed or some
completely different field other than that sort field.

So this patch will restore the master branch behavior.

[ and on the assumption that a sort field is visible ]
[ we will search first for a field with the 'on' bit ]

Reference(s):
. Mar, 2022 - trade 'char' for 'int'
commit 46aa96e438

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-21 21:13:46 +11:00
Jim Warner
6c35695485 top: add more robustness to logic for reading a rcfile
At this point I don't know if the Rc.id ever carried a
value of 'b', 'c', 'd' or 'e' in a public release. But
I do know that those values ought not to be recognized
in any configuration file. Now they won't be for sure.

[ the net result is that now a user with such a file ]
[ will see the 'incompatible rcfile' message instead ]
[ of that misleading 'window entry corrupt' message. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-21 21:13:07 +11:00
Jim Warner
255383a8cd top: do not add an extra line when rewritting a rcfile
When the configuration file is first written, there is
just the normal single newline which ends that rcfile.

However, when any existing rcfile was rewritten, there
was one extra newline '\n' character added at the end.
This will happen just once. The file does NOT continue
to grow with the extra blank lines always being added.

Anyway, this patch will put an end to such a practice.

[ along the way i fixed an unrelated whitespace oops ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-21 21:13:07 +11:00
Jim Warner
212de8cf8c top: man page now has 'UTILIZATION_C' as newest column
When %CUC was added in the commit shown below I failed
to update the man document. This fixes that oversight.

Reference(s):
commit cfa5538832

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-21 21:13:07 +11:00
Jim Warner
5822210618 top: swat a bug with 3.2.8 support for field additions
This new integer based version of 'fieldscur' deviated
a bit too much from that character based logic when it
comes to ancient 3.2.8 rcfile support. This results in
an inappropriate extra field shown as the last column.

If we're truly dealing with 20 year old 3.2.8 rcfiles,
it's important the 3.3.9 extension (RCF_PLUS_H) not be
concatenated to what was read. That's because a search
for the special SUSE characters will always find a '\'
in the 26th position (after normal 3.2.8 'fieldscur').

[ for symmetry, we'll also avoid RCF_PLUS_J (3.3.17) ]

All other 'old' rcfiles are transformed without error.

Reference(s):
. Mar, 2022 - 3.2.8 support restores

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-15 22:02:46 +11:00
Jim Warner
980dc08a5b top: honor old rcfiles after change to field additions
This patch will restore the previously abandoned older
rcfile support. To be honest, I wasn't sure this would
be possible given the vast difference between formats.

But after some very intense hacking our newlib top can
again fully support seamless migration from some older
'char' based file to this new 'int' based file format.

[ top even supports a 20+ year old 3.2.8 config file ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2022-03-15 22:01:32 +11:00