Commit Graph

2342 Commits

Author SHA1 Message Date
Nathan Scott c401ac3a98 Ensure DynamicColumn hash lookups never see NULL pointers
This cannot happen in these code locations, but for the purposes
of static checkers like Coverity scan (and for future proofing),
add two more guards on NULL hash table entry pointers.
2021-08-17 14:41:40 +10:00
Sohaib fefff80631 PCP: PCPMetric.[ch] Mdoule
Split the PCP Metric API (functions `Metric_*`) into their own module.
as @BenBE suggested.
2021-08-16 17:23:07 +02:00
Christian Göttsche edafa26f9e Simplify Action_pickFromVector() width parameter usage
Pass one less instead of subtracting one inside the function.
2021-08-16 08:05:46 +02:00
Christian Göttsche 68460b25e3 Reset the signal handlers at program exit
The signal handler will access the Settings struct, which gets freed at
normal program finalization.

When using leak sanitizers with ASAN_OPTIONS=abort_on_error=1, which
runs after program termination, any leak causes SIGABRT to be raised,
calling the crash handler, which will derefernce the freed Settings.

    ==44741==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d000000080 at pc 0x0000005680df bp 0x7fffe335e960 sp 0x7fffe335e958
    READ of size 8 at 0x60d000000080 thread T0
        #0 0x5680de in Settings_write /home/christian/Coding/workspaces/htop/Settings.c:329:26
        #1 0x4f77b7 in CRT_handleSIGSEGV /home/christian/Coding/workspaces/htop/CRT.c:1020:4
        #2 0x7f8a1120c13f  (/lib/x86_64-linux-gnu/libpthread.so.0+0x1413f)
        #3 0x7f8a11042ce0 in __libc_signal_restore_set signal/../sysdeps/unix/sysv/linux/internal-signals.h:86:3
        #4 0x7f8a11042ce0 in raise signal/../sysdeps/unix/sysv/linux/raise.c:48:3
        #5 0x7f8a1102c536 in abort stdlib/abort.c:79:7
        #6 0x4c3db6 in __sanitizer::Abort() (/home/christian/Coding/workspaces/htop/htop+0x4c3db6)
        #7 0x4c2090 in __sanitizer::Die() (/home/christian/Coding/workspaces/htop/htop+0x4c2090)
        #8 0x4d0a17 in __lsan::HandleLeaks() (/home/christian/Coding/workspaces/htop/htop+0x4d0a17)
        #9 0x4cd950 in __lsan::DoLeakCheck() (/home/christian/Coding/workspaces/htop/htop+0x4cd950)
        #10 0x7f8a110454d6 in __run_exit_handlers stdlib/exit.c:108:8
        #11 0x7f8a11045679 in exit stdlib/exit.c:139:3
        #12 0x7f8a1102dd10 in __libc_start_main csu/../csu/libc-start.c:342:3
        #13 0x428a19 in _start (/home/christian/Coding/workspaces/htop/htop+0x428a19)

    0x60d000000080 is located 64 bytes inside of 144-byte region [0x60d000000040,0x60d0000000d0)
    freed by thread T0 here:
        #0 0x4a4f72 in free (/home/christian/Coding/workspaces/htop/htop+0x4a4f72)
        #1 0x566693 in Settings_delete /home/christian/Coding/workspaces/htop/Settings.c:32:4
        #2 0x4ede10 in CommandLine_run /home/christian/Coding/workspaces/htop/CommandLine.c:393:4
        #3 0x4d6f32 in main /home/christian/Coding/workspaces/htop/htop.c:15:11
        #4 0x7f8a1102dd09 in __libc_start_main csu/../csu/libc-start.c:308:16

    previously allocated by thread T0 here:
        #0 0x4a5372 in __interceptor_calloc (/home/christian/Coding/workspaces/htop/htop+0x4a5372)
        #1 0x57f61a in xCalloc /home/christian/Coding/workspaces/htop/XUtils.c:55:17
        #2 0x5688a6 in Settings_new /home/christian/Coding/workspaces/htop/Settings.c:392:21
        #3 0x4ecb57 in CommandLine_run /home/christian/Coding/workspaces/htop/CommandLine.c:303:25
        #4 0x4d6f32 in main /home/christian/Coding/workspaces/htop/htop.c:15:11
        #5 0x7f8a1102dd09 in __libc_start_main csu/../csu/libc-start.c:308:16

