83 Commits
3.1.0 ... 3.1.2

Author SHA1 Message Date
d73783d6db Release 3.1.2 2021-11-30 12:03:21 +11:00
89b7c4c9f9 Merge branch 'release_action' of https://github.com/rofl0r/htop into rofl0r-release_action 2021-11-30 11:16:57 +11:00
78aefc2a99 Minor typo fix and wordsmith-ing in the changelog 2021-11-30 11:15:35 +11:00
697c502b7e Update changelog to include recent changes 2021-11-28 23:34:41 +01:00
171aa0faaa Add a fix to use gettimeofday if monotonic is not available. 2021-11-28 23:13:46 +01:00
ddfacb8694 Get file size using stat() for OpenFilesScreen if missing from lsof 2021-11-28 20:32:02 +01:00
5beef3e737 Strip prefix "0t" from OFFSET column of OpenFilesScreen 2021-11-28 20:32:02 +01:00
27a18830d5 Add OFFSET column to OpenFilesScreen 2021-11-28 20:32:02 +01:00
b98a4f8d56 Include support for legacy LXC cgroup naming 2021-11-28 20:19:10 +01:00
55e073a455 Use helpers for parsing of cgroup labels 2021-11-28 20:19:10 +01:00
915b558bbe Document CCGROUP column 2021-11-28 20:19:10 +01:00
550100327b Extract string writing/buffer handling into some callback 2021-11-28 20:19:10 +01:00
9dc964bb42 Compress cgroup names based on some heuristics 2021-11-28 20:19:10 +01:00
ea4282784d Filter leading colons in CGROUP name 2021-11-28 20:19:10 +01:00
1c3c149d20 Ensure maximum width for CGROUP column 2021-11-28 20:19:10 +01:00
42c0493021 add github workflow to build release tarball 2021-11-23 16:29:25 +00:00
1284ab4835 Reduce allocation size of cp_time_n and cp_time_o on FreeBSD and DragonFlyBSD 2021-11-19 12:46:48 +01:00
07496eafb0 Linux: use proper way to detect kernel threads
Use PF_KTHREAD flag in /proc/[pid]/stat to detect kernel threads.
This fixed an issue when a process's cmdline is empty, htop think
it is a kernel thread.
2021-11-09 19:04:25 +01:00
e7a8d14cbd Correct the order of xCalloc parameters in a couple of places
No functional change.  Thanks to @BenBE for pointing these out.
2021-11-05 09:22:09 +11:00
21cb1c4d59 Cleanup: Fix misc styleguide issues
Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
2021-11-04 23:13:38 +01:00
e64269df2c Fix process state handling compiler warning on PCP platform 2021-11-03 15:46:20 +11:00
d8dfbbd37c Tidy up process state handling 2021-11-02 20:02:54 +01:00
afa3fe4af1 Drop unicode whitespace 2021-11-01 12:12:13 +01:00
2ef70ad7f6 Early program termination only from main() 2021-10-31 15:07:00 +01:00
2977414d54 Discard stale information from DiskIO and NetworkIO meters
This ensures the initial read of the data is not misinterpreted as arbitrarily large values.
Also this forces the maximum update interval between two subsequent reads to within 30s.

Fixes #860
2021-10-30 10:57:14 +02:00
696f79fe50 Dynamically scale the ST_UID size to support 32-bit UIDs
While most Unix-like systems use 16-bit user IDs,
Linux supports 32-bit UIDs since version 2.6.
UIDs above 65535 are used for UID namespacing of containers,
where a container has its own set of 16-bit user IDs.
Processes in such containers will have (much) larger UIDs than 65535.

Because the current format strings for `ST_UID` and `USER`
are `%5d` and `%9d` respectively, processes with such UIDs
lead to misaligned columns.

Dynamically scale the `ST_UID` column and increase the size of `USER`
to 10 characters (length of UINT32_MAX) to ensure that the user ID always fits.

Additionally: clean up how the titlebuffer size calculation and ensure
the PID column has a minimum size of 5.
2021-10-27 21:20:59 +02:00
4374a267be Linux: restore battery state with numbered AC's 2021-10-26 10:58:59 +02:00
3e70de64b3 Code clean up for reading battery info 2021-10-25 22:43:10 +02:00
3f9f52fd29 Linux: ignore mapped /dev/zero
Virtualbox maps /dev/zero for memory allocation. That results in
false positive, so ignore.
2021-10-25 21:05:28 +02:00
dfa62506b7 Allow -u UID
Defaults to username, of course, like all POSIX utilities do
2021-10-24 04:39:58 +02:00
731b4003a2 Fix Security Attributes column header width
Limit the maximum width (instead of only the minimum width), pad the
header width accordingly, and also remove extra stray spaces from the
format string (the main spacing should just come from the alignment of
the value).

Fixes #850.
2021-10-20 15:02:26 +02:00
30c5004cbb Merge branch 'del-exe-lib-docs' of BenBE/htop into main 2021-10-19 06:59:11 +02:00
9d3a1d4981 Elaborate the highlighting of outdated/deleted executables and libraries 2021-10-19 00:39:24 +02:00
60cfa2edce FreeBSD: add comment for memory leak workaround
Follow-up of #841

[ci skip]
2021-10-15 22:22:30 +02:00
604744f68d Header: allocate memory for terminating entry
The names array is terminated by a NULL entry, thus allocate space for
one more than entries.

Fixes: #844

==6708==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6060000045b8 at pc 0x000000589ee1 bp 0x7ffcd1dee220 sp 0x7ffcd1dee218
READ of size 8 at 0x6060000045b8 thread T0
    #0 0x589ee0 in String_freeArray ./XUtils.c:157:23
    #1 0x56c9af in Settings_delete ./Settings.c:31:7
    #2 0x4ee44b in CommandLine_run ./CommandLine.c:395:4
    #3 0x4d6fb2 in main ./htop.c:15:11
    #4 0x7ff3b8154e49 in __libc_start_main csu/../csu/libc-start.c:314:16
    #5 0x428aa9 in _start (./htop+0x428aa9)

0x6060000045b8 is located 0 bytes to the right of 56-byte region [0x606000004580,0x6060000045b8)
allocated by thread T0 here:
    #0 0x4a53f2 in __interceptor_calloc (./htop+0x4a53f2)
    #1 0x5890ba in xCalloc ./XUtils.c:55:17
    #2 0x50a044 in Header_writeBackToSettings ./Header.c:148:34
    #3 0x4de861 in Action_runSetup ./Action.c:91:7
    #4 0x4de861 in actionSetup ./Action.c:386:4
    #5 0x515caf in MainPanel_eventHandler ./MainPanel.c:106:19
    #6 0x56a5c1 in ScreenManager_run ./ScreenManager.c:235:19
    #7 0x4ee13b in CommandLine_run ./CommandLine.c:364:4
    #8 0x4d6fb2 in main ./htop.c:15:11
    #9 0x7ff3b8154e49 in __libc_start_main csu/../csu/libc-start.c:314:16
2021-10-15 12:16:41 +02:00
13fe58f54a Update version number to 3.2.0-dev to identify git repo builds 2021-10-14 23:53:41 +02:00
e785693ef9 Release 3.1.1 2021-10-14 23:42:05 +02:00
4cf74de1f1 Suppress reporting memory leaks originating from libdevstat
Based on https://cgit.freebsd.org/src/tree/lib/libdevstat/devstat.c
the following four functions call memory allocation functions:

