]> granicus.if.org Git - procps-ng/log
procps-ng
3 years agotop: some minor tweaks supporting long cmdline options
Jim Warner [Wed, 8 Sep 2021 05:00:00 +0000 (00:00 -0500)]
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>
3 years agoNEWS: update to acknowledge top's long cmdline options
Jim Warner [Sun, 5 Sep 2021 05:00:00 +0000 (00:00 -0500)]
NEWS: update to acknowledge top's long cmdline options

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: update man document with new long cmdline options
Jim Warner [Sun, 5 Sep 2021 05:00:00 +0000 (00:00 -0500)]
top: update man document with new long cmdline options

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: utilize getopt and introduce long cmdline options
Jim Warner [Sun, 5 Sep 2021 05:00:00 +0000 (00:00 -0500)]
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>
3 years agotop: some minor organizational tweaks for man document
Jim Warner [Fri, 3 Sep 2021 05:00:00 +0000 (00:00 -0500)]
top: some minor organizational tweaks for man document

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: and just eliminate a couple of unnecessary braces
Jim Warner [Mon, 23 Aug 2021 05:00:00 +0000 (00:00 -0500)]
top: and just eliminate a couple of unnecessary braces

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: reposition call to cpus_refresh() for consistency
Jim Warner [Mon, 23 Aug 2021 05:00:00 +0000 (00:00 -0500)]
top: reposition call to cpus_refresh() for consistency

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: corrected some more miscellaneous man page errata
Jim Warner [Mon, 23 Aug 2021 05:00:00 +0000 (00:00 -0500)]
top: corrected some more miscellaneous man page errata

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: whack a label & branch in 'summary_show' function
Jim Warner [Mon, 23 Aug 2021 05:00:00 +0000 (00:00 -0500)]
top: whack a label & branch in 'summary_show' function

Catch-up with newlib, original commit message follows:
------------------------------------------------------

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>
3 years agotop: added a new #define to test absence of numa nodes
Jim Warner [Mon, 23 Aug 2021 05:00:00 +0000 (00:00 -0500)]
top: added a new #define to test absence of numa nodes

Catch-up with newlib, original commit message follows:
------------------------------------------------------

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>
3 years agotop: man page reflects '-H' impact for '-p' provisions
Jim Warner [Thu, 12 Aug 2021 05:00:00 +0000 (00:00 -0500)]
top: man page reflects '-H' impact for '-p' provisions