SUMMARY: AddressSanitizer: heap-use-after-free /home/christian/Coding/workspaces/htop/Settings.c:329:26 in Settings_write
2021-08-16 08:05:07 +02:00
Benny Baumann b42c441ee0 Use proper metric to detect kernel threads
Querying kernel threads with `ps -o pid,lid,flags,state,lname -sp 0`
gives that kernel threads have state `K` and flags have mask `0x20000` set.
This corresponds to `LW_SYSTEM` in kernel which is mapped as `L_SYSTEM`/`P_SYSTEM` for userspace.
2021-08-16 08:03:57 +02:00
fraggerfox 68123adb6f Build fix for NetBSD 2021-08-16 07:45:04 +02:00
Christian Göttsche ce27f8379d Respect "Show custom thread names" setting update
Update merged command-line when started with "Show custom thread names"
disabled and enabling at runtime.

Also only consider showThreadNames when working on userland threads.
2021-08-14 17:05:00 +02:00
Explorer09 2d1b6f4783 TasksMeter: save some float casts
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
2021-08-14 11:16:03 +02:00
Daniel Lange fc2377f052 Build pcp-htop.5 only when --enable-pcp 2021-08-14 10:44:31 +02:00
nia dd91e9a9da netbsd: Add NetworkIOMeter support 2021-08-13 22:27:14 +02:00
Nathan Scott 9a07ba2700
Merge pull request #705 from natoscott/pcp-htop-manual
docs: updates and new manual page for pcp-htop
2021-08-13 16:05:38 +10:00
Nathan Scott 5b5836a2b1
Apply suggestions from code review
Co-authored-by: BenBE <BenBE@geshi.org>
2021-08-13 16:04:25 +10:00
Nathan Scott f839095e3b Merge branch 'dynamic-columns' of https://github.com/smalinux/htop into smalinux-dynamic-columns 2021-08-13 15:56:01 +10:00
Sohaib Mohamed 6f2021f3d9 PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns.  The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.

We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.

Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location.  Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop.  This
final location becomes the preferred place for our own
shipped meter and column files.

The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start.  Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-08-13 07:32:57 +02:00
Christian Göttsche 6974ce8e79 Linux: do not include zram devices in DiskIO
The meter is intended to show *real* IO, which is significantly slower
than zram.
2021-08-10 22:01:42 +02:00
Christian Göttsche 796bc36fe0 Add assert to improve backtraces on NULL function pointer 2021-08-10 21:26:50 +02:00
Christian Göttsche ba5ef1ac8b CPUMeter: show if a CPU is offline in text mode
Related to #729 as the text mode displays all zero values for offline
CPUs.
2021-08-10 17:09:04 +02:00
Christian Göttsche 671282d309 Correct grammatical error in crash information
Spotted by @natoscott
2021-08-10 17:09:04 +02:00
Christian Göttsche a8b8f5f836 ScreenManager: drop unused member 2021-08-10 17:09:04 +02:00
Christian Göttsche 51669ecba8 Solaris: the average CPU utilization value must never be marked 'offline'
Similar to #729 only for Solaris
2021-08-10 17:09:04 +02:00
Nathan Scott 02cfd38671 The average CPU utilization value must never be marked 'offline'
Fixes https://github.com/htop-dev/htop/issues/729
2021-08-10 08:00:35 +02:00
nia 6d3b4a0f2e netbsd: handle repeated ENOMEM from HW_IOSTATS safely 2021-08-09 14:17:06 +02:00
Nathan Scott c31fd3c691 Merge branch 'pcp-dynamic-cpu' 2021-08-09 19:24:29 +10:00
nia 324f9d048d netbsd: add more robust error handling for sysctl HW_IOSTATS 2021-08-09 09:08:37 +02:00
nia 5b8654d341 netbsd: Add support for DiskIOMeter 2021-08-09 09:08:37 +02:00
Daniel Lange eb4ff3c69c Add Shift-F7, Shift-F8 keybindings for autogroups 2021-08-09 16:23:09 +10:00
Nathan Scott 1bd95983b2 Add columns for process autogroup identifier and nice value
Adds AGRP (autogroup) and ANI (autogroup nice) columns that
report the information from /proc/PID/autogroup, as well as
handlers for '{' and '}' to change the autogroup nice value.