- devstat_getdevs()
- devstat_selectdevs()
- devstat_buildmatch()
- get_devstat_kvm()
2021-10-14 23:25:19 +02:00
0a5890d332 Updates to the ChangeLog for 3.1.1 release 2021-10-13 17:03:35 +11:00
2128edfba2 Plug the memory leak for the Disk I/O meter
There are no functions in libdevstat to initialise or clean up memory. The simplest change is to mark the local variable info as static.
2021-10-12 09:09:00 +02:00
d1c833fe95 Merge branch 'revert-used-memory' 2021-10-12 17:47:03 +11:00
868b0b3574 Ensure consistent reporting of MemoryMeter used memory
Resolves #821
2021-10-12 17:46:44 +11:00
04871a2d04 Report hugepage memory as real and used memory (as before)
This is real, physical memory available for applications to
use.  We should not try to pretend otherwise; its confusing
for users and inconsistent with all other tools.
2021-10-12 17:46:16 +11:00
b7248f6cb8 Handle procExeDeleted & usesDeletedLib without mergedCommandline mode 2021-10-07 08:42:08 +02:00
74afca7bc1 Validate meter configuration before proceeding 2021-10-06 08:59:02 +02:00
2a13e15ad0 Properly release memory on partially read configuration 2021-10-06 08:59:02 +02:00
8ac8542b6e Handle interrupted sampling from within libpcp PDU transfers
This situation can arise if pcp-htop screen is resized right
at the same time sampling from pmcd(1) is happening.  Have a
couple more goes at it before giving up entirely; once there
is no data available though we cannot proceed into accessing
the sample result data structure (segv will result) so a new
short-circuit guard is added there also.
2021-10-05 15:53:18 +11:00
f75a8bc3a1 Memory leak on OpenBSD when querying full command line 2021-10-03 19:18:25 +02:00
d520199e62 Memory leak on NetBSD when querying full command line 2021-10-03 19:18:25 +02:00
9d8d87e1d5 Memory leak on DragonFlyBSD when querying full command line 2021-10-03 19:18:25 +02:00
57c1538887 Don't force allocation, as failure is handled 2021-10-03 19:18:25 +02:00
9eb52d5932 Release memory for cmdline when Process_updateCmdline() returns.
This closes a nasty memory leak. There is at least another leak looming somewhere when Disk I/O is shown in the header area. That could very well be an issue within libdevstat native to FreeBSD.
2021-10-03 19:18:11 +02:00
970885edc3 Linux: improve tryRead macro safety
Add an explicit else clause so a following else branch for a prior if
condition does not get mixed up.

Also force a trailing semicolon and thereby silence current
-Wextra-semi-stmt warnings.

Improve readability of the hwloc_bitmap_foreach_begin loop macro.
2021-10-01 18:36:35 +02:00
ae1816e563 Settings: use size_t for meter count in header
Header.c:150:26: error: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') [-Werror,-Wimplicit-int-conversion]
          colSettings->len = len;
                           ~ ^~~
2021-10-01 18:36:35 +02:00
53732ab0bb Resolve -Wimplicit-int-conversion warnings
Panel.c:414:49: error: implicit conversion loses integer precision: 'int' to 'short' [-Werror,-Wimplicit-int-conversion]
      this->scrollH = MAXIMUM(this->selectedLen - this->w, 0);
                    ~         ~~~~~~~~~~~~~~~~~~^~~~~~~~~
./Macros.h:11:54: note: expanded from macro 'MAXIMUM'
#define MAXIMUM(a, b)                  ((a) > (b) ? (a) : (b))
                                                     ^

IncSet.c:159:38: error: implicit conversion loses integer precision: 'int' to 'char' [-Werror,-Wimplicit-int-conversion]
         mode->buffer[mode->index] = ch;
                                   ~ ^~

Panel.c:456:24: error: implicit conversion loses integer precision: 'int' to 'char' [-Werror,-Wimplicit-int-conversion]
         buffer[len] = ch;
                     ~ ^~
Panel.c:473:22: error: implicit conversion loses integer precision: 'int' to 'char' [-Werror,-Wimplicit-int-conversion]
         buffer[0] = ch;
                   ~ ^~
2021-10-01 18:36:35 +02:00
8932efece9 astyle: Add --pad-header option
Insert space padding between a header (e.g. 'if', 'for', 'while'...) and the
following paren. ex:

if(isFoo((a+2), b))
    bar(a, b);

becomes:

if (isFoo((a+2), b))
    bar(a, b);

Link: http://astyle.sourceforge.net/astyle.html#_pad-paren
Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
2021-10-01 15:01:51 +02:00
d23627fda9 Adds a missing HAVE_GETMOUSE check.
Fixes builds failing with error
MainPanel.c:65:62: error: 'Settings {aka struct Settings_}' has no member named 'enableMouse'
    if (ch != ERR && (ch != KEY_MOUSE || this->state->settings->enableMouse))
2021-09-29 22:21:53 +02:00
4c846921a6 Improve configuration file version diagnostic formatting slightly 2021-09-27 15:13:01 +10:00
c5e789db1b Prepare changelog contents for the 3.1.1 bugfix release 2021-09-27 13:33:48 +10:00
eb94c4f9c9 Merge branch 'amomchilov-workaround-for-FB9546856' 2021-09-27 13:15:58 +10:00
8361c6c1ae Merge branch 'workaround-for-FB9546856' of https://github.com/amomchilov/htop into amomchilov-workaround-for-FB9546856 2021-09-27 13:15:50 +10:00
07f934ccfb Update the README to drop now redundant glibc version requirement 2021-09-27 13:14:23 +10:00
6f751d5929 Merge branch 'o_path' of https://github.com/cgzones/htop into cgzones-o_path 2021-09-27 13:13:13 +10:00
e26a2cf431 Workaround for Rosetta 2 on Darwin
rdar://FB9546856

https://openradar.appspot.com/radar?id=5055988478509056
2021-09-26 10:58:47 -04:00
d527bc9132 Refactor Platform_CompareKernelVersion API 2021-09-26 10:58:47 -04:00
dadcb87ad0 Extract Darwin "PlatformHelpers" 2021-09-26 10:58:47 -04:00
754c0d6bb9 Linux: always compute procExeDeleted if already set
A process, whose executable has been replaced and thus marked by htop,
can be re-executed with the replaced executable, with the same PID, in
two ways: the Linux feature checkpoint/restore or re-execution of PID 1.
The actual check is just a string comparison, like the dropped
condition, leading to (almost) no computation overhead.
2021-09-24 22:03:16 +02:00
9f4a4faab9 Merge branch 'license' of cgzones/htop 2021-09-24 21:25:00 +02:00
a710deeaa7 Linux: define O_PATH if not defined
Defining O_PATH if not defined by <fcntl.h> does not really add any
maintenance cost and might improve some portability.

Related: #804
2021-09-24 20:31:48 +02:00
466d6f99e2 Update remaining license headers to explicitly say GPLv2+
Also change ReadMe badge.
2021-09-24 20:28:26 +02:00
1601931bbf Merge branch 'fasterit-clarify-license' 2021-09-24 11:59:41 +10:00
41f9c0ab77 Merge branch 'clarify-license' of https://github.com/fasterit/htop into fasterit-clarify-license 2021-09-24 11:59:32 +10:00
e28d022716 Merge branch 'automake-compat' 2021-09-24 11:59:09 +10:00
d5ac75a5c7 Merge branch 'fasterit-fix-mouse-wheel' 2021-09-24 11:58:03 +10:00
2ba7d5ff36 Merge branch 'fix-mouse-wheel' of https://github.com/fasterit/htop into fasterit-fix-mouse-wheel 2021-09-24 11:57:52 +10:00
3d99c306b9 Document minimum versions for glibc and libcap. Thank you to James Brown (Roguelazer).
Closes #804
2021-09-23 18:10:51 +02:00
3d3474b3fc Adjust Makefile.am macro definitions for older automake versions
Fixes: #803
2021-09-23 10:06:38 +10:00
94ad111391 Update license headers to explicitly say GPLv2+ 2021-09-22 14:28:19 +02:00
976fa3b121 Make the "Released under the GNU GPLv2+. See 'man' page for more info." from ScreenManager.c valid 2021-09-22 14:23:49 +02:00
61227793de Clarify licensing
htop has been licensed as GPLv2 but there was inconsistency regarding the
option to choose "any later version" as granted by the license.

This commit clarifies the htop dev team is fine with that choice.
2021-09-22 14:23:38 +02:00
e6ded48d1a Update version to 3.1.1-dev 2021-09-22 11:49:25 +02:00
87c992739b Fix mouse wheel collision with autogroups nice adjustment
Fixes #805
2021-09-22 09:00:31 +02:00
29e1fcfa05 Use libunwind for printing backtrace 2021-09-21 09:06:30 +02:00
211 changed files with 1683 additions and 776 deletions

51
.github/workflows/build_release.yml vendored Normal file
View File

