Commit Graph

2674 Commits

Author SHA1 Message Date
Kevin Bracey
4a664c0df8 Help: Linux swap consistency
On the help screen's depiction of the swap bar, the / separator between
used and cache should be coloured for consistency with the other bars.

I tried removing the coloured /s from the other bars to make them
consistent, but found that less visually appealing.
2022-01-13 19:45:01 +01:00
Tobias Stoeckmann
d0d9f202c5 Avoid zombie processes on signal races
The system curses library can handle terminal size changes with
SIGWINCH without asking system calls to restart, which effectively
stops system calls with -1 and EINTR. An example is ncurses on
Linux systems.

One of these system calls is waitpid. While waiting for the lsof child
to complete, a badly timed SIGWINCH can interrupt the waitpid call,
effectively never clearing the state of the child, keeping the zombie
until htop exits.

Proof of Concept:

 #include <unistd.h>
 int main(void) {
   close(1); close(2);
   sleep(5);
   return 0;
 }

Compile this as a replacement "lsof" and put it into your path. Make
sure that it's called instead of the real lsof.

Press "l" to list open files and resize your terminal within the next
5 seconds. You will see that a zombie process is kept by htop when the
timeout finishes.
2022-01-11 22:56:27 +01:00
Tobias Stoeckmann
a0ad0697a8 Always set SIGCHLD to default handling
The parent process of htop might have set SIGCHLD to ignore, which can
be inherited by htop (Linux does this, OpenBSD resets to default).

If SIGCHLD is ignored then waitpid returns -1 which is not properly
handled by htop for lsof output.

Proof of Concept (Linux):

 #include <signal.h>
 #include <unistd.h>
 int main(void) {
   char *arg[] = { "htop", NULL };
   signal(SIGCHLD, SIG_IGN);
   execv("htop", arg);
   return 1;
 }

If you run htop with ignored SIGCHLD then pressing "l" always fails,
i.e. it is not possible to list open files even if lsof is installed.
2022-01-11 22:56:27 +01:00
Tobias Stoeckmann
a133ffd829 Removed unused String_getToken function
Since String_getToken is not used anymore and currently only supports
a 50 char token, simply remove it for now.
2022-01-11 21:42:57 +01:00
Tobias Stoeckmann
fde1243443 Fix out of boundary writes in XUtils
It is possible to exceed the unsigned int data type on 64 bit systems
with enough available RAM. Use size_t in all places instead.

Proof of Concept: Create a 4 GB line in .htoprc file and run htop

$ dd if=/dev/zero bs=1024 count=4194304 | tr '\0' 'a' > ~/.htoprc
$ htop
Segmentation fault

Also avoid overflow of stack based "match" array in String_getToken.
2022-01-11 21:42:57 +01:00
Tobias Stoeckmann
6eab39c0ab Fix typo
This typo has been found with codespell.
2022-01-11 19:56:27 +01:00
Daniel Lange
2c3a64ac9c Year 2022 updates 2022-01-03 18:01:18 +01:00
Christian Göttsche
442c1596f6 GH Actions: enable Werror in PCP build
Just exclude the singe warning type currently issued.

Avoids e64269df ("Fix process state handling compiler warning on PCP platform")
2021-12-20 10:54:12 +01:00
Denis Lisov
f782f821f7 LinuxProcessList: do not collect LRS per thread
It's a memory map property, so it's process-wide and collecting it just
once should be enough.
2021-12-18 12:31:36 +01:00
Christian Göttsche
5b78ad2d53 Set correct default sorting direction
Respect the field option defaultSortDesc for the default screen sort
direction, e.g. for CPU%.
2021-12-17 14:45:15 +01:00
Christian Göttsche
1ef8c0e12f Drop getCommandStr member of Process
Formatting the merged command string is now implemented in an platform
independent way. Drop the Process member getCommandStr designed for
overrides of individual platforms.
2021-12-17 14:45:15 +01:00
Christian Göttsche
6fcb1994c8 Do not combine default and configuration process fields
When reading a configuration file with the syntax previous to the
screens update Settings_defaultScreens() will add the default fields and
later ScreenSettings_readFields() will add the ones from the
configuration file. This will duplicate some fields and corrupt the
columns due to the boundless Command field.
2021-12-17 14:45:15 +01:00
Christian Göttsche
5bc988ad6d Use correct command field as default field
The default htop command process field has the enum identifier `COMM`
but the name `Command` (`COMM` is the field name for /proc/<PID>/comm).
2021-12-17 14:45:15 +01:00
Christian Göttsche
6e9a5e9e49 Mark ScreenDefaults const 2021-12-17 14:45:15 +01:00
Christian Göttsche
14f428a172 Drop unused Platform variables 2021-12-17 14:45:15 +01:00
Christian Göttsche
6388033e10 configure: support libunwind of LLVM
The libunwind headers of LLVM are located in the subdirectory
/usr/include/libunwind. Search that subdirectory when the default
header test fails. Also extend the include path due to the transitive
include of `<__libunwind_config.h>`.

