Commit Graph

3831 Commits

Author SHA1 Message Date
Craig Small
ea6dcd529c testsuite: skip pmap -X for missing/readable smaps
Some test systems fail on pmap -X 1 which should exist
and not be readable. Skip the test if either of these
is not true

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 17:19:24 +11:00
Craig Small
1c61ac2c61 w: Cache pids and other enhancements
Load and cache the pids list once like previous version of w as
re-scanning each user is time consuming.

Make sure utmpx structure is sent when not using systemd, stops
a segfault due to empty host value

Re-worked main loops as we either had branches (systemd) or two loops
(other) when just checking for username was all that was needed.

References:
 #305

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 16:35:21 +11:00
Robert Malz
bfb0eadc38 uptime: fix output on 60 seconds
When procps_uptime will return 60 seconds uptime -p will not
provide any output except "up". To stay consistent with other
time units the expected output is "up 0 minutes".

References:
 #302

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-09-21 16:45:49 +10:00
Craig Small
91ff8d9959 library: days/users when value is 0
The check for using days/users was > 0 which meant you could
get results like 0 day or 0 user. The check is now for not 1
so w prints 0 days and 0 users.

References:
 #303
2023-09-21 16:32:34 +10:00
Jim Warner
09fbd70de3 ps: don't lose tasks when --sort used with forest mode
In an issue cited below the loss of tasks was revealed
whenever the --sort option is used in combination with
forest mode. One could argue against such combinations
and print an error. But we'll take an easier approach.

This patch restores the prior version 3.3.17 behavior.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-09-21 16:21:06 +10:00
Craig Small
dd9640faa7 testsuite: Make the pmap -X a looser regex 2023-09-17 17:57:03 +10:00
Craig Small
dd81f49394 tests: Tell which match failed for pmap -X
There are two matches made for pmap -X/-XX
The test script will tell you which one failed.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-09-17 17:53:11 +10:00
Craig Small
79042e07fa ps: Don't crash when using short option
ps would crash with the -si or -sf options with systemd enabled.
The issue was the utmp wasn't filled in, the long option checked, the
short option did not.

Refactored the showinfo() function so instead of a branch with duplicate
prints for the items in both long and short we just branch on the items
for long output.

Also, made the function prototypes not dependendent on systemd enabled,
it was too messy that way and passing a char* NULL is not really going
to hurt anything.

References:
 #301

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-09-12 16:59:18 +10:00
Craig Small
e1dfeeb11c ps: Don't use PATH_MAX
PATH_MAX is used to define the length of a signal name. This constant is
not even guaranteed to be on certain systems or consistent. It's not
even been used for a path, but a signal name.

For paths, its not considered the Right Way anyhow.

References:
 https://www.gnu.org/software/hurd/community/gsoc/project_ideas/maxpath.html
 https://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html
 https://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-09-07 20:57:42 +10:00
Craig Small
bc37d699d0 library: Hurd uses /proc/version too
procps_linux_version() would fail on Hurd systems as there is
/proc/sys directory. This uses the same work-around that Cygwin uses.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-09-07 20:46:54 +10:00
Craig Small
e2eb467d29 docs: Remove incorrect AIX output example in ps.1
The example used the -e option incorrectly and the format is
not quite to standard

References:
 https://bugs.debian.org/925438
2023-08-31 22:56:48 +10:00
Craig Small
ca004d4657 build-sys: Add systemd/elogind to w
Depending on the compiler flags, w needs to be explictly linked
to libsystemd or elogind even though libproc2 is linked to it.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-31 22:24:23 +10:00
Craig Small
4ddcef2fd8 NEWS: This is Version 4.0.4
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-31 19:54:51 +10:00
Craig Small
a6ef923775 nls: Update translation files
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-31 19:47:01 +10:00
Craig Small
469b964621 library: Increment revision
There have been some internal updates, library is now 0:2:0

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-19 17:47:08 +10:00
Craig Small
a3ee82776e nls: Update translation files 2023-08-19 17:39:42 +10:00
Craig Small
bce60dbc4b docs: Updatye -w option for sysctl.8
The -w option didn't really explain what it was doing.

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

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-19 17:34:35 +10:00
Craig Small
0632609efd misc: Add NEWS for escape fix
References:
 49f92f690c
 https://bugs.debian.org/1035649