@ -0,0 +1,51 @@
name: Build Source Release
# Trigger whenever a release is created
on:
release:
types:
- created
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: archive
id: archive
run: |
VERSION=${{ github.event.release.tag_name }}
PKGNAME="htop-$VERSION"
SHASUM=$PKGNAME.tar.xz.sha256
autoreconf -i
mkdir -p /tmp/$PKGNAME
mv * /tmp/$PKGNAME
mv /tmp/$PKGNAME .
TARBALL=$PKGNAME.tar.xz
tar cJf $TARBALL $PKGNAME
sha256sum $TARBALL > $SHASUM
echo "::set-output name=tarball::$TARBALL"
echo "::set-output name=shasum::$SHASUM"
- name: upload tarball
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ steps.archive.outputs.tarball }}
asset_name: ${{ steps.archive.outputs.tarball }}
asset_content_type: application/gzip
- name: upload shasum
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ steps.archive.outputs.shasum }}
asset_name: ${{ steps.archive.outputs.shasum }}
asset_content_type: text/plain

View File

@ -1,7 +1,7 @@
/*
htop - Action.c
(C) 2015 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -519,7 +519,7 @@ static Htop_Reaction actionHelp(State* st) {
int line = 0;
mvaddstr(line++, 0, "htop " VERSION " - " COPYRIGHT);
mvaddstr(line++, 0, "Released under the GNU GPLv2. See 'man' page for more info.");
mvaddstr(line++, 0, "Released under the GNU GPLv2+. See 'man' page for more info.");
attrset(CRT_colors[DEFAULT_COLOR]);
line++;

View File

@ -3,7 +3,7 @@
/*
htop - Action.h
(C) 2015 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -2,7 +2,7 @@
htop - Affinity.c
(C) 2004-2011 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -4,7 +4,7 @@
htop - Affinity.h
(C) 2004-2011 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - AffinityPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - AffinityPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - AvailableColumnsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - AvailableColumnsPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - AvailableMetersPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - AvailableMetersPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - BatteryMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).

View File

@ -3,7 +3,7 @@
/*
htop - BatteryMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com).

View File

@ -1,7 +1,7 @@
/*
htop - CPUMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - CPUMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

79
CRT.c
View File

@ -1,7 +1,7 @@
/*
htop - CRT.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -21,14 +21,22 @@ in the source distribution for its full text.
#include "ProvideCurses.h"
#include "XUtils.h"
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#if !defined(NDEBUG) && defined(HAVE_MEMFD_CREATE)
#include <sys/mman.h>
#endif
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LIBUNWIND)
# define PRINT_BACKTRACE
# define UNW_LOCAL_ONLY
# include <libunwind.h>
# if defined(HAVE_DLADDR)
# include <dlfcn.h>
# endif
#elif defined(HAVE_EXECINFO_H)
# define PRINT_BACKTRACE
# include <execinfo.h>
#endif
#define ColorIndex(i,j) ((7-(i))*8+(j))
@ -1008,6 +1016,59 @@ void CRT_setColors(int colorScheme) {
CRT_colors = CRT_colorSchemes[colorScheme];
}
#ifdef PRINT_BACKTRACE
static void print_backtrace(void) {
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LIBUNWIND)
unw_context_t context;
unw_getcontext(&context);
unw_cursor_t cursor;
unw_init_local(&cursor, &context);
unsigned int item = 0;
while (unw_step(&cursor) > 0) {
unw_word_t pc;
unw_get_reg(&cursor, UNW_REG_IP, &pc);
if (pc == 0)
break;
char symbolName[256] = "?";
unw_word_t offset = 0;
unw_get_proc_name(&cursor, symbolName, sizeof(symbolName), &offset);
unw_proc_info_t pip;
pip.unwind_info = NULL;
const char* fname = "?";
const void* ptr = 0;
if (unw_get_proc_info(&cursor, &pip) == 0) {
ptr = (const void*)(pip.start_ip + offset);
#ifdef HAVE_DLADDR
Dl_info dlinfo;
if (dladdr(ptr, &dlinfo) && dlinfo.dli_fname && *dlinfo.dli_fname)
fname = dlinfo.dli_fname;
#endif
}
const char* frame = "";
if (unw_is_signal_frame(&cursor) > 0)
frame = "{signal frame}";
fprintf(stderr, "%2u: %#14lx %s (%s+%#lx) [%p]%s%s\n", item++, pc, fname, symbolName, offset, ptr, frame ? " " : "", frame);
}
#elif defined(HAVE_EXECINFO_H)
void* backtraceArray[256];
size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO);
#else
#error No implementation for print_backtrace()!
#endif
}
#endif
void CRT_handleSIGSEGV(int signal) {
CRT_done();
@ -1022,7 +1083,7 @@ void CRT_handleSIGSEGV(int signal) {
" - Likely steps to reproduce (How did it happen?)\n"
);
#ifdef HAVE_EXECINFO_H
#ifdef PRINT_BACKTRACE
fprintf(stderr, " - Backtrace of the issue (see below)\n");
#endif
@ -1048,16 +1109,14 @@ void CRT_handleSIGSEGV(int signal) {
Settings_write(CRT_crashSettings, true);
fprintf(stderr, "\n\n");
#ifdef HAVE_EXECINFO_H
#ifdef PRINT_BACKTRACE
fprintf(stderr,
"Backtrace information:\n"
"----------------------\n"
);
void* backtraceArray[256];
print_backtrace();
size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO);
fprintf(stderr,
"\n"
"To make the above information more practical to work with, "

8
CRT.h
View File

@ -3,7 +3,7 @@
/*
htop - CRT.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -147,9 +147,9 @@ void CRT_fatalError(const char* note) ATTR_NORETURN;
void CRT_handleSIGSEGV(int signal) ATTR_NORETURN;
#define KEY_WHEELUP KEY_F(20)
#define KEY_WHEELDOWN KEY_F(21)
#define KEY_RECLICK KEY_F(22)
#define KEY_WHEELUP KEY_F(30)
#define KEY_WHEELDOWN KEY_F(31)
#define KEY_RECLICK KEY_F(32)
#define KEY_ALT(x) (KEY_F(64 - 26) + ((x) - 'A'))
extern const char* CRT_degreeSign;

View File

@ -1,7 +1,7 @@
/*
htop - CategoriesPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - CategoriesPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,3 +1,36 @@
What's new in version 3.1.2
* Bugfix for crash when storing modified settings at exit
* Generate xz-compressed source tarball (with configure) using github actions
* Allow -u UID with numerical value as argument
* Added documentation for obsolete/state libraries/program files highlighting
* Some obsolete/stale library highlighting refinements
* Column width issues resolved
* Dynamic UID column sizing improved
* Discard stale information from Disk and Network I/O meters
* Refined Linux kernel thread detection
* Reworked process state handling
* New CCGROUP column showing abbreviated cgroup name
* New OFFSET column in the list of open files screen
What's new in version 3.1.1
* Update license headers to explicitly say GPLv2+
* Document minimum version for libcap (thanks to James Brown)
* Fix mouse wheel collision with autogroups nice adjustment
* Adjust Makefile.am macro definitions for older automake versions
* Ensure consistent reporting of MemoryMeter 'used' memory
* Report hugepage memory as real and used memory (as before)
* Handle procExeDeleted, usesDeletedLib without mergedCommandline mode
* Validate meter configuration before proceeding beyond htoprc parsing
* Properly release memory on partially read configuration
* Handle interrupted sampling from within libpcp PDU transfers
* On Linux, provide O_PATH value if not defined
* On Linux, always compute procExeDeleted if already set
* Workaround for Rosetta 2 on Darwin (thanks to Alexander Momchilov)
* Fix FreeBSD cmdline memory leak in Process_updateCmdline, and
* Plug a Disk I/O meter memory leak on FreeBSD (thanks to Ximalas)
What's new in version 3.1.0
* Updated COPYING file to remove the PLPA exemption (appendix 2)

View File

@ -1,7 +1,7 @@
/*
htop - ClockMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - ClockMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - ColorsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -52,7 +52,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
HandlerResult result = IGNORED;
int mark;
switch(ch) {
switch (ch) {
case 0x0a:
case 0x0d:
case KEY_ENTER:

View File

@ -3,7 +3,7 @@
/*
htop - ColorsPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - ColumnsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - ColumnsPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -2,7 +2,7 @@
htop - CommandLine.c
(C) 2004-2011 Hisham H. Muhammad
(C) 2020-2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -11,6 +11,7 @@ in the source distribution for its full text.
#include "CommandLine.h"
#include <assert.h>
#include <ctype.h>
#include <getopt.h>
#include <locale.h>
#include <stdbool.h>
@ -47,7 +48,7 @@ static void printVersionFlag(const char* name) {
static void printHelpFlag(const char* name) {
printf("%s " VERSION "\n"
COPYRIGHT "\n"
"Released under the GNU GPLv2.\n\n"
"Released under the GNU GPLv2+.\n\n"
"-C --no-color Use a monochrome color scheme\n"
"-d --delay=DELAY Set the delay between updates, in tenths of seconds\n"
"-F --filter=FILTER Show only the commands matching the given filter\n"
@ -85,9 +86,9 @@ typedef struct CommandLineSettings_ {
bool readonly;
} CommandLineSettings;
static CommandLineSettings parseArguments(const char* program, int argc, char** argv) {
static CommandLineStatus parseArguments(const char* program, int argc, char** argv, CommandLineSettings* flags) {
CommandLineSettings flags = {
*flags = (CommandLineSettings) {
.pidMatchList = NULL,
.commFilter = NULL,
.userId = (uid_t)-1, // -1 is guaranteed to be an invalid uid_t (see setreuid(2))
@ -130,10 +131,10 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
switch (opt) {
case 'h':
printHelpFlag(program);
exit(0);
return STATUS_OK_EXIT;
case 'V':
printVersionFlag(program);
exit(0);
return STATUS_OK_EXIT;
case 's':
assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */
if (String_eq(optarg, "help")) {
@ -142,29 +143,29 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
const char* description = Process_fields[j].description;
if (name) printf("%19s %s\n", name, description);
}
exit(0);
return STATUS_OK_EXIT;
}
flags.sortKey = 0;
flags->sortKey = 0;
for (int j = 1; j < LAST_PROCESSFIELD; j++) {
if (Process_fields[j].name == NULL)
continue;
if (String_eq(optarg, Process_fields[j].name)) {
flags.sortKey = j;
flags->sortKey = j;
break;
}
}
if (flags.sortKey == 0) {
if (flags->sortKey == 0) {
fprintf(stderr, "Error: invalid column \"%s\".\n", optarg);
exit(1);
return STATUS_ERROR_EXIT;
}
break;
case 'd':
if (sscanf(optarg, "%16d", &(flags.delay)) == 1) {
if (flags.delay < 1) flags.delay = 1;
if (flags.delay > 100) flags.delay = 100;
if (sscanf(optarg, "%16d", &(flags->delay)) == 1) {
if (flags->delay < 1) flags->delay = 1;
if (flags->delay > 100) flags->delay = 100;
} else {
fprintf(stderr, "Error: invalid delay value \"%s\".\n", optarg);
exit(1);
return STATUS_ERROR_EXIT;
}
break;
case 'u':
@ -176,26 +177,30 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
}
if (!username) {
flags.userId = geteuid();
} else if (!Action_setUserOnly(username, &(flags.userId))) {
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
exit(1);
flags->userId = geteuid();
} else if (!Action_setUserOnly(username, &(flags->userId))) {
for (const char *itr = username; *itr; ++itr)
if (!isdigit((unsigned char)*itr)) {
fprintf(stderr, "Error: invalid user \"%s\".\n", username);
return STATUS_ERROR_EXIT;
}
flags->userId = atol(username);
}
break;
}
case 'C':
flags.useColors = false;
flags->useColors = false;
break;
case 'M':
#ifdef HAVE_GETMOUSE
flags.enableMouse = false;
flags->enableMouse = false;
#endif
break;
case 'U':
flags.allowUnicode = false;
flags->allowUnicode = false;
break;
case 't':
flags.treeView = true;
flags->treeView = true;
break;
case 'p': {
assert(optarg); /* please clang analyzer, cause optarg can be NULL in the 'u' case */
@ -203,14 +208,14 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
char* saveptr;
const char* pid = strtok_r(argCopy, ",", &saveptr);
if (!flags.pidMatchList) {
flags.pidMatchList = Hashtable_new(8, false);
if (!flags->pidMatchList) {
flags->pidMatchList = Hashtable_new(8, false);
}
while(pid) {
unsigned int num_pid = atoi(pid);
// deepcode ignore CastIntegerToAddress: we just want a non-NUll pointer here
Hashtable_put(flags.pidMatchList, num_pid, (void *) 1);
// deepcode ignore CastIntegerToAddress: we just want a non-NULL pointer here
Hashtable_put(flags->pidMatchList, num_pid, (void *) 1);
pid = strtok_r(NULL, ",", &saveptr);
}
free(argCopy);
@ -219,7 +224,7 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
}
case 'F': {
assert(optarg);
free_and_xStrdup(&flags.commFilter, optarg);
free_and_xStrdup(&flags->commFilter, optarg);
break;
}
case 'H': {
@ -229,28 +234,30 @@ static CommandLineSettings parseArguments(const char* program, int argc, char**
delay = argv[optind++];
}
if (delay) {
if (sscanf(delay, "%16d", &(flags.highlightDelaySecs)) == 1) {
if (flags.highlightDelaySecs < 1)
flags.highlightDelaySecs = 1;
if (sscanf(delay, "%16d", &(flags->highlightDelaySecs)) == 1) {
if (flags->highlightDelaySecs < 1)
flags->highlightDelaySecs = 1;
} else {
fprintf(stderr, "Error: invalid highlight delay value \"%s\".\n", delay);
exit(1);
return STATUS_ERROR_EXIT;
}
}
flags.highlightChanges = true;
flags->highlightChanges = true;
break;
}
case 128:
flags.readonly = true;
flags->readonly = true;
break;
default:
if (Platform_getLongOption(opt, argc, argv) == false)
exit(1);
break;
default: {
CommandLineStatus status;
if ((status = Platform_getLongOption(opt, argc, argv)) != STATUS_OK)
return status;
break;
}
}
}
return flags;
return STATUS_OK;
}
static void CommandLine_delay(ProcessList* pl, unsigned long millisec) {
@ -283,12 +290,17 @@ int CommandLine_run(const char* name, int argc, char** argv) {
else
setlocale(LC_CTYPE, "");
CommandLineSettings flags = parseArguments(name, argc, argv);
CommandLineStatus status = STATUS_OK;
CommandLineSettings flags = { 0 };
if ((status = parseArguments(name, argc, argv, &flags)) != STATUS_OK)
return status != STATUS_OK_EXIT ? 1 : 0;
if (flags.readonly)
Settings_enableReadonly();
Platform_init();
if (!Platform_init())
return 1;
Process_setupColumnWidths();

View File

@ -4,10 +4,15 @@
htop - CommandLine.h
(C) 2004-2011 Hisham H. Muhammad
(C) 2020-2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
typedef enum {
STATUS_OK,
STATUS_ERROR_EXIT,
STATUS_OK_EXIT
} CommandLineStatus;
int CommandLine_run(const char* name, int argc, char** argv);

View File

@ -1,7 +1,7 @@
/*
htop - Compat.c
(C) 2020 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -44,7 +44,7 @@ int Compat_faccessat(int dirfd,
// Fallback to stat(2)/lstat(2) depending on flags
struct stat statinfo;
if(flags) {
if (flags) {
ret = lstat(pathname, &statinfo);
} else {
ret = stat(pathname, &statinfo);

View File

@ -3,7 +3,7 @@
/*
htop - Compat.h
(C) 2020 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - DateMeter.c
(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer
Released under the GNU GPL, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - DateMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - DateTimeMeter.c
(C) 2004-2020 Hisham H. Muhammad, Michael Schönitzer
Released under the GNU GPL, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - DateTimeMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - DiskIOMeter.c
(C) 2020 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -81,6 +81,12 @@ static void DiskIOMeter_updateValues(Meter* this) {
cached_msTimeSpend_total = data.totalMsTimeSpend;
}
if (passedTimeInMs > 30000) {
// Triggers for the first initialization and
// when there was a long time we did not collect updates
hasData = false;
}
this->values[0] = cached_utilisation_diff;
this->total = MAXIMUM(this->values[0], 100.0); /* fix total after (initial) spike */

View File

@ -3,7 +3,7 @@
/*
htop - DiskIOMeter.h
(C) 2020 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - DisplayOptionsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -107,7 +107,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
Panel_add(super, (Object*) CheckItem_newByRef("Show custom thread names", &(settings->showThreadNames)));
Panel_add(super, (Object*) CheckItem_newByRef("Show program path", &(settings->showProgramPath)));
Panel_add(super, (Object*) CheckItem_newByRef("Highlight program \"basename\"", &(settings->highlightBaseName)));
Panel_add(super, (Object*) CheckItem_newByRef("Highlight out-dated/removed programs", &(settings->highlightDeletedExe)));
Panel_add(super, (Object*) CheckItem_newByRef("Highlight out-dated/removed programs (red) / libraries (yellow)", &(settings->highlightDeletedExe)));
Panel_add(super, (Object*) CheckItem_newByRef("Merge exe, comm and cmdline in Command", &(settings->showMergedCommand)));
Panel_add(super, (Object*) CheckItem_newByRef("- Try to find comm in cmdline (when Command is merged)", &(settings->findCommInCmdline)));
Panel_add(super, (Object*) CheckItem_newByRef("- Try to strip exe from cmdline (when Command is merged)", &(settings->stripExeFromCmdline)));

View File

@ -3,7 +3,7 @@
/*
htop - DisplayOptionsPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@ htop - DynamicColumn.c
(C) 2021 Sohaib Mohammed
(C) 2021 htop dev team
(C) 2021 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -2,7 +2,7 @@
htop - DynamicMeter.c
(C) 2021 htop dev team
(C) 2021 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - FunctionBar.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - FunctionBar.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - Hashtable.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - Hashtable.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - Header.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -145,7 +145,7 @@ void Header_writeBackToSettings(const Header* this) {
const Vector* vec = this->columns[col];
int len = Vector_size(vec);
colSettings->names = len ? xCalloc(len, sizeof(char*)) : NULL;
colSettings->names = len ? xCalloc(len + 1, sizeof(char*)) : NULL;
colSettings->modes = len ? xCalloc(len, sizeof(int)) : NULL;
colSettings->len = len;

View File

@ -3,7 +3,7 @@
/*
htop - Header.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - HeaderLayout.h
(C) 2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - HeaderOptionsPanel.c
(C) 2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -35,7 +35,7 @@ static HandlerResult HeaderOptionsPanel_eventHandler(Panel* super, int ch) {
HandlerResult result = IGNORED;
int mark;
switch(ch) {
switch (ch) {
case 0x0a:
case 0x0d:
case KEY_ENTER:

View File

@ -3,7 +3,7 @@
/*
htop - ColorsPanel.h
(C) 2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - HostnameMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - HostnameMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - IncSet.c
(C) 2005-2012 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -156,7 +156,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
doSearch = false;
} else if (0 < ch && ch < 255 && isprint((unsigned char)ch)) {
if (mode->index < INCMODE_MAX) {
mode->buffer[mode->index] = ch;
mode->buffer[mode->index] = (char) ch;
mode->index++;
mode->buffer[mode->index] = 0;
if (mode->isFilter) {

View File

@ -3,7 +3,7 @@
/*
htop - IncSet.h
(C) 2005-2012 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -135,7 +135,7 @@ void InfoScreen_run(InfoScreen* this) {
continue;
}
switch(ch) {
switch (ch) {
case ERR:
continue;
case KEY_F(3):

View File

@ -1,7 +1,7 @@
/*
htop - ListItem.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - ListItem.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - LoadAverageMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - LoadAverageMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -2,7 +2,7 @@
htop - ColumnsPanel.c
(C) 2004-2015 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -61,8 +61,14 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
if (ch == KEY_RESIZE)
return IGNORED;
/* reset on every normal key, except mouse events while mouse support is disabled */
if (ch != ERR && (ch != KEY_MOUSE || this->state->settings->enableMouse))
/* reset on every normal key */
bool needReset = ch != ERR;
#ifdef HAVE_GETMOUSE
/* except mouse events while mouse support is disabled */
if (!(ch != KEY_MOUSE || this->state->settings->enableMouse))
needReset = false;
#endif
if (needReset)
this->state->hideProcessSelection = false;
if (EVENT_IS_HEADER_CLICK(ch)) {

View File

@ -4,7 +4,7 @@
htop - ColumnsPanel.h
(C) 2004-2015 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,3 +1,11 @@
if !HTOP_PCP
bin_PROGRAMS = htop
myhtopplatprogram = htop.c
else
bin_PROGRAMS = pcp-htop
myhtopplatprogram = pcp-htop.c
endif
dist_man_MANS = htop.1
EXTRA_DIST = \
$(dist_man_MANS) \
@ -145,6 +153,7 @@ linux_platform_headers = \
generic/gettime.h \
generic/hostname.h \
generic/uname.h \
linux/CGroupUtils.h \
linux/HugePageMeter.h \
linux/IOPriority.h \
linux/IOPriorityPanel.h \
@ -166,6 +175,7 @@ linux_platform_sources = \
generic/gettime.c \
generic/hostname.c \
generic/uname.c \
linux/CGroupUtils.c \
linux/HugePageMeter.c \
linux/IOPriorityPanel.c \
linux/LibSensors.c \
@ -181,7 +191,6 @@ linux_platform_sources = \
if HTOP_LINUX
AM_LDFLAGS += -rdynamic
myhtopplatprogram = htop
myhtopplatheaders = $(linux_platform_headers)
myhtopplatsources = $(linux_platform_sources)
endif
@ -214,7 +223,6 @@ freebsd_platform_sources = \
zfs/ZfsCompressedArcMeter.c
if HTOP_FREEBSD
myhtopplatprogram = htop
myhtopplatheaders = $(freebsd_platform_headers)
myhtopplatsources = $(freebsd_platform_sources)
endif
@ -240,7 +248,6 @@ dragonflybsd_platform_sources = \
generic/uname.c
if HTOP_DRAGONFLYBSD
myhtopplatprogram = htop
myhtopplatheaders = $(dragonflybsd_platform_headers)
myhtopplatsources = $(dragonflybsd_platform_sources)
endif
@ -266,7 +273,6 @@ netbsd_platform_sources = \
netbsd/NetBSDProcessList.c
if HTOP_NETBSD
myhtopplatprogram = htop
myhtopplatheaders = $(netbsd_platform_headers)
myhtopplatsources = $(netbsd_platform_sources)
endif
@ -292,7 +298,6 @@ openbsd_platform_sources = \
openbsd/Platform.c
if HTOP_OPENBSD
myhtopplatprogram = htop
myhtopplatheaders = $(openbsd_platform_headers)
myhtopplatsources = $(openbsd_platform_sources)
endif
@ -304,6 +309,7 @@ darwin_platform_headers = \
darwin/DarwinProcess.h \
darwin/DarwinProcessList.h \
darwin/Platform.h \
darwin/PlatformHelpers.h \
darwin/ProcessField.h \
generic/gettime.h \
generic/hostname.h \
@ -315,6 +321,7 @@ darwin_platform_headers = \
darwin_platform_sources = \
darwin/Platform.c \
darwin/PlatformHelpers.c \
darwin/DarwinProcess.c \
darwin/DarwinProcessList.c \
generic/gettime.c \
@ -326,7 +333,6 @@ darwin_platform_sources = \
if HTOP_DARWIN
AM_LDFLAGS += -framework IOKit -framework CoreFoundation
myhtopplatprogram = htop
myhtopplatheaders = $(darwin_platform_headers)
myhtopplatsources = $(darwin_platform_sources)
endif
@ -357,7 +363,6 @@ solaris_platform_sources = \
zfs/ZfsCompressedArcMeter.c
if HTOP_SOLARIS
myhtopplatprogram = htop
myhtopplatheaders = $(solaris_platform_headers)
myhtopplatsources = $(solaris_platform_sources)
endif
@ -393,10 +398,9 @@ pcp_platform_sources = \
zfs/ZfsCompressedArcMeter.c
if HTOP_PCP
myhtopplatprogram = pcp-htop
myhtopplatheaders = $(pcp_platform_headers)
myhtopplatsources = $(pcp_platform_sources)
pcp_htop_SOURCES = $(myhtopplatprogram).c $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
pcp_htop_SOURCES = $(myhtopplatprogram) $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
endif
# Unsupported
@ -416,15 +420,13 @@ unsupported_platform_sources = \
unsupported/UnsupportedProcessList.c
if HTOP_UNSUPPORTED
myhtopplatprogram = htop
myhtopplatsources = $(unsupported_platform_sources)
myhtopplatheaders = $(unsupported_platform_headers)
endif
# ----
bin_PROGRAMS = $(myhtopplatprogram)
htop_SOURCES = $(myhtopplatprogram).c $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
htop_SOURCES = $(myhtopplatprogram) $(myhtopheaders) $(myhtopplatheaders) $(myhtopsources) $(myhtopplatsources)
nodist_htop_SOURCES = config.h
target:

View File

@ -1,7 +1,7 @@
/*
htop - MemoryMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -36,7 +36,7 @@ static void MemoryMeter_updateValues(Meter* this) {
/* Do not print available memory in bar mode */
this->curItems = 4;
written = Meter_humanUnit(buffer, isnan(this->values[4]) ? this->values[0] : this->total - this->values[4], size);
written = Meter_humanUnit(buffer, this->values[0], size);
METER_BUFFER_CHECK(buffer, size, written);
METER_BUFFER_APPEND_CHR(buffer, size, '/');

View File

@ -3,7 +3,7 @@
/*
htop - MemoryMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - MemorySwapMeter.c
(C) 2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - MemorySwapMeter.h
(C) 2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - Meter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - Meter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - MetersPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - MetersPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -85,6 +85,12 @@ static void NetworkIOMeter_updateValues(Meter* this) {
cached_txp_total = data.packetsTransmitted;
}
if (passedTimeInMs > 30000) {
// Triggers for the first initialization and
// when there was a long time we did not collect updates
hasData = false;
}
this->values[0] = cached_rxb_diff;
this->values[1] = cached_txb_diff;
if (cached_rxb_diff + cached_txb_diff > this->total) {

View File

@ -2,7 +2,7 @@
htop - Object.c
(C) 2004-2012 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -4,7 +4,7 @@
htop - Object.h
(C) 2004-2012 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - OpenFilesScreen.c
(C) 2005-2006 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -10,12 +10,14 @@ in the source distribution for its full text.
#include "OpenFilesScreen.h"
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include "Macros.h"
#include "Panel.h"
@ -25,7 +27,7 @@ in the source distribution for its full text.
typedef struct OpenFiles_Data_ {
char* data[7];
char* data[8];
} OpenFiles_Data;
typedef struct OpenFiles_ProcessData_ {
@ -55,6 +57,8 @@ static size_t getIndexForType(char type) {
return 5;
case 't':
return 6;
case 'o':
return 7;
}
/* should never reach here */
@ -74,7 +78,7 @@ OpenFilesScreen* OpenFilesScreen_new(const Process* process) {
} else {
this->pid = process->pid;
}
return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 2, " FD TYPE MODE DEVICE SIZE NODE NAME");
return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 2, " FD TYPE MODE DEVICE SIZE OFFSET NODE NAME");
}
void OpenFilesScreen_delete(Object* this) {
@ -115,13 +119,14 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
close(fdnull);
char buffer[32] = {0};
xSnprintf(buffer, sizeof(buffer), "%d", pid);
execlp("lsof", "lsof", "-P", "-p", buffer, "-F", NULL);
execlp("lsof", "lsof", "-P", "-o", "-p", buffer, "-F", NULL);
exit(127);
}
close(fdpair[1]);
OpenFiles_Data* item = &(pdata->data);
OpenFiles_FileData* fdata = NULL;
bool lsofIncludesFileSize = false;
FILE* fd = fdopen(fdpair[0], "r");
if (!fd) {
@ -155,8 +160,17 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
case 't': /* file's type */
{
size_t index = getIndexForType(cmd);
free(item->data[index]);
item->data[index] = xStrdup(line + 1);
free_and_xStrdup(&item->data[index], line + 1);
break;
}
case 'o': /* file's offset */
{
size_t index = getIndexForType(cmd);
if (String_startsWith(line + 1, "0t")) {
free_and_xStrdup(&item->data[index], line + 3);
} else {
free_and_xStrdup(&item->data[index], line + 1);
}
break;
}
case 'c': /* process command name */
@ -166,7 +180,6 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
case 'k': /* link count */
case 'l': /* file's lock status */
case 'L': /* process login name */
case 'o': /* file's offset */
case 'p': /* process ID */
case 'P': /* protocol name */
case 'R': /* parent process ID */
@ -175,6 +188,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
/* ignore */
break;
}
if (cmd == 's')
lsofIncludesFileSize = true;
free(line);
}
fclose(fd);
@ -191,6 +208,25 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) {
pdata->error = WEXITSTATUS(wstatus);
}
/* We got all information we need; no post-processing needed */
if (lsofIncludesFileSize)
return pdata;
/* On linux, `lsof -o -F` omits SIZE, so add it back. */
/* On macOS, `lsof -o -F` includes SIZE, so this block isn't needed. If no open files have a filesize, this will still run, unfortunately. */
size_t fileSizeIndex = getIndexForType('s');
for (fdata = pdata->files; fdata != NULL; fdata = fdata->next) {
item = &fdata->data;
const char* filename = getDataForType(item, 'n');
struct stat st;
if (stat(filename, &st) == 0) {
char fileSizeBuf[21]; /* 20 (long long) + 1 (NULL) */
xSnprintf(fileSizeBuf, sizeof(fileSizeBuf), "%"PRIu64, st.st_size); /* st.st_size is long long on macOS, long on linux */
free_and_xStrdup(&item->data[fileSizeIndex], fileSizeBuf);
}
}
return pdata;
}
@ -213,14 +249,15 @@ static void OpenFilesScreen_scan(InfoScreen* this) {
while (fdata) {
OpenFiles_Data* data = &fdata->data;
size_t lenN = strlen(getDataForType(data, 'n'));
size_t sizeEntry = 5 + 7 + 4 + 10 + 10 + 10 + lenN + 7 /*spaces*/ + 1 /*null*/;
size_t sizeEntry = 5 + 7 + 4 + 10 + 10 + 10 + 10 + lenN + 8 /*spaces*/ + 1 /*null*/;
char entry[sizeEntry];
xSnprintf(entry, sizeof(entry), "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %s",
xSnprintf(entry, sizeof(entry), "%5.5s %-7.7s %-4.4s %-10.10s %10.10s %10.10s %10.10s %s",
getDataForType(data, 'f'),
getDataForType(data, 't'),
getDataForType(data, 'a'),
getDataForType(data, 'D'),
getDataForType(data, 's'),
getDataForType(data, 'o'),
getDataForType(data, 'i'),
getDataForType(data, 'n'));
InfoScreen_addLine(this, entry);

View File

@ -3,7 +3,7 @@
/*
htop - OpenFilesScreen.h
(C) 2005-2006 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - OptionItem.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - OptionItem.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - Panel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -453,7 +453,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
}
if (len < 99) {
buffer[len] = ch;
buffer[len] = (char) ch;
buffer[len + 1] = '\0';
}
@ -470,7 +470,7 @@ HandlerResult Panel_selectByTyping(Panel* this, int ch) {
// if current word did not match,
// retry considering the character the start of a new word.
buffer[0] = ch;
buffer[0] = (char) ch;
buffer[1] = '\0';
}

View File

@ -3,7 +3,7 @@
/*
htop - Panel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -67,7 +67,7 @@ struct Panel_ {
int selectedLen;
void* eventHandlerState;
int scrollV;
short scrollH;
int scrollH;
bool needsRedraw;
bool wasFocus;
FunctionBar* currentBar;

124
Process.c
View File

@ -2,7 +2,7 @@
htop - Process.c
(C) 2004-2015 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -41,17 +41,33 @@ static const char* const kthreadID = "KTHREAD";
static uid_t Process_getuid = (uid_t)-1;
int Process_pidDigits = 7;
int Process_pidDigits = PROCESS_MIN_PID_DIGITS;
int Process_uidDigits = PROCESS_MIN_UID_DIGITS;
void Process_setupColumnWidths() {
int maxPid = Platform_getMaxPid();
if (maxPid == -1)
return;
if (maxPid < (int)pow(10, PROCESS_MIN_PID_DIGITS)) {
Process_pidDigits = PROCESS_MIN_PID_DIGITS;
return;
}
Process_pidDigits = ceil(log10(maxPid));
assert(Process_pidDigits <= PROCESS_MAX_PID_DIGITS);
}
void Process_setUidColumnWidth(uid_t maxUid) {
if (maxUid < (uid_t)pow(10, PROCESS_MIN_UID_DIGITS)) {
Process_uidDigits = PROCESS_MIN_UID_DIGITS;
return;
}
Process_uidDigits = ceil(log10(maxUid));
assert(Process_uidDigits <= PROCESS_MAX_UID_DIGITS);
}
void Process_printBytes(RichString* str, unsigned long long number, bool coloring) {
char buffer[16];
int len;
@ -399,7 +415,7 @@ void Process_makeCommandStr(Process* this) {
* - a user thread and showThreadNames is not set */
if (Process_isKernelThread(this))
return;
if (this->state == 'Z' && !this->mergedCommand.str)
if (this->state == ZOMBIE && !this->mergedCommand.str)
return;
if (Process_isUserlandThread(this) && settings->showThreadNames && (showThreadNames == mc->prevShowThreadNames))
return;
@ -511,6 +527,12 @@ void Process_makeCommandStr(Process* this) {
if (cmdlineBasenameEnd > cmdlineBasenameStart)
WRITE_HIGHLIGHT(showProgramPath ? cmdlineBasenameStart : 0, cmdlineBasenameEnd - cmdlineBasenameStart, baseAttr, CMDLINE_HIGHLIGHT_FLAG_BASENAME);
if (this->procExeDeleted)
WRITE_HIGHLIGHT(showProgramPath ? cmdlineBasenameStart : 0, cmdlineBasenameEnd - cmdlineBasenameStart, delExeAttr, CMDLINE_HIGHLIGHT_FLAG_DELETED);
else if (this->usesDeletedLib)
WRITE_HIGHLIGHT(showProgramPath ? cmdlineBasenameStart : 0, cmdlineBasenameEnd - cmdlineBasenameStart, delLibAttr, CMDLINE_HIGHLIGHT_FLAG_DELETED);
(void)stpcpyWithNewlineConversion(str, cmdline + (showProgramPath ? 0 : cmdlineBasenameStart));
return;
@ -727,6 +749,28 @@ void Process_printPercentage(float val, char* buffer, int n, int* attr) {
}
}
static inline char processStateChar(ProcessState state) {
switch (state) {
case UNKNOWN: return '?';
case RUNNABLE: return 'U';
case RUNNING: return 'R';
case QUEUED: return 'Q';
case WAITING: return 'W';
case UNINTERRUPTIBLE_WAIT: return 'D';
case BLOCKED: return 'B';
case PAGING: return 'P';
case STOPPED: return 'T';
case TRACED: return 't';
case ZOMBIE: return 'Z';
case DEFUNCT: return 'X';
case IDLE: return 'I';
case SLEEPING: return 'S';
default:
assert(0);
return '!';
}
}
void Process_writeField(const Process* this, RichString* str, ProcessField field) {
char buffer[256];
size_t n = sizeof(buffer);
@ -861,25 +905,35 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
case SESSION: xSnprintf(buffer, n, "%*d ", Process_pidDigits, this->session); break;
case STARTTIME: xSnprintf(buffer, n, "%s", this->starttime_show); break;
case STATE:
xSnprintf(buffer, n, "%c ", this->state);
xSnprintf(buffer, n, "%c ", processStateChar(this->state));
switch (this->state) {
#ifdef HTOP_NETBSD
case 'P':
#else
case 'R':
#endif
case RUNNABLE:
case RUNNING:
case TRACED:
attr = CRT_colors[PROCESS_RUN_STATE];
break;
case 'D':
case BLOCKED:
case DEFUNCT:
case STOPPED:
case ZOMBIE:
attr = CRT_colors[PROCESS_D_STATE];
break;
case 'I':
case 'S':
case QUEUED:
case WAITING:
case UNINTERRUPTIBLE_WAIT:
case IDLE:
case SLEEPING:
attr = CRT_colors[PROCESS_SHADOW];
break;
case UNKNOWN:
case PAGING:
break;
}
break;
case ST_UID: xSnprintf(buffer, n, "%5d ", this->st_uid); break;
case ST_UID: xSnprintf(buffer, n, "%*d ", Process_uidDigits, this->st_uid); break;
case TIME: Process_printTime(str, this->time, coloring); return;
case TGID:
if (this->tgid == this->pid)
@ -902,11 +956,11 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
attr = CRT_colors[PROCESS_SHADOW];
if (this->user) {
Process_printLeftAlignedField(str, attr, this->user, 9);
Process_printLeftAlignedField(str, attr, this->user, 10);
return;
}
xSnprintf(buffer, n, "%-9d ", this->st_uid);
xSnprintf(buffer, n, "%-10d ", this->st_uid);
break;
default:
if (DynamicColumn_writeField(this, str, field))
@ -1050,44 +1104,6 @@ int Process_compare(const void* v1, const void* v2) {
return (Settings_getActiveDirection(settings) == 1) ? result : -result;
}
static uint8_t stateCompareValue(char state) {
switch (state) {
case 'S':
return 10;
case 'I':
return 9;
case 'X':
return 8;
case 'Z':
return 7;
case 't':
return 6;
case 'T':
return 5;
case 'L':
return 4;
case 'D':
return 3;
case 'R':
return 2;
case '?':
return 1;
default:
return 0;
}
}
int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField key) {
int r;
@ -1142,7 +1158,7 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField
r = SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime);
return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid);
case STATE:
return SPACESHIP_NUMBER(stateCompareValue(p1->state), stateCompareValue(p2->state));
return SPACESHIP_NUMBER(p1->state, p2->state);
case ST_UID:
return SPACESHIP_NUMBER(p1->st_uid, p2->st_uid);
case TIME:

View File

@ -4,7 +4,7 @@
htop - Process.h
(C) 2004-2015 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -60,6 +60,26 @@ typedef enum ProcessField_ {
LAST_PROCESSFIELD
} ProcessField;
/* Core process states (shared by platforms)
* NOTE: The enum has an ordering that is important!
* See processStateChar in process.c for ProcessSate -> letter mapping */
typedef enum ProcessState_ {
UNKNOWN = 1,
RUNNABLE,
RUNNING,
QUEUED,
WAITING,
UNINTERRUPTIBLE_WAIT,
BLOCKED,
PAGING,
STOPPED,
TRACED,
ZOMBIE,
DEFUNCT,
IDLE,
SLEEPING
} ProcessState;
struct Settings_;
/* Holds information about regions of the cmdline that should be
@ -202,20 +222,8 @@ typedef struct Process_ {
/* Number of major faults the process has made which have required loading a memory page from disk */
unsigned long int majflt;
/*
* Process state (platform dependent):
* D - Waiting
* I - Idle
* L - Acquiring lock
* R - Running
* S - Sleeping
* T - Stopped (on a signal)
* X - Dead
* Z - Zombie
* t - Tracing stop
* ? - Unknown
*/
char state;
/* Process state enum field (platform dependent) */
ProcessState state;
/* Whether the process was updated during the current scan */
bool updated;
@ -278,8 +286,12 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
int Process_compare(const void* v1, const void* v2);
void Process_delete(Object* cast);
extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD];
#define PROCESS_MIN_PID_DIGITS 5
#define PROCESS_MAX_PID_DIGITS 19
#define PROCESS_MIN_UID_DIGITS 5
#define PROCESS_MAX_UID_DIGITS 19
extern int Process_pidDigits;
extern int Process_uidDigits;
typedef Process* (*Process_New)(const struct Settings_*);
typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField);
@ -337,6 +349,9 @@ static inline bool Process_isThread(const Process* this) {
void Process_setupColumnWidths(void);
/* Sets the size of the UID column based on the passed UID */
void Process_setUidColumnWidth(uid_t maxUid);
/* Takes number in bytes (base 1024). Prints 6 columns. */
void Process_printBytes(RichString* str, unsigned long long number, bool coloring);

View File

@ -1,7 +1,7 @@
/*
htop - ProcessList.c
(C) 2004,2005 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -105,13 +105,19 @@ static const char* alignedProcessFieldTitle(const ProcessList* this, ProcessFiel
if (!title)
return "- ";
if (!Process_fields[field].pidColumn)
return title;
if (Process_fields[field].pidColumn) {
static char titleBuffer[PROCESS_MAX_PID_DIGITS + sizeof(" ")];
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_pidDigits, title);
return titleBuffer;
}
static char titleBuffer[PROCESS_MAX_PID_DIGITS + /* space */ 1 + /* null-terminator */ + 1];
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_pidDigits, title);
if (field == ST_UID) {
static char titleBuffer[PROCESS_MAX_UID_DIGITS + sizeof(" ")];
xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s ", Process_uidDigits, title);
return titleBuffer;
}
return titleBuffer;
return title;
}
void ProcessList_printHeader(const ProcessList* this, RichString* header) {
@ -626,10 +632,15 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
ProcessList_goThroughEntries(this, false);
uid_t maxUid = 0;
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->processes, i);
Process_makeCommandStr(p);
// keep track of the highest UID for column scaling
if (p->st_uid > maxUid)
maxUid = p->st_uid;
if (p->tombStampMs > 0) {
// remove tombed process
if (this->monotonicMs >= p->tombStampMs) {
@ -647,6 +658,9 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
}
}
// Set UID column width based on max UID.
Process_setUidColumnWidth(maxUid);
if (this->settings->treeView) {
// Clear out the hashtable to avoid any left-over processes from previous build
//

View File

@ -3,7 +3,7 @@
/*
htop - ProcessList.h
(C) 2004,2005 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - ProcessLocksScreen.c
(C) 2020 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - ProcessLocksScreen.h
(C) 2020 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - RichString.h
(C) 2004,2011 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

6
README
View File

@ -6,7 +6,7 @@
[![IRC #htop](https://img.shields.io/badge/IRC-htop-blue.svg)](https://web.libera.chat/#htop)
[![GitHub Release](https://img.shields.io/github/release/htop-dev/htop.svg)](https://github.com/htop-dev/htop/releases/latest)
[![Packaging status](https://repology.org/badge/tiny-repos/htop.svg)](https://repology.org/project/htop/versions)
[![License: GPL v2](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](COPYING?raw=true)
[![License: GPL v2+](https://img.shields.io/badge/License-GPL%20v2+-blue.svg)](COPYING?raw=true)
![Screenshot of htop](docs/images/screenshot.png?raw=true)
@ -47,7 +47,7 @@ List of build-time dependencies:
List of additional build-time dependencies (based on feature flags):
* `sensors`
* `hwloc`
* `libcap`
* `libcap` (v2.21 or later)
* `libnl-3`
Install these and other required packages for C development from your package manager.
@ -174,4 +174,4 @@ In 2020 a [team](https://github.com/orgs/htop-dev/people) took over the developm
## License
GNU General Public License, version 2 (GPL-2.0)
GNU General Public License, version 2 (GPL-2.0) or, at your option, any later version.

View File

@ -1,7 +1,7 @@
/*
htop - RichString.c
(C) 2004,2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - RichString.h
(C) 2004,2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - ScreenManager.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -88,7 +88,7 @@ void ScreenManager_resize(ScreenManager* this) {
Panel_move(panel, lastX, y1_header);
}
static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) {
static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut, bool *force_redraw) {
ProcessList* pl = this->header->pl;
Platform_gettime_realtime(&pl->realtime, &pl->realtimeMs);
@ -103,6 +103,7 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
if (*rescan) {
*oldTime = newTime;
int oldUidDigits = Process_uidDigits;
// scan processes first - some header values are calculated there
ProcessList_scan(pl, this->state->pauseProcessUpdate);
// always update header, especially to avoid gaps in graph meters
@ -111,6 +112,10 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
ProcessList_sort(pl);
*sortTimeout = 1;
}
// force redraw if the number of UID digits was changed
if (Process_uidDigits != oldUidDigits) {
*force_redraw = true;
}
*redraw = true;
}
if (*redraw) {
@ -153,7 +158,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
while (!quit) {
if (this->header) {
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut, &force_redraw);
}
if (redraw || force_redraw) {

View File

@ -3,7 +3,7 @@
/*
htop - ScreenManager.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - Settings.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -28,11 +28,7 @@ void Settings_delete(Settings* this) {
free(this->filename);
free(this->fields);
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
if (this->hColumns[i].names) {
for (uint8_t j = 0; j < this->hColumns[i].len; j++)
free(this->hColumns[i].names[j]);
free(this->hColumns[i].names);
}
String_freeArray(this->hColumns[i].names);
free(this->hColumns[i].modes);
}
free(this->hColumns);
@ -65,16 +61,51 @@ static void Settings_readMeterModes(Settings* this, const char* line, unsigned i
this->hColumns[column].modes = modes;
}
static bool Settings_validateMeters(Settings* this) {
const size_t colCount = HeaderLayout_getColumns(this->hLayout);
for (size_t column = 0; column < colCount; column++) {
char** names = this->hColumns[column].names;
const int* modes = this->hColumns[column].modes;
const size_t len = this->hColumns[column].len;
if (!names || !modes || !len)
return false;
// Check for each mode there is an entry with a non-NULL name
for (size_t meterIdx = 0; meterIdx < len; meterIdx++)
if (!names[meterIdx])
return false;
if (names[len])
return false;
}
return true;
}
static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) {
int sizes[] = { 3, 3 };
if (initialCpuCount > 4 && initialCpuCount <= 128) {
sizes[1]++;
}
for (int i = 0; i < 2; i++) {
// Release any previously allocated memory
for (size_t i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
String_freeArray(this->hColumns[i].names);
free(this->hColumns[i].modes);
}
free(this->hColumns);
this->hLayout = HF_TWO_50_50;
this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
for (size_t i = 0; i < 2; i++) {
this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char*));
this->hColumns[i].modes = xCalloc(sizes[i], sizeof(int));
this->hColumns[i].len = sizes[i];
}
int r = 0;
if (initialCpuCount > 128) {
@ -181,8 +212,9 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
this->config_version = atoi(option[1]);
if (this->config_version > CONFIG_READER_MIN_VERSION) {
// the version of the config file on disk is newer than what we can read
fprintf(stderr, "WARNING: %s specifies configuration format version v%d, but this %s binary supports up to v%d\n.", fileName, this->config_version, PACKAGE, CONFIG_READER_MIN_VERSION);
fprintf(stderr, " The configuration version will be downgraded to v%d when %s exits.\n", CONFIG_READER_MIN_VERSION, PACKAGE);
fprintf(stderr, "WARNING: %s specifies configuration format\n", fileName);
fprintf(stderr, " version v%d, but this %s binary only supports up to version v%d.\n", this->config_version, PACKAGE, CONFIG_READER_MIN_VERSION);
fprintf(stderr, " The configuration file will be downgraded to v%d when %s exits.\n", CONFIG_READER_MIN_VERSION, PACKAGE);
String_freeArray(option);
fclose(fd);
return false;
@ -304,7 +336,7 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
String_freeArray(option);
}
fclose(fd);
if (!didReadMeters) {
if (!didReadMeters || !Settings_validateMeters(this)) {
Settings_defaultMeters(this, initialCpuCount);
}
return didReadAny;
@ -328,7 +360,7 @@ static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns
static void writeMeters(const Settings* this, FILE* fd, char separator, unsigned int column) {
const char* sep = "";
for (uint8_t i = 0; i < this->hColumns[column].len; i++) {
for (size_t i = 0; i < this->hColumns[column].len; i++) {
fprintf(fd, "%s%s", sep, this->hColumns[column].names[i]);
sep = " ";
}
@ -337,7 +369,7 @@ static void writeMeters(const Settings* this, FILE* fd, char separator, unsigned
static void writeMeterModes(const Settings* this, FILE* fd, char separator, unsigned int column) {
const char* sep = "";
for (uint8_t i = 0; i < this->hColumns[column].len; i++) {
for (size_t i = 0; i < this->hColumns[column].len; i++) {
fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]);
sep = " ";
}
@ -586,7 +618,7 @@ void Settings_setHeaderLayout(Settings* this, HeaderLayout hLayout) {
} else if (newColumns < oldColumns) {
for (unsigned int i = newColumns; i < oldColumns; i++) {
if (this->hColumns[i].names) {
for (uint8_t j = 0; j < this->hColumns[i].len; j++)
for (size_t j = 0; j < this->hColumns[i].len; j++)
free(this->hColumns[i].names[j]);
free(this->hColumns[i].names);
}

View File

@ -3,7 +3,7 @@
/*
htop - Settings.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@ -22,7 +22,7 @@ in the source distribution for its full text.
#define CONFIG_READER_MIN_VERSION 2
typedef struct {
uint8_t len;
size_t len;
char** names;
int* modes;
} MeterColumnSetting;

View File

@ -1,7 +1,7 @@
/*
htop - SignalsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - SignalsPanel.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - SwapMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - SwapMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -1,7 +1,7 @@
/*
htop - SysArchMeter.c
(C) 2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - SysArchMeter.h
(C) 2021 htop dev team
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
#include "Meter.h"

View File

@ -1,7 +1,7 @@
/*
htop - TasksMeter.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

View File

@ -3,7 +3,7 @@
/*
htop - TasksMeter.h
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

Some files were not shown because too many files have changed in this diff Show More