Reference(s):
https://www.freelists.org/post/procps/important-extension-to-newlib,4

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: thread mode transitions should remove focus ('F')
Jim Warner [Tue, 10 Aug 2021 05:00:00 +0000 (00:00 -0500)]
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 9dd7a97c4a6861aa3a6217c8a03fc0d2397b2bef

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: document summary area changes involving 2 abreast
Jim Warner [Thu, 5 Aug 2021 05:00:00 +0000 (00:00 -0500)]
top: document summary area changes involving 2 abreast

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: allow the summary memory lines to print 2 abreast
Jim Warner [Thu, 5 Aug 2021 05:00:00 +0000 (00:00 -0500)]
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 fca48e7e9947871f280066c01a50ca4812bcc847

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: add a visual separator to lines printed 2 abreast
Jim Warner [Thu, 5 Aug 2021 05:00:00 +0000 (00:00 -0500)]
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>
3 years agotop: new #define added for focus ('F') toggle tweaking
Jim Warner [Wed, 28 Jul 2021 05:00:00 +0000 (00:00 -0500)]
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>
3 years agotop: introduced new focus toggle ('F'), man doc & NEWS
Jim Warner [Wed, 28 Jul 2021 05:00:00 +0000 (00:00 -0500)]
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>
3 years agotop: introduced new focus toggle ('F'), program source
Jim Warner [Wed, 28 Jul 2021 05:00:00 +0000 (00:00 -0500)]
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 ]
[ that prologue for 'forest_display' since all other ]
[ forest functions used punctuation. And, instead of ]
[ a pointer to a proc_t he will now get a ppt index. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: fix a fix for the 'bye_bye' function (merge #127)
Jim Warner [Mon, 21 Jun 2021 05:00:00 +0000 (00:00 -0500)]
top: fix a fix for the 'bye_bye' function (merge #127)

In the merge request shown below, 1 too many bytes are
written to stdout thus including the terminating null.
As the cure, this commit just reduces the length by 1.

[ along the way, we will remove some unneeded braces ]
[ plus add some additional comments with attribution ]

Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/127
. original merged change
commit 0bf15c004db6a3342703a3c420a5692e376c457d

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: refactor 'mkVIZ' support to avoid future problems
Jim Warner [Wed, 16 Jun 2021 05:00:00 +0000 (00:00 -0500)]
top: refactor 'mkVIZ' support to avoid future problems

In the patch referenced below, 2 potential abends were
fixed both of which involved 'alternate display mode'.

The root cause of those abends was a negative value in
the 'begnext' field for other than the current window.

And while that potential is fixed for now the existing
code almost invites such problems again in the future.

So, this patch will remove any temptation to name some
other window in the 'mkVIZrow1' macro. And, since that
macro is not the only source of 'begnext' changes, the
'mkVizrowX' is being added to identify such occasions.

[ and for symmetry i've added a 'mkVIZyes' macro and ]
[ ameliorated an otherwise surreptitious assignment! ]

Reference(s):
commit 84e85611c36d31a478e1b62e5668671d9389265d

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agoMerge branch 'ericonr/procps-error'
Craig Small [Wed, 16 Jun 2021 10:02:18 +0000 (20:02 +1000)]
Merge branch 'ericonr/procps-error'

References:
 procps-ng/procps!137

3 years agoc: print strerror() instead of error code.
Érico Nogueira [Fri, 4 Jun 2021 16:10:28 +0000 (13:10 -0300)]
c: print strerror() instead of error code.

This changes error() behavior to match what glibc already does.

3 years agoMerge branch 'heftig/procps-fix-free-h-si'
Craig Small [Wed, 16 Jun 2021 09:45:31 +0000 (19:45 +1000)]
Merge branch 'heftig/procps-fix-free-h-si'

References:
 procps-ng/procps!140
 procps-ng/procps#133

3 years agofree: Clean up scale_size and fix `free -h --si`
Jan Alexander Steffens (heftig) [Tue, 15 Jun 2021 18:43:36 +0000 (20:43 +0200)]
free: Clean up scale_size and fix `free -h --si`

- Simplify control flow a bit. We don't need two loop variables, either.
- Consistently use %lld for bytes.
- Fix the base handling for human-readable output. The code used to
  calculate *mebibytes* first, then scale that to the required exponent
  with the selected base, which is patently wrong.

Fixes https://gitlab.com/procps-ng/procps/-/issues/133

3 years agotop: fix two potential 'alternate display mode' abends
Jim Warner [Mon, 31 May 2021 05:00:00 +0000 (00:00 -0500)]
top: fix two potential 'alternate display mode' abends

This commit will address potential abends upon leaving
the windows help or color mapping screens and invoking
alternate display mode ('A').  It only happens if that
current window was changed with multiple 'a'/'w' keys.

So now, rather than leaving a trail of negative values
in the 'begtask' field, compliments of that win_select
function, we'll remove the mkVIZrow1 macro. Henceforth
it will be issued just once per user interaction. Thus
a promise of 'Curwin' only being impacted is restored.

[ my thanks to Vladimir Chren for reporting this bug ]

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/210
https://gitlab.com/procps-ng/procps/-/merge_requests/135

Discovered by:Vladimir Chren <vladimir.chren@gmail.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: extend end-of-job report to reflect unused fields
Jim Warner [Tue, 27 Apr 2021 05:00:00 +0000 (00:00 -0500)]
top: extend end-of-job report to reflect unused fields

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agotop: eliminate the #define VER_J_RCFILE as superfluous
Jim Warner [Wed, 31 Mar 2021 05:00:00 +0000 (00:00 -0500)]
top: eliminate the #define VER_J_RCFILE as superfluous

With that commit referenced below, which preserved the
'4' and + '!' toggles in the rcfile, this VER_J_RCFILE
macro was made superfluous. But, it was never removed.

Reference(s):
commit f858e563b7e5013352a8c8316a90c702afd0e1a0

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agosysctl man page update for pattern
Bas van der Vlies [Thu, 25 Feb 2021 08:35:33 +0000 (09:35 +0100)]
sysctl  man page update for pattern

pattern must be used before `--system` else it does not work for sysctl
file(s)

```
root# /sbin/sysctl --system --pattern '^net.ipv6'
* Applying /etc/sysctl.d/30-ceph-osd.conf ...
fs.aio-max-nr = 1048576
kernel.pid_max = 4194304
* Applying /etc/sysctl.d/protect-links.conf ...
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/sara_tweaks.conf ...
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 0
* Applying /etc/sysctl.conf ...
```

vs:
```
root# /sbin/sysctl --pattern '^net.ipv6' --system
* Applying /etc/sysctl.d/30-ceph-osd.conf ...
* Applying /etc/sysctl.d/protect-links.conf ...
* Applying /etc/sysctl.d/sara_tweaks.conf ...
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 0
* Applying /etc/sysctl.conf ...
```

3 years agoconfigure: add macro to check for __PROGNAME
Henrik Grimler [Wed, 26 May 2021 13:45:02 +0000 (15:45 +0200)]
configure: add macro to check for __PROGNAME

in include/c.h we check if HAVE___PROGNAME is defined, but the
corresponding macro for setting (or not setting) it is missing from
the configure script. This commit adds the missing macro, by
copying it from the macro in tmux.

3 years agoCoverity scan findings - memleaks, unused vars, potential nullptr dereferences
Jan Rybar [Thu, 6 May 2021 14:30:54 +0000 (16:30 +0200)]
Coverity scan findings - memleaks, unused vars, potential nullptr dereferences

3 years agoescape.c: Fix missing nl_langinfo on certain configs
Issam E. Maghni [Fri, 23 Apr 2021 20:53:39 +0000 (16:53 -0400)]
escape.c: Fix missing nl_langinfo on certain configs

3 years agoconfigure: Add --disable-w
Issam E. Maghni [Fri, 23 Apr 2021 19:58:36 +0000 (15:58 -0400)]
configure: Add --disable-w

3 years agotop: In the bye_bye function, replace fputs with the write interface.
Shaohua Zhan [Thu, 3 Dec 2020 02:24:09 +0000 (10:24 +0800)]
top: In the bye_bye function, replace fputs with the write interface.

When top calls malloc, if a signal is received, it will
call sig_endpgm to process the signal. In the bye_bye function, if the
-b option is enable, the Batch variable is set, the fputs function
will calls malloc at the same time. The malloc function is not reentrant, so
it will cause the program to crash.

Signed-off-by: Shaohua Zhan <shaohua.zhan@windriver.com>
3 years agopidwait: Rename from pwait
Craig Small [Mon, 15 Feb 2021 10:10:06 +0000 (21:10 +1100)]
pidwait: Rename from pwait

pwait is already in at least Debian in a different package

References:
 https://bugs.debian.org/982391

3 years agoNEWS: tweak wording associated with library versioning v3.3.17
Jim Warner [Mon, 8 Feb 2021 16:10:10 +0000 (10:10 -0600)]
NEWS: tweak wording associated with library versioning

Signed-off-by: Jim Warner <james.warner@comcast.net>
3 years agolibrary: Version has revision incremented
Craig Small [Mon, 8 Feb 2021 10:36:05 +0000 (21:36 +1100)]
library: Version has revision incremented

Library had only its revision incremented to three as there were only
internal changes.

References:
 commit 0d386260b4b007e65172d137924db6e4e4e994cd
 commit eea5626bb144328eb60e9ea8a29bd5b1f100ecd9
 commit 1b9ea61116a625456a89dd7d26b3e4c3d390a599
 commit b0c8e3408b0c0e8e2b41e704083139ab791194a1
 commit e3196502784b11c70d6e3c33159403d2f7c118e1
 commit bb1a79f2c837cad238c2576d2b2705f9cc781c35
 commit b52a26740445904c01233166271817743f2e4b40
 commit 8e0c33be46820c11bb7a911ae0f67fd390864058

Signed-off-by: Craig Small <csmall@dropbear.xyz>
3 years agobuild-sys: Don't require po4a for installation
Craig Small [Mon, 8 Feb 2021 10:23:41 +0000 (21:23 +1100)]
build-sys: Don't require po4a for installation

The build system tested for the presence of po4a binary at the
install step. procps ships with translated man pages so doesn't
need po4a for install/uninstallation.

Works already in psmisc!

References:
 https://gitlab.com/psmisc/psmisc/-/commit/5fab6b7ab385080f1db725d6803136ec1841a15f

Signed-off-by: Craig Small <csmall@dropbear.xyz>
3 years agonls: Fix translation problems
Craig Small [Fri, 29 Jan 2021 23:38:30 +0000 (10:38 +1100)]
nls: Fix translation problems

Some of the translation files did not escape the < properly leading
to po4a aborting.  Also some translators are using old templates
and this merges them to the new ones.

References:
 procps-ng/procps#188

3 years agonls: Update the translation files
Craig Small [Thu, 28 Jan 2021 11:39:49 +0000 (22:39 +1100)]
nls: Update the translation files

Download of the translation files from the translation
project.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
3 years agobuild-sys: Ignore temp directory for POTFILES.in
Craig Small [Thu, 28 Jan 2021 11:35:33 +0000 (22:35 +1100)]
build-sys: Ignore temp directory for POTFILES.in

Sometimes the testing sequence would leave a source tree
under procps-ng-(version) which, if update-potfiles was
run, would include these temporary files in the list, causing issues
later.

The script now explicitly ignores those temporary files.

3 years agomisc: Update NEWS to next version v3.3.17rc1
Craig Small [Fri, 22 Jan 2021 07:21:08 +0000 (18:21 +1100)]
misc: Update NEWS to next version

3 years agonls: Minor update to po files
Craig Small [Fri, 22 Jan 2021 07:19:05 +0000 (18:19 +1100)]
nls: Minor update to po files

3 years agobuild-sys: One more man-po build fix
Craig Small [Thu, 21 Jan 2021 10:58:48 +0000 (21:58 +1100)]
build-sys: One more man-po build fix

3 years agobuild-sys: Update build to install translated manpages
Craig Small [Thu, 21 Jan 2021 10:40:10 +0000 (21:40 +1100)]
build-sys: Update build to install translated manpages

Based on the psmisc build system this now installs the
translated man pages and seems to survive a make distcheck

3 years agobuild-sys: Fix version directory
Craig Small [Thu, 21 Jan 2021 10:01:33 +0000 (21:01 +1100)]
build-sys: Fix version directory

.version needs to be generated into the build directory not the
source directory.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
3 years agodocs: vmstat.8 - swap is not virtual memory
Craig Small [Thu, 21 Jan 2021 06:58:48 +0000 (17:58 +1100)]
docs: vmstat.8 - swap is not virtual memory

Chanson Shen rightly pointed out that vmstat swpd stat is
swap memory used not virtual memory used.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
4 years agotop: tweak cmd/cmdline logic for a possible bad locale
Jim Warner [Fri, 1 Jan 2021 06:00:00 +0000 (00:00 -0600)]
top: tweak cmd/cmdline logic for a possible bad locale

Since this master library isn't quite as sophisticated
as the newlib version, this patch will protect against
the possibility of multibyte characters in a program's
name combined with some locale without UTF-8 encoding.

[ it is better to treat the COMMAND column length as ]
[ more than what's actually printed than to have the ]
[ line overflow & corrupt the remaining screen lines ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agolibrary: let's make 'escaped_copy' multibyte aware too
Jim Warner [Thu, 31 Dec 2020 06:00:00 +0000 (00:00 -0600)]
library: let's make 'escaped_copy' multibyte aware too

This patch is intended to bring the master branch into
closer alignment with the newlib branch functionality.

The commit shown below replaced that 'escape_str' with
'escaped_copy' so that the ps program wouldn't execute
some code twice. However, it created a problem for the
top program when the UTF-8 encoding was not available.

Unlike ps who calls the escape functions directly, top
outputs those library provided strings unaltered. That
means there is no workaround (like LANG=) when such an
encoding was unavailable. This, in turn, can lead to a
corrupted display (especially with the linux console).

Now, when a UTF-8 encoding is not available, multibyte
chars are converted to '?', reducing display problems.

[ there's still a potential problem concerning 'cmd' ]
[ should program names contain multibyte characters. ]
[ unlike that newlib branch, this string is not ever ]
[ altered with the '?' char under the master branch. ]

Reference(s);
. Dec 2020, escaoed_copy repleced most escape_str
commit eea5626bb144328eb60e9ea8a29bd5b1f100ecd9

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agolibrary: help ensure 'escape_str' isn't executed twice
Jim Warner [Sat, 26 Dec 2020 06:00:00 +0000 (00:00 -0600)]
library: help ensure 'escape_str' isn't executed twice

Now that the ps program is using 'escape_str' for most
of the library's returned strings, this patch tries to
lessen the prospects of executing that function twice.

Our newlib branch has achieved such a goal through the
elimination of nearly all escape.c code. However, here
we avoid API change by trading some 'escape_str' calls
(with wide character overhead) for a slightly extended
'escaped_copy' call (which incurs no multibyte costs).

Note: until we migrate to the newlib version, there is
a remaining call to 'escape_str' which we can't avoid.
Such code involves the 'escape_command' function call.

[ As we prepare for this new (final?) release, there ]
[ were already internal library changes that require ]
[ a new 'revision'. This patch won't impact the API! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agotop: added utf8 multibyte support to additional fields
Jim Warner [Thu, 24 Dec 2020 06:00:00 +0000 (00:00 -0600)]
top: added utf8 multibyte support to additional fields

When any process' command line contains multibyte utf8
characters, two separate display problems could arise.

1. If that COMMAND column is not displayed as the very
last field, then field(s) to the right are misaligned.

2. Even when last, should utf8 string length (not that
display length) exceed allowable screen width, it will
nonetheless suffer from improper premature truncation.

Number 1 is less of a concern since the cmdline column
is likely to always be the last field to be displayed,
if only to enable right and left scrolling provisions.

Number 2 is much more likely to occur, especially with
additional fields which might be shown before COMMAND.
Or, forest view child tasks can yield the same effect.

So, this commit will permit the correct utf8 multibyte
display regardless of field position or string length.

And, we'll bring top into line with the ps program for
additional fields potentially subject to utf8 display.

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agops: extend utf8 multibyte support to additional fields
Jim Warner [Thu, 24 Dec 2020 06:00:00 +0000 (00:00 -0600)]
ps: extend utf8 multibyte support to additional fields

Form its inception (back in May of 2011), escaped_copy
has always been a flawed function. It does not operate
on 'escaped' strings but instead treats all input as a
regular string incapable of containing utf8 sequences.

As such, it should only be used for strings guaranteed
to NOT contain multibyte characters (like supgid). For
all other strings, which could contain utf8 stuff, the
correct function should have been that escape_str guy.

So this commit changes nearly every escaped_copy call.

[ note: unlike the newlib guy, the master ps program ]
[ cannot properly handle utf8 multibyte sequences in ]
[ in the recently introduced 'exe' field shown below ]

Reference(s):
. Jun 2018, introduced 'exe' field
commit b556bf5ba82c7e593eb682bbf836c2bc444b2e7d
. May 2011, original escaped_copy (cmdline, cgroup)
commit 7b0fc19e9d28380dc9790615b93bc3653d6d686e

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agotop: correct one spelling oops in a programmer comment
Jim Warner [Tue, 22 Dec 2020 06:00:00 +0000 (00:00 -0600)]
top: correct one spelling oops in a programmer comment

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agomisc: Add NEWS for ps sorting
Craig Small [Tue, 22 Dec 2020 05:26:35 +0000 (16:26 +1100)]
misc: Add NEWS for ps sorting

4 years agoMerge branch 'topimiettinen/procps-ps-sort-label'
Craig Small [Tue, 22 Dec 2020 05:24:47 +0000 (16:24 +1100)]
Merge branch 'topimiettinen/procps-ps-sort-label'

References:
 procps-ng/procps!99

4 years agops: add lots of sorting functions
Topi Miettinen [Wed, 11 Mar 2020 09:23:33 +0000 (11:23 +0200)]
ps: add lots of sorting functions

Use NULL in format_array to indicate that the print function shall be
used also for sorting. Change sr_nop() to NULL for all fields which
don't use pr_nop() for printing.

Before the commit (note that '--sort label' has no effect: the rows
are not sorted according to label field):
$ ps -A -o command,label --sort label | grep /lib/systemd
/lib/systemd/systemd-journa system_u:system_r:syslogd_t:s0
/lib/systemd/systemd-udevd  system_u:system_r:udev_t:s0-s0:c0.c1023
/lib/systemd/systemd-networ system_u:system_r:systemd_networkd_t:s0
/lib/systemd/systemd-resolv system_u:system_r:systemd_resolved_t:s0
/lib/systemd/systemd-timesy system_u:system_r:ntpd_t:s0
/lib/systemd/systemd-logind system_u:system_r:systemd_logind_t:s0
/lib/systemd/systemd --user user_u:user_r:user_t:s0
/lib/systemd/systemd --user root:sysadm_r:sysadm_t:s0-s0:c0.c1023
grep /lib/systemd           user_u:user_r:user_t:s0

After the commit, '--sort label' works and the output is sorted:
$ ps -A -o command,label --sort label | grep /lib/systemd
/lib/systemd/systemd --user root:sysadm_r:sysadm_t:s0-s0:c0.c1023
/lib/systemd/systemd-timesy system_u:system_r:ntpd_t:s0
/lib/systemd/systemd-journa system_u:system_r:syslogd_t:s0
/lib/systemd/systemd-logind system_u:system_r:systemd_logind_t:s0
/lib/systemd/systemd-networ system_u:system_r:systemd_networkd_t:s0
/lib/systemd/systemd-resolv system_u:system_r:systemd_resolved_t:s0
/lib/systemd/systemd-udevd  system_u:system_r:udev_t:s0-s0:c0.c1023
/lib/systemd/systemd --user user_u:user_r:user_t:s0
grep /lib/systemd           user_u:user_r:user_t:s0

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
4 years agopgrep: Remove memory leak
Craig Small [Tue, 22 Dec 2020 05:08:49 +0000 (16:08 +1100)]
pgrep: Remove memory leak

This is part of !118 where @tt.rantala found a memory leak.
The other part of !118 may come later if the performance change
is significant.

References:
 procps-ng/procps!118

4 years agoMerge branch 'axxName/procps-master'
Craig Small [Tue, 22 Dec 2020 04:43:07 +0000 (15:43 +1100)]
Merge branch 'axxName/procps-master'

References:
 procps-ng/procps!63

4 years agoIf you use echo -e $(put sgr0)"text" - reset color attributes, it turns out the artif...
Alexandr Miasnikov [Fri, 27 Apr 2018 13:27:17 +0000 (13:27 +0000)]
If you use echo -e $(put sgr0)"text" - reset color attributes, it turns out the artifact (Btext

4 years agops: Add NEWS and test for exe output
Craig Small [Tue, 22 Dec 2020 04:31:39 +0000 (15:31 +1100)]
ps: Add NEWS and test for exe output

Only need this for master, as Jim took care of exe
handling for newlib in the ad4269 change.

References:
 commit b556bf5ba82c7e593eb682bbf836c2bc444b2e7d
 commit ad4269f1189d5a7d68765e291bcfa981b6731c25

4 years agops: new format option 'exe' now shows executable path if unavail from cmdline
Jan Rybar [Fri, 8 Jun 2018 14:38:14 +0000 (16:38 +0200)]
ps: new format option 'exe' now shows executable path if unavail from cmdline

Red Hat Bugzilla #1399206

4 years agobuild-sys: Make pwait test dependent on pwait built
Craig Small [Tue, 22 Dec 2020 04:20:30 +0000 (15:20 +1100)]
build-sys: Make pwait test dependent on pwait built

As pwait building is conditional, testsuite should
only run pwait tests if there is a pwait binary.

4 years agoMerge branch 'awilfox/procps-utmpx-support'
Craig Small [Tue, 22 Dec 2020 03:59:47 +0000 (14:59 +1100)]
Merge branch 'awilfox/procps-utmpx-support'

References:
 procps-ng/procps!67

4 years agow: Use POSIX <utmpx.h> functions where available
A. Wilcox [Sat, 16 Jun 2018 07:26:53 +0000 (02:26 -0500)]
w: Use POSIX <utmpx.h> functions where available

<utmp.h> has been deprecated since 2001 in favour of <utmpx.h>.

On glibc systems, utmp is just an alias to utmpx, so there is no
functional change using one over the other.

However, on the musl libc, a library (utmps) can be used to provide
utmpx functionality - but not utmp.  This means that procps either
doesn't work properly (`w` shows nothing under musl with default no-op
implementation), or fails to build (utmps provides utmpx.h but no
utmp.h).

This commit will use utmpx.h where available, which allows `w` to work
correctly with utmps and has no change on glibc systems.

4 years agoMerge branch 'teknoraver/procps-master'
Craig Small [Tue, 22 Dec 2020 03:32:26 +0000 (14:32 +1100)]
Merge branch 'teknoraver/procps-master'

References:
 procps-ng/procps!83

4 years agoNEWS: Add notice for pidof -q
Craig Small [Tue, 22 Dec 2020 03:32:03 +0000 (14:32 +1100)]
NEWS: Add notice for pidof -q

4 years agopidof: allow to suppress output
Matteo Croce [Tue, 19 Mar 2019 13:33:01 +0000 (14:33 +0100)]
pidof: allow to suppress output

Often pidof is used in shell scripts in this form:

    if pidof daemon >/dev/null; then
        ...
    fi

The redirection to /dev/null is needed because otherwise the script
would output the found PIDs.
Let's add a -q option which, similary to grep, just sets the exit code.
Also exit on first match, as there is no reason to proceed further when
at least a process is matched.

Tested with:

    $ ./pidof bash
    17701 14019 5276 2967
    $ echo $?
    0
    $ ./pidof bashx
    $ echo $?
    1
    $ ./pidof -q bash
    $ echo $?
    0
    $ ./pidof -q bashx
    $ echo $?
    1

4 years agokill: Fix argument handling for negative PIDs
Raphaël Jakse [Fri, 7 Sep 2018 12:57:03 +0000 (12:57 +0000)]
kill: Fix argument handling for negative PIDs

4 years agoMerge branch 'nipunn1313/procps-watch_colors2'
Craig Small [Tue, 22 Dec 2020 02:54:50 +0000 (13:54 +1100)]
Merge branch 'nipunn1313/procps-watch_colors2'

References:
 procps-ng/procps!109

4 years agoSupporting bright colors with ncurses
Nipunn Koorapati [Mon, 13 Jul 2020 02:08:26 +0000 (02:08 +0000)]
Supporting bright colors with ncurses

4 years agoSupport simple 8 bit ansi escape sequences
Nipunn Koorapati [Thu, 2 Jul 2020 06:05:24 +0000 (06:05 +0000)]
Support simple 8 bit ansi escape sequences

See https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
Support standard and high intensity colors. The default
ncurses colors ARE the high intensity colors - represented
via an 8 bit ansi escape sequence here.

4 years agoMerge branch 'nipunn1313/procps-watch_colors'
Craig Small [Tue, 22 Dec 2020 02:48:15 +0000 (13:48 +1100)]
Merge branch 'nipunn1313/procps-watch_colors'

References:
 procps-ng/procps!106

4 years agoSpaces to tabs
Nipunn Koorapati [Mon, 13 Jul 2020 03:20:23 +0000 (03:20 +0000)]
Spaces to tabs

4 years agoAdd comments and limit to standard colors
Nipunn Koorapati [Mon, 13 Jul 2020 00:59:29 +0000 (00:59 +0000)]
Add comments and limit to standard colors

4 years agobugfix - increment endpointer when parsing color_escape_sequence
Nipunn Koorapati [Thu, 2 Jul 2020 07:45:29 +0000 (07:45 +0000)]
bugfix - increment endpointer when parsing color_escape_sequence

4 years agoSupport simple 8 bit ansi escape sequences
Nipunn Koorapati [Thu, 2 Jul 2020 06:05:24 +0000 (06:05 +0000)]
Support simple 8 bit ansi escape sequences

See https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
Support standard and high intensity colors. The default
ncurses colors ARE the high intensity colors - represented
via an 8 bit ansi escape sequence here.

4 years agoMerge branch 'antonblanchard/procps-proc-stat-buffer'
Craig Small [Tue, 22 Dec 2020 02:18:58 +0000 (13:18 +1100)]
Merge branch 'antonblanchard/procps-proc-stat-buffer'

References:
 procps-ng/procps!105

4 years agoIncrease BUFFSIZE to handle very large /proc/stat files
Anton Blanchard [Thu, 25 Jun 2020 23:06:12 +0000 (09:06 +1000)]
Increase BUFFSIZE to handle very large /proc/stat files

We read /proc/stat using a statically sized buffer. This was increased
to 64kB in 2005 via commit 777fcd3cf15d "/proc/stat for 1024 CPUs".

Unfortunately in 2020, 1024 CPUs is not enough for anyone. I have a
large machine where /proc/stat is 74kB, and vmstat gives incorrect
output.

Double the buffer to 128kB in the confidence that 2048 CPUs is actually
enough for anyone.

Signed-off-by: Anton Blanchard <anton@ozlabs.org>
4 years agotestsuite: Add pwait tests
Craig Small [Tue, 22 Dec 2020 01:25:44 +0000 (12:25 +1100)]
testsuite: Add pwait tests

They're pretty simple tests but its something.

References:
  commit 09327c2b772fd7bc2762c557855e6a78b6352eb5

4 years agoMerge branch 'alxu/procps-pwait'
Craig Small [Tue, 22 Dec 2020 01:16:09 +0000 (12:16 +1100)]
Merge branch 'alxu/procps-pwait'

New command, pwait! Waits for another process to finish just like
pgrep finds or pkill kills another process.

References:
 procps-ng/procps!97

Signed-off-by: Craig Small <csmall@dropbear.xyz>
4 years agopgrep: add pwait
Alex Xu (Hello71) [Mon, 24 Feb 2020 03:02:59 +0000 (22:02 -0500)]
pgrep: add pwait

4 years agoMerge branch 'nipunn1313/procps-spaces_to_tabs'
Craig Small [Tue, 22 Dec 2020 00:55:10 +0000 (11:55 +1100)]
Merge branch 'nipunn1313/procps-spaces_to_tabs'

References:
 procps-ng/procps!108

4 years agoConvert spaces to tabs in watch.c
Nipunn Koorapati [Mon, 13 Jul 2020 03:24:53 +0000 (03:24 +0000)]
Convert spaces to tabs in watch.c

4 years agoMerge branch 'nipunn1313/procps-configure_ncurses'
Craig Small [Tue, 22 Dec 2020 00:45:47 +0000 (11:45 +1100)]
Merge branch 'nipunn1313/procps-configure_ncurses'

Macs have the wide stuff in the ncurses (not ncursesw) library.

References:
 procps-ng/procps!110
 procps-ng/procps#47

4 years agowatch: Support wide char ncurses on mac with enable-watch8bit
Nipunn Koorapati [Mon, 13 Jul 2020 05:08:24 +0000 (22:08 -0700)]
watch: Support wide char ncurses on mac with enable-watch8bit

Fixes #47

4 years agomisc: fix typos in manual pages
Samanta Navarro [Sat, 3 Oct 2020 11:26:22 +0000 (11:26 +0000)]
misc: fix typos in manual pages

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agopkill manpage to document '-e' option
Jan Rybar [Fri, 6 Nov 2020 14:45:56 +0000 (14:45 +0000)]
pkill manpage to document '-e' option

4 years agopidof: new option to show cmdline-less PIDs (kernel workers), empty input fixed
Jan Rybar [Tue, 22 Dec 2020 00:14:41 +0000 (00:14 +0000)]
pidof: new option to show cmdline-less PIDs (kernel workers), empty input fixed

4 years agoMerge branch 'brenns10/procps-master'
Craig Small [Tue, 22 Dec 2020 00:08:52 +0000 (11:08 +1100)]
Merge branch 'brenns10/procps-master'

References:
 procps-ng/procps!119

4 years agoSet TZ to avoid repeated stat("/etc/localtime")
Stephen Brennan [Fri, 20 Nov 2020 00:03:58 +0000 (16:03 -0800)]
Set TZ to avoid repeated stat("/etc/localtime")

With glibc, each time the strftime() function is used (twice per process
in a typical ps -fe run), a stat("/etc/localtime") system call is used
to determine the timezone. Not only does this add extra system call
overhead, but when multiple ps processes are trying to access this
file (or multiple glibc programs using strftime) in parallel, this can
trigger significant lock contention within the OS kernel.

Since ps is not intended to run for long periods of time as a
daemon (during which the system timezone could be altered and PS might
reasonably be expected to adapt its output), there is no benefit to
repeatedly doing this stat(). To stop this behavior, explicitly set the
TZ variable to its default value (:/etc/localtime) whenever it is unset.
glibc will then cache the stat() result.

4 years agoMerge branch 'ratijas/procps-man-watch'
Craig Small [Tue, 22 Dec 2020 00:03:57 +0000 (11:03 +1100)]
Merge branch 'ratijas/procps-man-watch'

References:
 procps-ng/procps!121

4 years agodocs: Consistent style across watch.1
ivan tkachenko [Sun, 6 Dec 2020 11:17:23 +0000 (14:17 +0300)]
docs: Consistent style across watch.1

4 years agomisc: Document sysctl change bug
Craig Small [Mon, 21 Dec 2020 23:55:18 +0000 (10:55 +1100)]
misc: Document sysctl change bug

While sysctl did change the order of /run and /etc to match
systemd in the referenced commit, the Debian bug report that
brought it to light was not documented.

References:
 commit 24a1574f0acbe636c98ab13b439c93f7b91de697
 https://bugs.debian.org/950788

4 years agotop: a small safeguard added to the ATEOJ_RPTHSH logic
Jim Warner [Mon, 19 Oct 2020 05:00:00 +0000 (00:00 -0500)]
top: a small safeguard added to the ATEOJ_RPTHSH logic

If a hash results report was output (via ATEOJ_RPTHSH)
a portion is devoted to occupied table entries ordered
by depth. There is a possibility that some depths will
not be found among existing occupied table entries and
to avoid any confusion probably should not be printed.

[ to illustrate the potential for confusion prior to ]
[ this patch, force a very small table size (like 8) ]
[ and then arrange to trigger the end-of-job report. ]

So this patch ensures only 'in use' entries are shown.

[ admittedly, all of the remaining logic in the loop ]
[ could/should be subordinate to this new 'if' test, ]
[ but we will keep the change to a minimum. besides, ]
[ there's no harm subtracting/adding a zero numdepth ]
[ especially since the chance of a zero is very low. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agofree,slabtop,uptime: complain about extra ops
Craig Small [Mon, 19 Oct 2020 11:36:06 +0000 (22:36 +1100)]
free,slabtop,uptime: complain about extra ops

free, slabtop and uptime would happily take extra command line
arguments and doing nothing about them. The programs now check
optind after option processing and will give you usage screen
if there is anything extra.

References:
 procps-ng/procps#181

4 years agowatch: Add no linewrap option
Craig Small [Mon, 19 Oct 2020 11:03:44 +0000 (22:03 +1100)]
watch: Add no linewrap option

For long lines from a process, watch would wrap them around to the
next. While this default option has it uses, sometimes you want to
just cut those long lines down.

watch has a -w flag which will truncate the lines to the number
of columns. A few simple lines to do this new trick.

I think I caught all the ANSI state correctly but there might be
a chance it bleeds to the next row.

References:
 procps-ng/procps#182

4 years agotop: just a small tweak to that history hash algorithm
Jim Warner [Thu, 1 Oct 2020 05:00:00 +0000 (00:00 -0500)]
top: just a small tweak to that history hash algorithm

This patch just raises the size of the hash table used
to calculate elapsed task stuff. The net result should
be less need for 'chaining' under pid hash collisions.

[ the hash scheme is intentionally kept as primitive ]
[ and, therefore, as fast as possible. it employs an ]
[ 'and' approach versus a 'mod' operation since both ]
[ yield similar distribution but the former approach ]
[ was 4 fewer cpu instructions in terms of overhead. ]

[ additionally, for hash collisions, 'chaining' uses ]
[ an array index rather than the usual pointer since ]
[ the HST_t guys may move when they are reallocated. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agops: Match on truncated 16 char for -C
Craig Small [Thu, 24 Sep 2020 12:01:22 +0000 (22:01 +1000)]
ps: Match on truncated 16 char for -C

The referenced commit the comm length was increased from 16 to 64
characters to handle the larger command names for things like kernel
threads.

However most user processes are limited to 15 characters which means
if you try something like ps -C myprogramisbiggerthansixteen this would
fail to match because /proc/<PID>/comm would only be myprogramisbigg

ps now checks the comm length and if it is 15 and if the given match
is 15 or more, it will only match the first 15 characters.

This is also how killall has worked for about a year.

Thanks to Jean Delvare <jdelvare@suse.de> for the note.

References:
 commit 14005a371e5c14289e96a4927ffd1a827d3c9d85
 commit psmisc/psmisc@1188315cd037d73bf946a0003b70c6423cc330d2

Signed-off-by: Craig Small <csmall@dropbear.xyz>
4 years agotop: fix additional SEGVs if no tasks were displayable
Jim Warner [Sun, 13 Sep 2020 05:00:00 +0000 (00:00 -0500)]
top: fix additional SEGVs if no tasks were displayable

This patch is an outgrowth of that commit shown below.

Many additional potential segmentation faults might be
encountered if interactive commands are opened up to a
user when a '-p' switch has a single non-existent pid.

[ always the 'k', 'L', 'r', 'Y' keys & maybe 'v' too ]

So, this patch will restrict such a loser (oops, user)
to a reduced subset of normal commands until he/she/it
quits then restarts top with something to be displayed
or issues the '=' command overriding that '-p' switch.

Reference(s):
commit f57a0301e3adfa5fd456404a200182c7f21da03a

Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agotop: fix potential SEGV when no tasks were displayable
Jim Warner [Wed, 9 Sep 2020 05:00:00 +0000 (00:00 -0500)]
top: fix potential SEGV when no tasks were displayable

This patch fixes a nearly decade old bug discovered by
Frederik Deweerdt. His merge request shown below would
be an adequate solution except for iterative overhead.

This alternate patch will represent substantially less
overhead for an admittedly extremely rare possibility.

Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/114

And-thanks-to: Frederik Deweerdt <fdeweerdt@fastly.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
4 years agotop: update user/system cpu % graph content (man page)
Jim Warner [Tue, 8 Sep 2020 05:00:00 +0000 (00:00 -0500)]
top: update user/system cpu % graph content (man page)

What had been stated as the contents of the cpu graphs
was never really inclusive enough. Those recent newlib
tweaks highlighted the need for these man doc changes.

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