This is guarded by /proc/sys/kernel/sched_autogroup_enabled
such that sampling and/or changing values wont be attempted
unless the kernel feature is enabled.

Fixes: #720
2021-08-09 07:56:13 +02:00
Nathan Scott ee831263c3 PCP: implement a missing piece for offline and hotplug CPUs
Related: #656
2021-08-09 12:42:45 +10:00
Christian Göttsche aa0424ade8 configure: check for NaN compiler support
Compilers might due to optimizations, like -ffast-math (included in
-Ofast) expect floating point variables to be never NaN and replace each
call to isnan() with false.  Htop uses the value NaN for signaling no
data available for various information.

Warn at configure time if the compiler will ignore NaN values.

Note: this can not be implemented as a compile time static assert, as
some compilers handle compile NaNs differently than runtime NaNs.
2021-08-08 17:02:12 +02:00
Christian Göttsche 10e9ffd8e5 Fix misc typos
[ci skip]
2021-08-08 15:10:58 +02:00
nia 97a859c5bd netbsd: Use newer proplib API. Create aliases so it works on 9.x.
This way we avoid deprecation warnings on the development branch
of NetBSD while keeping the code functioning on the stable branch.
2021-08-05 10:47:14 +02:00
nia c85aafa608 netbsd: If at least one AC adapter is connected, keep its state. 2021-08-05 10:47:14 +02:00
nia 93ca5af953 netbsd: style: declare variables on first use rather than C89-style 2021-08-05 10:47:14 +02:00
nia fdcdc54ec4 netbsd: Add battery support
This uses proplib and sysmon_envsys to determine the total charge
percentage of any number of connected batteries as well as the
AC adapter state. Should work with ACPI and non-ACPI systems.
2021-08-05 10:47:14 +02:00
fraggerfox 2e3f34f5c1 NetBSD: Rework CPU counting. 2021-08-05 10:25:59 +02:00
Nathan Scott 04da92dfd1 docs: updates and new manual page for pcp-htop
Add some words about pcp-htop to the main man page, and add a
new man page describing the pcp-htop configuration files that
allow new meters and columns to be defined at runtime.
2021-08-03 14:11:21 +10:00
Daniel Lange ed82ce6456 Merge branch 'cpu_count' of cgzones/htop 2021-08-02 15:21:07 +02:00
Benny Baumann e341217fea Properly handle multiple batteries on darwin
This makes the behaviour consistent with other platforms where AC is
marked as present if at least one power source is marked as AC_PRESENT.

Fixes: #711
2021-08-02 14:37:44 +02:00
Benny Baumann 44e01dd32b Makefile.am fix that actually does a proper substitution 2021-08-02 00:43:10 +02:00
Benny Baumann 03705a20aa Fix portability issue in Makefile.am
Fixes #662
2021-08-02 00:00:46 +02:00
Nathan Scott 19ad28a560 PCP: fix per-process user and system time conversions 2021-07-29 10:15:43 +02:00
Nathan Scott 97d9b320ad PCP: use the correct metric for shared memory calculations 2021-07-29 10:14:51 +02:00
nia 4f3ba680fb Fix indentation style 2021-07-21 21:06:58 +02:00
nia 3fced48eea netbsd: convert snprintf use to xSnprintf 2021-07-21 21:06:58 +02:00
nia a4b650fdec netbsd: re-initialize freqSize before sysctlbyname() 2021-07-21 21:06:58 +02:00
nia 72cea2881c netbsd: Remove conditional compilation of CPU frequency variables 2021-07-21 21:06:58 +02:00
nia b4884373e5 netbsd: Support display of CPU frequency 2021-07-21 21:06:58 +02:00
Daniel Lange 370f89c086 Merge branch 'fix-dragon' of smalinux/htop 2021-07-18 13:03:13 +02:00
Sohaib Mohamed 32faba0b6d DragonFlyBSD: fixup: ProcessList_new declaration & definition mismatch 2021-07-18 12:41:11 +02:00
Sohaib Mohamed 82aa956940 PCP: fixup: missing setter for isUserlandThread
fixes the color of PROC_COMM for PCP...
2021-07-18 10:28:52 +02:00