2023-08-19 17:26:04 +10:00
Craig Small
6fd4956c0e docs: Remove ps -aux note from ps.1
Removed note of difference between ps aux and ps -aux. I and most other
people get the same output.

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

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-19 17:15:54 +10:00
Craig Small
6e9485065d docs: Clean up of ps.1
Added suggestions from Debian bug #894480
Added comment about --signames on signal mask fields

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

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-19 17:09:52 +10:00
Bjarni Ingi Gislason
45587db966 docs: Minor fixes to skill.1
References:
 https://bugs.debian.org/893457

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-19 16:17:46 +10:00
Roman Žilka
f5f843e257 ps/parser: parse_list(): int overflow for large arg, free() of uninit. ptr
* ps/parser.c:parse_list(): Regression (2c933ecb): node->u is uninitialized at
  free(node->u) when reached before node->u=xcalloc().
* ps/parser.c:parse_list(): When "arg" is very long, CVE-2023-4016 is triggered.
  2c933ecb handles the multiplication issue, but there is still the possibility
  of int overflow when incrementing "items".
2023-08-19 15:46:55 +10:00
Jim Warner
571733c387 misc: eliminate all of the useless trailing whitespace
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-08-19 15:26:40 +10:00
Craig Small
c10ba96147 ps: Add --signames to print signal names
Fields such as pending, blocked, ignored and caught would only show
an incomprehensible hexadecimal field for signals, with the
--signames option it now shows the short name.

Largely based on the work of @mcgrof

References:
 !98
 https://gitlab.com/mcgrof/sigstat

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-16 17:00:31 +10:00
Craig Small
675246119d build-sys: add missing configure.ac for previous
The previous commit has a missing update for configure.ac
2023-08-15 21:29:25 +10:00
Craig Small
11c91313c9 watch: Add compile time flag to support color
configure --enable-colorwatch will make watch run as if
the --color option is always on. Add the -C,--no-color
option to remove color.

References:
 #296

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-15 21:26:13 +10:00
Craig Small
0f4de1c438 misc: Add NEWS for pidof -t
Added NEWS item for previous commit to add -t option to pidof

References:
 dd9310da0b19c06382ee205f77ed211dd8ba8ccf
 !190
2023-08-15 21:04:06 +10:00
Masatake YAMATO
dd9310da0b pidof: add -t/--lightweight option for printing threads
The option does the same as -w/--lightweight option of pgrep.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-08-15 11:01:57 +00:00
Masatake YAMATO
f2d497d03a pidof: (cosmetic) use tab characters for indentation
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
2023-08-15 11:01:57 +00:00
Craig Small
a7a03ba4e4 pmap: Reset totals between procs with -X or -XX
When pmap used with -X or -XX option with multiple pids, the
totals were not reset between the pids, meaning the first total
was for pid1, but second total was for pid1+pid2.

These running totals are now reset when they are printed, meaning
each total is for it's own pid only.

References:
 issue #298

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-15 20:52:14 +10:00
Chris Green
7aa4e5c235 Utilize LTLIBINTL for universal libintl handling 2023-08-15 09:51:39 +00:00
Jiachen Zhang
13a6df9f57 sysctl: improve the clearness of warning messages when writing keys
Set the proper errno if we don't have the write permission of the key or
the path is a directory. Otherwise the warning message might be misleading.

Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
2023-08-15 09:49:17 +00:00
Grzegorz Szpetkowski
51e8bfa6f4 ps: man: short process filters aligned with source implementation
According to parse_trailing_pids, short ps filters: 123, -123, +123
stand for PID, PGID and SID, respectively.

Signed-off-by: Grzegorz Szpetkowski <gszpetkowski@gmail.com>
2023-08-15 09:44:43 +00:00
Chao Liu
0edb44333b Fix errors when compile with musl
__UT_NAMESIZE is undeclared in musl, which cause:

ocps/4.0.2-r0/recipe-sysroot-native= -c -o src/w.o ../procps-ng-4.0.2/src/w.c
| ../procps-ng-4.0.2/src/w.c: In function 'print_from':
| ../procps-ng-4.0.2/src/w.c:70:22: error: '__UT_HOSTSIZE' undeclared (first use in this function); did you mean 'UT_HOSTSIZE'?
| 70 | # define UT_HOSTSIZE __UT_HOSTSIZE
| | ^~~~~~~~~~~~~
| ../procps-ng-4.0.2/src/w.c:230:43: note: in expansion of macro 'UT_HOSTSIZE'
| 230 | print_display_or_interface(u->ut_host, UT_HOSTSIZE, fromlen - len);
| | ^~~~~~~~~~~
| ../procps-ng-4.0.2/src/w.c:70:22: note: each undeclared identifier is reported only once for each function it appears in
| 70 | # define UT_HOSTSIZE __UT_HOSTSIZE
| | ^~~~~~~~~~~~~
| ../procps-ng-4.0.2/src/w.c:230:43: note: in expansion of macro 'UT_HOSTSIZE'
| 230 | print_display_or_interface(u->ut_host, UT_HOSTSIZE, fromlen - len);
| | ^~~~~~~~~~~
| ../procps-ng-4.0.2/src/w.c: In function 'find_best_proc':
| ../procps-ng-4.0.2/src/w.c:72:22: error: '__UT_NAMESIZE' undeclared (first use in this function); did you mean 'UT_NAMESIZE'?
| 72 | # define UT_NAMESIZE __UT_NAMESIZE
| | ^~~~~~~~~~~~~
| ../procps-ng-4.0.2/src/w.c:391:18: note: in expansion of macro 'UT_NAMESIZE'
| 391 | char buf[UT_NAMESIZE + 1];
| | ^~~~~~~~~~~
| ../procps-ng-4.0.2/src/w.c: In function 'showinfo':
| ../procps-ng-4.0.2/src/w.c:72:22: error: '__UT_NAMESIZE' undeclared (first use in this function); did you mean 'UT_NAMESIZE'?
| 72 | # define UT_NAMESIZE __UT_NAMESIZE
2023-08-15 09:39:46 +00:00
Thorsten Kukuk
b4115b4aab w: Prefer logind over utmp
The utmp format of glibc is not Y2038 safe, not even on 64bit systems.
Query logind/elogind for all required informations instead.

Signed-off-by: Thorsten Kukuk <kukuk@suse.com>
2023-08-15 09:56:10 +02:00
Craig Small
2c933ecba3 ps: Fix possible buffer overflow in -C option
ps allocates memory using malloc(length of arg * len of struct).
In certain strange circumstances, the arg length could be very large
and the multiplecation will overflow, allocating a small amount of
memory.

Subsequent strncpy() will then write into unallocated memory.
The fix is to use calloc. It's slower but this is a one-time
allocation. Other malloc(x * y) calls have also been replaced
by calloc(x, y)

References:
 https://www.freelists.org/post/procps/ps-buffer-overflow-CVE-20234016
 https://nvd.nist.gov/vuln/detail/CVE-2023-4016
 https://gitlab.com/procps-ng/procps/-/issues/297
 https://bugs.debian.org/1042887

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-08-10 21:22:23 +10:00
Vishal Chourasia
dd95215280 top: modifying the behavior of the '!' toggle function
Previously, each press of `!' led to the combining of an additional
CPU. However, we have now updated this feature to double the number of combined
CPUs with each press.

The updated example now reflects this change: with the first press of !', two
CPUs are combined and displayed as 0-1, 2-3, ...', instead of the previous
format. Additional presses of `!' continue to double the number of combined
CPUs.

[ jw note: the commit message 1st line was amended to ]
[ add the top program name and remove capitalization. ]
[ the patch itself was adjusted to avoid a fatal po4a ]
[ man document error encountered during clean builds. ]

Signed-off-by: Vishal Chourasia <vishalc@linux.ibm.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-08-10 21:14:27 +10:00
Jim Warner
5ec0a511ce top: correct the spelling errors detected by codespell
Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-08-02 21:39:56 +10:00
Craig Small
7a46278fce misc: Add NEWS for last two commits
References:
 merges #197 #198

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-07-30 21:37:19 +10:00
Florian Schmaus
bbc86cbb3c testsuite: check if /proc/self/smaps exists
On Linux systems wehre CONFIG_PROC_PAGE_MONITOR is not enabled,
/proc/self/smaps does not exist causing the test suite to fail.