Closes: #894
2021-12-16 17:51:15 +01:00
Christian Göttsche
b45eaf2fe1 Hashtable: use a minimum size of 7
With a size of 2 or 3 the grow factor does not reach 70% for one empty
entry. This will cause the following assert violation:

    htop: Hashtable.c:236: void Hashtable_put(Hashtable *, ht_key_t, void *): Assertion `this->size > this->items' failed.
2021-12-13 21:17:58 +01:00
Denis Lisov
230dc9c3c1 Hashtable: adjust shrink-on-remove factor
Due to the use of prime numbers Hashtable_remove used to never shrink
from some sizes. For example, a size 8191 hashtable would try to shrink
to 4095, which nextPrime would round back to 8191 instead of the
intended 4093. A factor of 3 is enough to allow every prime size used to
shrink to the previous one.
2021-12-13 21:05:22 +01:00
Denis Lisov
d084a80023 Hashtable: skip rehashing if the size is the same
Hashtable_setSize should not rehash if the actual size stays the same as
the number of buckets and natural positions stay the same too.
2021-12-13 21:05:22 +01:00
Christian Göttsche
5c8670717a Do not leave empty last column in header
Do not leave empty last column in header meters by refactoring the width
and separator logic.

Closes: #784
2021-12-09 17:52:00 +01:00
Nathan Scott
bc08c7dc2a
Merge pull request #889 from cgzones/screens_update
Screens update
2021-12-09 08:38:25 +11:00
Christian Göttsche
1e94b92226 Linux: read generic sysfs batteries
Not all batteries entries in /sys/class/power_supply start with either
BAT or AC, but might have device specific names, e.g. CMB1.
Detect the types of those entries and parse them accordingly.

Closes: #881
Fixes: 3e70de64 ("Code clean up for reading battery info")
2021-12-08 20:50:11 +01:00
Christian Göttsche
63fafb4844 IOMeters: rework initial display
Show a non highlighted string at the start of htop, not the failure
text.
Also the original fix only handled the text mode, not the bar mode.

Improves: 2977414d ("Discard stale information from DiskIO and NetworkIO meters")
Related: #860
2021-12-08 19:08:20 +01:00
Christian Göttsche
c85e5bbf5c ScreenPanels: free ScreenSettings of deleted screens 2021-12-08 16:34:15 +01:00
Christian Göttsche
c9e0bd2002 ScreenPanel: misc updates
- use ASCII escape sequences
- use array allocation wrappers
2021-12-08 16:34:15 +01:00
Christian Göttsche
df1914f429 Add ScreenSettings_delete helper 2021-12-08 16:34:15 +01:00
Christian Göttsche
3cfdf66d9a Settings: initialize default sort key for new screenpanel
Use C99 struct initialization, which also makes using calloc redundant.

htop: Process.c:1179: int Process_compareByKey_Base(const Process *, const Process *, ProcessField): Assertion `0 && "Process_compareByKey_Base: default key reached"' failed.
2021-12-08 14:55:14 +01:00
Christian Göttsche
fa9f260f63 Process: print default key 2021-12-08 14:48:20 +01:00
Christian Göttsche
1da78b5818 CRT: add debug printing function 2021-12-08 14:48:20 +01:00
Christian Göttsche
2ae1906479 Panel: initialize cursorOn member
Panel.c:496:14: runtime error: load of value 190, which is not a valid value for type 'bool'
2021-12-08 12:40:13 +01:00
Nathan Scott
0e58784224 Fix memory leak on shutdown in new screen settings code.
Also tidy up the calloc call parameters in the initial allocation
of this pointer, thanks to @BenBE for noticing.
2021-12-07 17:04:49 +11:00
Sohaib Mohamed
4ef5e4296e fix CI issue
Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
2021-12-07 17:04:49 +11:00
Sohaib Mohamed
ba3a1df806 Fix misc styleguide issues and add missing header files
Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
2021-12-07 17:04:49 +11:00
Sohaib Mohamed
b672e60886 Enable tabs for a fresh install of htop Only
If the new htop is configured with htoprc having no tabs (eg on upgrade)
then the interface will not automatically introduce/enable them.
However, for a fresh install of htop, enabling them automatically

Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
2021-12-07 17:04:49 +11:00
Sohaib Mohamed
cd6457ef88 Fixup tabs with dynamic Columns - add missing Dynamic() 2021-12-07 17:04:49 +11:00
Sohaib Mohamed
31fe29c5a7 Pass correct ColorElements values to Panel_setSelectionColor 2021-12-07 17:04:49 +11:00
Nathan Scott
cc2547fcf0 Improvements to the tab code after initial feedback 2021-12-07 17:04:49 +11:00
Hisham Muhammad
72ba20fa5f Introduce screen tabs
This is a forward port (by nathans) of Hisham's original code.
2021-12-07 17:04:49 +11:00
Christian Göttsche
ff4f44b22a Pre-select the last sent signal in SignalsPanel
Instead of pre-selecting SIGTERM every time, select the signal last
send in the same htop session.

