Commit Graph

3862 Commits

Author SHA1 Message Date
Roman Žilka
3813326f2f watch: Implemented displaying of cmd running time in header
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:53:07 +11:00
Roman Žilka
ac89d63c5a signals: Updated signal list and defines, introduced RTMAX, fixed strtosig()
* Removed the intro comment: it's >20 years old, some things clearly no longer
  hold (UNUSED, the bug in glibc, Linux ports, ...). Replaced it with some
  boilerplate intro.
* Updated manual defines of missing macros (explained in comments). Removed the
  EMT/STKFLT situation (ancient).
* All functions now account for SIGRTMAX.
* Placed all known non-RT signals into sigtable[]. There's no need anymore to
  try hard to only keep uniquely-numbered signals in it and to make them a
  complete sequence. Most kinds of updates to the signals can be accomplished
  just by editing the table. All functions accomodate, there's no longer a need
  for them to maintain exceptions (most of them).
* No function returns a freeable pointer.
* strtosig(): Re-write (old one didn't handle synonyms, interpreted malloc()
  failure as signal not found).
* On the auxiliary, implemented a stable sort. The stability of qsort() is
  unspecified.

References:
 !207
2023-10-06 16:45:43 +11:00
Roman Žilka
77aecd3e9f watch: Removed TODO that'd been impl., listed name in credits
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:35:12 +11:00
Roman Žilka
21adce9fc4 watch: Corrected header on first_screen, build error when !8BIT (branch regr.)
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:34:48 +11:00
Roman Žilka
4760f3d6b3 watch: Calculate cur usec timestamp in a large enough type (branch regression)
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:34:38 +11:00
Roman Žilka
0a5b342927 watch: Orderly recovery from cmd taking longer than -n [BUG]; code cleanup
* When cmd took longer than -n to complete, -p is no longer skipping sleeps to
  make up for the time lost waiting for the completion(s) [BUG].
* Code cleanup, minor optimization. Moved universal routines to
  strutils/fileutils.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:34:11 +11:00
Roman Žilka
771f8dc559 watch: -d considers full width of new character
* -d considers all columns the new char will occupy, not just the first one.
  When 日a -> a日a, 日 is now highlighted (because of the change in its 2nd
  column).

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:33:52 +11:00
Roman Žilka
4e3d520f09 watch: Fixed -d ignoring combining characters [BUG]
* Worked around a ncurses bug of applying combining characters to the base
  character preceding the target one. -d now operates on all components of
  complex characters. Removes a BUG.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:33:25 +11:00
Roman Žilka
1b8626ec54 watch: Consume outstanding input before allowing termination due to -e
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:32:20 +11:00
Roman Žilka
54c531de6a watch: Header printing locale-aware, optimized and bug-fixed; corr. BUGS and EXIT STATUS in man
* Manpage:
  * Reduced EXIT STATUS to 0 and other. The others were uninteresting in a
    manpage and passing cmd exitcode doesn't work.
  * Removed BUG about combining characters in last column. AFAICS it's gone.
  * Removed BUG about -p not killing cmd when it takes too long. That can be a
    new feature, but the current behavior is what a lot of people might well
    expect by default.
  * Re-phrased the BUG with "rapid-fire" in it. Makes it look like a fork bomb.