Instead, check for /proc/self/smaps and skip the tests if the file
does not exist.

Based on a patch from tobbs@opentrash.com posted to
procps@freelists.org (https://www.freelists.org/post/procps/Patch-Test-suite-fails-if-procpidsmaps-is-absent,1)
and applied by Gentoo (https://bugs.gentoo.org/583036).

Signed-off-by: Florian Schmaus <flo@geekplace.eu>
2023-07-30 11:27:32 +00:00
Jan Rybar
47bf92659d sysctl: -N shows values instead of names 2023-07-30 11:25:16 +00:00
Jim Warner
49f92f690c library: refactor the escape_str utf-8 validation code
The last time library 'escape' logic was refactored in
the patch referenced below potential problems remained
which have now surfaced. They involve those C1 control
characters especially device control strings (DCS/ST).

Such strings, if not handled by the terminal emulator,
could lead to abnormal behaviors or even some exploit.

So, this commit will now escape the multi-byte control
characters (U+0080 thru U+009f). All single byte ascii
control characters were already treated in this manner.

[ in addition, continuation bytes in utf-8 encodings ]
[ requiring two bytes or more will also be validated ]

And unlike the current code, which will escape all the
remaining non-ascii bytes when some error is detected,
this patch honors remaining valid ascii & utf-8 bytes.

Reference(s):
. Dec, 2020 - 'escape' logic' was refactored *again)
commit 649e45482f

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-07-30 21:08:20 +10:00
Jim Warner
77bd62863a top: added summary area memory sources to man document
This patch was prompted by the issue referenced below.

It also places the top man page on a par with the free
man page which does a good job of documenting sources.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-07-17 18:09:51 +10:00
Shen-Ta Hsieh
978f49eb4c Makefile.am: Add ncurses cflags to top and slabtop
If the ncurses library is installed in an unusual spot the compilier
won't find them without these flags:

gcc -std=gnu99 -DHAVE_CONFIG_H -I.  -include ./config.h -I. -I./include -Wno-unused-result -DLOCALEDIR=\"$PREFIX/share/locale\"  -Iproc -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2,-D_GLIBCXX_ASSERTIONS -Wformat -Werror=format-security -Wno-psabi -fstack-clash-protection -MT slabtop.o -MD -MP -MF $depbase.Tpo -c -o slabtop.o slabtop.c &&\
mv -f $depbase.Tpo $depbase.Po
slabtop.c:31:10: fatal error: ncurses.h: No such file or directory

Signed-off-by: Craig Small <csmall@dropbear.xyz>

References:
 !134
2023-07-17 17:34:12 +10:00
Craig Small
9fc76f7feb misc: Add NEWS for previous
References:
 commit 2eafd0a215
 !193

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-07-13 20:27:48 +10:00
EulerOSWander
2eafd0a215 vmstat: remove this process form the number of processe
When 'r' in vmstat displays the number of processed,
delete the vmstat process, which is the same ad the
version before refactoring.

Signed-off-by: zhoujie <zhoujie133@huawei.com>
2023-07-13 10:25:10 +00:00
Roman Žilka
f4fd9d0b3a Resolved all warnings with -O2 -Wall (gcc 12.3, Linux, x86_64) 2023-07-13 09:45:48 +02:00
Craig Small
f4eeff0b26 vmstat: Print guest time
Guest time was removed from User time but not printed. This meant
that if guest time was non-zero then the CPU numbers did not add
up to 100%

References:
 !191
 !113
 commit 2461bb5bc1

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-07-11 19:16:15 +10:00
Roman Žilka
d313765571 pgrep: Minor memleak on multiple F cmdline options 2023-06-22 09:25:12 +02:00
EulerOSWander
b51ef773ad pmap: Increase memory allocation failure judgment
Call trace:
  #0 __vsnprintf_internal
  #1 0x00007f967aedd656 in __GI___snprintf
  #2 0x00005612da28c707 in snprintf
  #3 config_read (rc_filename=<optimized out>) at pmap.c:885
  #4 0x00005612da28b8c0 int main at pmap.c:1144

The above stack is caused by calling a null pointer
after the memory allocation fails. Increase the null
pointer judgment.

signed-off-by: zhoujie <zhoujie133@huawei.com>
2023-06-13 06:34:07 +00:00