Closes: #862
2021-12-05 19:36:36 +01:00
Christian Göttsche
a38f48481e Process: highlight UNINTERRUPTIBLE_WAIT state (D)
Commit d8dfbbd3 ("Tidy up process state handling") did change the
highlighting of the UNINTERRUPTIBLE_WAIT state (D) from red to gray.
As this state might means the process probably still has work to do and
can hint at bottlenecks, revert this particular change.

Fixes: d8dfbbd3 ("Tidy up process state handling")
2021-12-05 19:29:10 +01:00
Christian Göttsche
61c9fe44a3 CGroupUtils: avoid unsigned integer underflow
Do not underflow count at the last iteration, which triggers UBSAN when
using -fsanitize=unsigned-integer-overflow. This is useful as those
underflows can be a result of a flawed counting logic (e.g. a counter
gets reduced more than increased).
2021-12-05 19:28:07 +01:00
Emmanuel Mathi-Amorim
ff0ea41c86 Fix issue where last line is not cleared when SIGINT is received
When we close the application using the quit function F10, the last line
is cleared so that on terminals which do not support ALTBUF the last
line is not clobbered. This do not happen when the application exits as
a result of a signal (SIGINT,SIGTERM,SIGQUIT).

Move the logic to clear the last line into the CRT_done function. This
ensures that it will be executed when the CRT_handleSIGTERM is called.
2021-12-01 17:08:13 +01:00
Nathan Scott
43e9be5a8f Update version number to 3.2.0-dev to identify git repo builds 2021-11-30 12:10:54 +11:00
Nathan Scott
d73783d6db Release 3.1.2 2021-11-30 12:03:21 +11:00
Nathan Scott
89b7c4c9f9 Merge branch 'release_action' of https://github.com/rofl0r/htop into rofl0r-release_action 2021-11-30 11:16:57 +11:00
Nathan Scott
78aefc2a99 Minor typo fix and wordsmith-ing in the changelog 2021-11-30 11:15:35 +11:00
Benny Baumann
697c502b7e Update changelog to include recent changes 2021-11-28 23:34:41 +01:00
Lutz Mader
171aa0faaa Add a fix to use gettimeofday if monotonic is not available. 2021-11-28 23:13:46 +01:00
Peter VandeHaar
ddfacb8694 Get file size using stat() for OpenFilesScreen if missing from lsof 2021-11-28 20:32:02 +01:00
Peter VandeHaar
5beef3e737 Strip prefix "0t" from OFFSET column of OpenFilesScreen 2021-11-28 20:32:02 +01:00