* Impl. mbswidth(), the strlen()/wcswidth() for multi-byte strings.
* In header printing:
  * Fixed a few bugs in positioning and truncation (it's ctime()).
  * For 8BIT, column widths are considered instead of mbstring lengths (not just
    for the cmd).
  * ENOMEM handled after asprintf().
  * ctime() -> strftime() for a localized string. Left out date. Ok?
  * Most of header is pre-composed for speed.
* -qN, N < 1, becomes -q1.
* When screen resizes, -q now only pauses for a turn, doesn't restart. This is
  probably as much as can be done without a modification to the change-detecting
  routine.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:31:14 +11:00
Roman Žilka
552308031d watch: Removed use of hijacked streams after fork(), ensured fds/processes do not leak
* Manpage:
  * Rewrote the description of -p. It wasn't saying what -p did.
  * Added COLUMNS and LINES to ENVIRONMENT.
  * Refreshed EXAMPLES, moved it up to be before BUGS.
* Regression in topic branch: tabs now print properly.
* Removed output into the hijacked stdout/err following fork().
* EINTR-protected watpid()s and the release of fds to prevent leaks.
* Removed the measure taken in Debian#240989 to circumvent faulty is(w)print().
  Glibc has been fixed (verified) and as it was, watch was letting all non-ASCII
  non-printables into output. I'm not terribly certain about this one, but I
  figure people with old glibc also have old procps.
* Ensured reading cmd output is buffered. We do a lot of getc() from it.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:30:38 +11:00
Roman Žilka
607a0625a4 watch: Multiple bugs fixed (mostly about -g/-q/-d/-c), run_command() simplified greatly
* Moved character printing out of run_command() and into a new function to clean
  run_command() up and isolate self-contained functionality.
* Main loops in run_command() simplified greatly.
* Bugs fixed:
  * -g and -q now coexist well (both apply). Formerly, "watch -g -q X" with cmd
    output changing would act as "watch -q X" with cmd output not changing.
  * -d highlight no longer removes color.
  * -c together with -d no longer mark the entire screen as ever-changing.
  * malloc() of "wcommand" in main() corrrected (sizeof(item_ptr) ->
    sizeof(*item_ptr)). Also present in a commit in another merge request, but
    I could no longer keep scrolling over it.
  * -q counter now restarts when terminal size changes. That puts it in sync
    with the lifecycle of first_screen and prevents the counter from progressing
    extra fast due to the frequent restarts of the command during the resizing.
* Regression within topic branch: -g is no longer ignored.
* Larger blank areas are now drawn using dedicated ncurses routines, resulting,
  I presume, in faster & cheaper operation. Not confirmed.
* Manpage:
  * Changed the -x option description. The old one made it seem like it's the
    same thing, only better and everyone wants it, disregarding the fact that
    it behaves differently and that this difference is probably more important
    than the convenience regarding quoting.
  * fgrep is obsolete, in GNU grep at least.
  * Made the BUG "Non-printing characters..." into a NOTE. Some common
    non-printables are actually accounted for and the others would probably ruin
    the day of half the people.
  * Reduced the BUG "Upon terminal resize..." The screen does get repainted when
    its dimensions change. The -r is intended to prevent the screen from
    repainting.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:29:04 +11:00
Roman Žilka
22e729be9f watch: Avoid re-computing strlen(command) when displaying header
* Avoid re-computing strlen(command) every time header is printed.
* Regression within topic branch: diff once again accounts for blank space.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:27:17 +11:00
Roman Žilka
e4315b9ab8 watch: Blank lines after very long lines now display properly (one of BUGS)
* Fixed bug from watch(1): "Blank lines directly after a line which ends in the
  last column do not display."
* Cursor is now hidden.
* Bug from watch(1) involving missing compound characters may have been fixed as
  well. I can see no issues with canonically decomposed characters in UTF-8, if
  that's what it's regarding. The BUGS stays, however, until this is confirmed.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:25:56 +11:00
Roman Žilka
49932b9dc3 watch: Code cleanup, minor optim.
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:24:22 +11:00
Roman Žilka
eb24b63440 watch: Fixed output errors when --no-wrap and blank lines or wide wchars [#285]
Errors fixed when --no-wrap:
* empty line following a truncated line omitted from output
* overlong line isn't truncated when the truncation should happen "in the
  middle" of a wide (wcwidth) wchar

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:22:49 +11:00
Roman Žilka
0e472f791c watch: minor optimisations and fixes
Minor optimisations (narrower types)
Fixed indentation
minor fixes (wcwidth() only if not WEOF, wint_t accessed as *(wchar_t *)&var)

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:21:33 +11:00
Roman Žilka
67284cb719 watch: my_getwc(): errors when char signed/unsigned, off-by-one in ungetc(), ...
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:19:02 +11:00
Roman Žilka
03aa5d371c watch: Inserted a missing !8bit segment in run_command(); reduced 8bit ifdefs with finer macros
Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-06 16:12:37 +11:00
Roman Žilka
6884420264 str*dup()->xstr*dup() where needed; library: openproc(): avoid closedir(NULL) 2023-10-06 05:03:30 +00:00
Roman Žilka
b5db042e54 library/stat: Avoid smaller_int=huge_ULL in delta calc. due to newval<oldval 2023-10-05 15:22:21 +02:00
Roman Žilka
30cd16af3a vmstat: Type correction in stat output, in update counter 2023-10-05 15:22:21 +02:00
Jim Warner
4b735b3dc4 build-sys: only define USE_PROC_CTTY when under Cygwin
Unfortunately the previous '0' value for USE_PROC_CTTY
meant the Cygwin specific code in the devname.c module
would always be executed. That, in turn, meant a bunch
openat errors for anyone using PIDS_TTY_NAME / NUMBER.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-10-05 07:28:32 +11:00
Jim Warner
92bdeb176f NEWS: acknowledge fix for the lost tasks ps issue #304
[ and eliminate 1 decades old useless initialization ]

Reference(s):
. Sep, 2023 - fix for ps issue #304
commit 09fbd70de3

Signed-off-by: Jim Warner <james.warner@comcast.net>
2023-10-05 07:28:32 +11:00
Craig Small
23491ebf40 pgrep: Add match to environment variable
prep --env=KEY=value

Matches processes that have the environment variable KEY set to
VALUE

References:
 #167

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 21:55:06 +11:00
Craig Small
3431c17d45 ps: Add environment output
Added environment output for ps, using
 ps -o environ

Default length is 31 characters, like for the other "long" fields.

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 20:53:30 +11:00
Craig Small
0892f0b823 watch: Use clock_gettime where available
clock_gettime(CLOCK_MONOTONIC) is not impacted by the admin changing the
time and is always equal or more than the previous call (e.g. time never
goes backwards).

References:
 #295

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 20:32:43 +11:00
Sam James
aa85fb458a testsuite: skip tests where relevant binaries aren't built
* With --without-ncurses, slabtop isn't built.
* With --disable-w, w isn't built.

Signed-off-by: Sam James <sam@gentoo.org>
2023-10-04 08:56:22 +00:00
Craig Small
d59797b4cd misc: Add NEWS for previous glob commit
Added NEWS entry for sysctl glob exclude

References:
 commit 39748b78b0
 !206

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 19:54:55 +11:00
Jacek Tomasiak
39748b78b0 sysctl: Add support for systemd glob excludes
The systemd-sysctl version supports excludes with globs too.
Support for that was added to sysctl to match systemd.
Existing test was updated to test this behaviour.

Signed-off-by: Jacek Tomasiak <jtomasiak@arista.com>
Signed-off-by: Jacek Tomasiak <jacek.tomasiak@gmail.com>
2023-10-04 08:53:28 +00:00
Craig Small
65e3c4ad82 testsuite: Add pmap -XX too
Previous commit fixed it for pmap -X 1 this fixes it for
pmap -XX 1

Signed-off-by: Craig Small <csmall@dropbear.xyz>
2023-10-04 17:24:46 +11:00
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