Skip to content

Commit b8d397f

Browse files
authored
Merge branch 'htop-dev:main' into main
2 parents 54a5354 + a90081c commit b8d397f

File tree

15 files changed

+298
-158
lines changed

15 files changed

+298
-158
lines changed

CPUMeter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,10 @@ static void CPUMeterCommonInit(Meter* this) {
241241

242242
CPUMeterData* data = this->meterData;
243243
if (!data) {
244-
data = this->meterData = xMalloc(sizeof(CPUMeterData));
244+
data = xCalloc(1, sizeof(CPUMeterData));
245245
data->cpus = this->host->existingCPUs;
246246
data->meters = count ? xCalloc(count, sizeof(Meter*)) : NULL;
247+
this->meterData = data;
247248
}
248249

249250
Meter** meters = data->meters;

CRT.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ in the source distribution for its full text.
2929
#include <sys/mman.h>
3030
#endif
3131

32-
#if defined(HAVE_LIBUNWIND) && defined(HAVE_LOCAL_UNWIND)
32+
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LOCAL_UNWIND)
3333
# define PRINT_BACKTRACE
3434
# define UNW_LOCAL_ONLY
3535
# include <libunwind.h>
@@ -1142,6 +1142,11 @@ static bool terminalSupportsDefinedKeys(const char* termType) {
11421142
return true;
11431143
}
11441144
break;
1145+
case 'f':
1146+
if (String_eq(termType, "foot")) {
1147+
return true;
1148+
}
1149+
break;
11451150
case 's':
11461151
if (termType[1] == 't' && IS_END_OR_DASH(termType[2])) {
11471152
return true;
@@ -1346,7 +1351,7 @@ void CRT_setColors(int colorScheme) {
13461351

13471352
#ifdef PRINT_BACKTRACE
13481353
static void print_backtrace(void) {
1349-
#if defined(HAVE_LIBUNWIND) && defined(HAVE_LOCAL_UNWIND)
1354+
#if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LOCAL_UNWIND)
13501355
unw_context_t context;
13511356
unw_getcontext(&context);
13521357

GPUMeter.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ static void GPUMeter_display(const Object* cast, RichString* out) {
103103
return;
104104
}
105105

106-
written = xSnprintf(buffer, sizeof(buffer), "%4.1f", totalUsage);
106+
written = xSnprintf(buffer, sizeof(buffer), "%5.1f%%", totalUsage);
107107
RichString_appendnAscii(out, CRT_colors[METER_VALUE], buffer, written);
108-
RichString_appendAscii(out, CRT_colors[METER_TEXT], "%");
109108
if (totalGPUTimeDiff != -1ULL) {
110109
RichString_appendAscii(out, CRT_colors[METER_TEXT], "(");
111110
written = humanTimeUnit(buffer, sizeof(buffer), totalGPUTimeDiff);
@@ -120,12 +119,12 @@ static void GPUMeter_display(const Object* cast, RichString* out) {
120119
RichString_appendAscii(out, CRT_colors[METER_TEXT], " ");
121120
RichString_appendAscii(out, CRT_colors[METER_TEXT], GPUMeter_engineData[i].key);
122121
RichString_appendAscii(out, CRT_colors[METER_TEXT], ":");
123-
if (isNonnegative(this->values[i]))
124-
written = xSnprintf(buffer, sizeof(buffer), "%4.1f", this->values[i]);
125-
else
126-
written = xSnprintf(buffer, sizeof(buffer), " N/A");
127-
RichString_appendnAscii(out, CRT_colors[METER_VALUE], buffer, written);
128-
RichString_appendAscii(out, CRT_colors[METER_TEXT], "%");
122+
if (isNonnegative(this->values[i])) {
123+
written = xSnprintf(buffer, sizeof(buffer), "%5.1f%%", this->values[i]);
124+
RichString_appendnAscii(out, CRT_colors[METER_VALUE], buffer, written);
125+
} else {
126+
RichString_appendAscii(out, CRT_colors[METER_VALUE], " N/A");
127+
}
129128
if (GPUMeter_engineData[i].timeDiff != -1ULL) {
130129
RichString_appendAscii(out, CRT_colors[METER_TEXT], "(");
131130
written = humanTimeUnit(buffer, sizeof(buffer), GPUMeter_engineData[i].timeDiff);

Machine.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ void Machine_populateTablesFromSettings(Machine* this, Settings* settings, Table
7979

8080
for (size_t i = 0; i < settings->nScreens; i++) {
8181
ScreenSettings* ss = settings->screens[i];
82+
83+
if (!ss->table)
84+
ss->table = processTable;
85+
8286
Table* table = ss->table;
83-
if (!table)
84-
table = ss->table = processTable;
8587
if (i == 0)
8688
this->activeTable = table;
8789

MemorySwapMeter.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ static void MemorySwapMeter_draw(Meter* this, int x, int y, int w) {
4747
}
4848

4949
static void MemorySwapMeter_init(Meter* this) {
50-
MemorySwapMeterData* data = this->meterData;
50+
if (!this->meterData)
51+
this->meterData = xCalloc(1, sizeof(MemorySwapMeterData));
5152

52-
if (!data) {
53-
data = this->meterData = xCalloc(1, sizeof(MemorySwapMeterData));
54-
}
53+
MemorySwapMeterData* data = this->meterData;
5554

5655
if (!data->memoryMeter)
5756
data->memoryMeter = Meter_new(this->host, 0, (const MeterClass*) Class(MemoryMeter));

configure.ac

Lines changed: 129 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ m4_version_prereq(
182182
[AC_HEADER_STDC]
183183
)
184184
AC_CHECK_HEADERS(
185-
[
186-
stdlib.h
187-
string.h
188-
strings.h
189-
sys/param.h
190-
sys/time.h
191-
sys/utsname.h
192-
unistd.h
185+
[ \
186+
stdlib.h \
187+
string.h \
188+
strings.h \
189+
sys/param.h \
190+
sys/time.h \
191+
sys/utsname.h \
192+
unistd.h \
193193
],
194194
[],
195195
[AC_MSG_ERROR([can not find required generic header files])]
@@ -402,18 +402,18 @@ fi
402402

403403
AC_SEARCH_LIBS([clock_gettime], [rt])
404404

405-
AC_CHECK_FUNCS([
406-
clock_gettime
407-
dladdr
408-
faccessat
409-
fstatat
410-
host_get_clock_service
411-
memfd_create
412-
openat
413-
readlinkat
414-
sched_getscheduler
415-
sched_setscheduler
416-
strnlen
405+
AC_CHECK_FUNCS([ \
406+
clock_gettime \
407+
dladdr \
408+
faccessat \
409+
fstatat \
410+
host_get_clock_service \
411+
memfd_create \
412+
openat \
413+
readlinkat \
414+
sched_getscheduler \
415+
sched_setscheduler \
416+
strnlen \
417417
])
418418

419419
# strchrnul is available in macOS since 15.4, but the user may specify an older
@@ -780,27 +780,58 @@ esac
780780
htop_save_CFLAGS=$CFLAGS
781781
CFLAGS="$AM_CFLAGS $CFLAGS"
782782

783+
have_curses_header=no
784+
have_term_header=no
785+
783786
if test "x$enable_unicode" = xyes; then
784-
AC_CHECK_HEADERS([ncursesw/curses.h], [],
785-
[AC_CHECK_HEADERS([ncurses/ncurses.h], [],
786-
[AC_CHECK_HEADERS([ncurses/curses.h], [],
787-
[AC_CHECK_HEADERS([ncurses.h], [],
788-
[AC_MSG_ERROR([can not find required ncurses header file])])])])])
789-
790-
AC_CHECK_HEADERS([ncursesw/term.h], [],
791-
[AC_CHECK_HEADERS([ncurses/term.h], [],
792-
[AC_CHECK_HEADERS([term.h], [],
793-
[AC_MSG_ERROR([can not find required term header file])])])])
787+
AC_CHECK_HEADERS(
788+
[ \
789+
ncursesw/curses.h \
790+
ncurses/ncurses.h \
791+
ncurses/curses.h \
792+
ncurses.h \
793+
], [
794+
have_curses_header=yes
795+
break
796+
]
797+
)
798+
AC_CHECK_HEADERS(
799+
[ \
800+
ncursesw/term.h \
801+
ncurses/term.h \
802+
term.h \
803+
], [
804+
have_term_header=yes
805+
break
806+
]
807+
)
794808
else
795-
AC_CHECK_HEADERS([curses.h], [],
796-
[AC_CHECK_HEADERS([ncurses/curses.h], [],
797-
[AC_CHECK_HEADERS([ncurses/ncurses.h], [],
798-
[AC_CHECK_HEADERS([ncurses.h], [],
799-
[AC_MSG_ERROR([can not find required ncurses header file])])])])])
800-
801-
AC_CHECK_HEADERS([ncurses/term.h], [],
802-
[AC_CHECK_HEADERS([term.h], [],
803-
[AC_MSG_ERROR([can not find required term header file])])])
809+
AC_CHECK_HEADERS(
810+
[ \
811+
curses.h \
812+
ncurses/curses.h \
813+
ncurses/ncurses.h \
814+
ncurses.h \
815+
], [
816+
have_curses_header=yes
817+
break
818+
]
819+
)
820+
AC_CHECK_HEADERS(
821+
[ \
822+
ncurses/term.h \
823+
term.h \
824+
], [
825+
have_term_header=yes
826+
break
827+
]
828+
)
829+
fi
830+
831+
if test "$have_curses_header" = no; then
832+
AC_MSG_ERROR([can not find required curses header file])
833+
elif test "$have_term_header" = no; then
834+
AC_MSG_ERROR([can not find required term header file])
804835
fi
805836

806837
CFLAGS="-I$srcdir $CFLAGS"
@@ -896,6 +927,25 @@ if test "x$enable_affinity" = xyes; then
896927
fi
897928

898929

930+
dnl HTOP_PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
931+
dnl This macro is a wrapper of PKG_CHECK_MODULES, which checks if
932+
dnl MODULES exist, and then sets VARIABLE-PREFIX_CFLAGS and
933+
dnl VARIABLE-PREFIX_LIBS from pkg-config --cflags and --libs output
934+
dnl respectively, and then runs ACTION-IF-FOUND. If pkg.m4 is absent or
935+
dnl pkg-config MODULES don't exist, this instead runs
936+
dnl ACTION-IF-NOT-FOUND. ACTION-IF-NOT-FOUND defaults to printing an
937+
dnl error message and exiting.
938+
AC_DEFUN([HTOP_PKG_CHECK_MODULES],
939+
[m4_ifdef(
940+
[PKG_PROG_PKG_CONFIG],
941+
[PKG_CHECK_MODULES([$1], [$2], [$3], [$4])],
942+
[m4_default(
943+
[$4],
944+
[AC_MSG_ERROR([pkg.m4 required to check for pkg-config modules '$2'; please regenerate configure script])]
945+
)]
946+
)]
947+
)
948+
899949
# $1: Header file name
900950
# $2: List of directories to search, separated by spaces
901951
# $3: Additional include directives
@@ -944,37 +994,49 @@ case "$enable_unwind" in
944994
no)
945995
;;
946996
check|yes)
947-
if test "$enable_static" = yes; then
948-
AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
949-
fi
950-
951-
AC_CHECK_LIB(
952-
[unwind],
953-
[unw_init_local],
997+
HTOP_PKG_CHECK_MODULES(LIBUNWIND, libunwind,
954998
[],
955999
[
956-
if test "$enable_unwind" = yes; then
957-
AC_MSG_ERROR([can not find required library libunwind])
1000+
if test "$enable_static" = yes; then
1001+
AC_CHECK_LIB([lzma], [lzma_index_buffer_decode])
9581002
fi
959-
enable_unwind=no
1003+
: "${LIBUNWIND_LIBS='-lunwind'}"
9601004
]
9611005
)
1006+
1007+
htop_save_CFLAGS=$CFLAGS
1008+
CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS $CFLAGS"
1009+
1010+
if htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
1011+
AC_DEFINE([HAVE_LIBUNWIND_H], 1, [Define to 1 if you have the <libunwind.h> header file.])
1012+
elif test "$enable_unwind" = yes; then
1013+
AC_MSG_ERROR([can not find required header file libunwind.h])
1014+
else
1015+
enable_unwind=no
1016+
fi
1017+
1018+
CFLAGS=$htop_save_CFLAGS
9621019
;;
9631020
*)
9641021
AC_MSG_ERROR([bad value '$enable_unwind' for --enable-unwind])
9651022
;;
9661023
esac
9671024

968-
if test "$enable_unwind" = no; then
969-
:
970-
elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
1025+
if test "$enable_unwind" != no; then
9711026
htop_save_CPPFLAGS=$CPPFLAGS
1027+
htop_save_CFLAGS=$CFLAGS
1028+
htop_save_LIBS=$LIBS
9721029
CPPFLAGS="$AM_CPPFLAGS $CPPFLAGS"
1030+
CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS $CFLAGS"
1031+
LIBS="$LIBUNWIND_LIBS $LIBS"
9731032

974-
AC_MSG_CHECKING([whether local unwinding works])
1033+
# unw_init_local() is a macro in HP's implemention of libunwind
1034+
# (the most popular one, Mosberger et al.)
1035+
AC_MSG_CHECKING([whether $LIBUNWIND_LIBS supports local unwinding])
9751036
AC_LINK_IFELSE(
9761037
[AC_LANG_PROGRAM(
9771038
[[
1039+
#define UNW_LOCAL_ONLY
9781040
#include <libunwind.h>
9791041
]], [[
9801042
/* If libunwind is built with remote unwinding only,
@@ -1013,24 +1075,28 @@ elif htop_search_header_dir libunwind.h "/usr/include/libunwind"; then
10131075
if test "$enable_unwind" = yes; then
10141076
AC_MSG_WARN([this build of libunwind might not support local unwinding])
10151077
else
1078+
LIBS=$htop_save_LIBS
10161079
enable_unwind=no
10171080
fi
10181081
fi
10191082
],
10201083
[
10211084
AC_MSG_RESULT([no])
1022-
AC_MSG_FAILURE([there are problems with libunwind.h])
1085+
if test "$enable_unwind" = yes; then
1086+
AC_MSG_FAILURE([can not link with libunwind])
1087+
else
1088+
LIBS=$htop_save_LIBS
1089+
enable_unwind=no
1090+
fi
10231091
]
10241092
)
10251093

10261094
CPPFLAGS=$htop_save_CPPFLAGS
1027-
elif test "$enable_unwind" = yes; then
1028-
AC_MSG_ERROR([can not find required header file libunwind.h])
1029-
else
1030-
enable_unwind=no
1095+
CFLAGS=$htop_save_CFLAGS
10311096
fi
10321097

10331098
if test "$enable_unwind" != no; then
1099+
AM_CFLAGS="$AM_CFLAGS $LIBUNWIND_CFLAGS"
10341100
enable_unwind=yes
10351101
AC_DEFINE([HAVE_LOCAL_UNWIND], 1, [Define to 1 if local unwinding is enabled.])
10361102
else
@@ -1113,17 +1179,11 @@ case "$enable_hwloc" in
11131179
no)
11141180
;;
11151181
yes)
1116-
m4_ifdef(
1117-
[PKG_PROG_PKG_CONFIG],
1182+
HTOP_PKG_CHECK_MODULES(HWLOC, hwloc,
11181183
[
1119-
PKG_CHECK_MODULES(HWLOC, hwloc, [
1120-
AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
1121-
LIBS="$LIBS $HWLOC_LIBS"
1122-
AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
1123-
], [
1124-
AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
1125-
AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
1126-
])
1184+
AM_CFLAGS="$AM_CFLAGS $HWLOC_CFLAGS"
1185+
LIBS="$LIBS $HWLOC_LIBS"
1186+
AC_DEFINE([HAVE_LIBHWLOC], [1], [Define to 1 if you have the 'hwloc' library (-lhwloc).])
11271187
], [
11281188
AC_CHECK_LIB([hwloc], [hwloc_get_proc_cpubind], [], [AC_MSG_ERROR([can not find required library libhwloc])])
11291189
AC_CHECK_HEADERS([hwloc.h], [], [AC_MSG_ERROR([can not find require header file hwloc.h])])
@@ -1318,11 +1378,7 @@ esac
13181378
case "$enable_delayacct" in
13191379
check|yes)
13201380
if test "x${LIBNL3_CFLAGS+y}" = x; then
1321-
m4_ifdef(
1322-
[PKG_PROG_PKG_CONFIG],
1323-
[PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [LIBNL3_CFLAGS="-I/usr/include/libnl3"])],
1324-
[LIBNL3_CFLAGS="-I/usr/include/libnl3"]
1325-
)
1381+
HTOP_PKG_CHECK_MODULES(LIBNL3, libnl-3.0, [], [LIBNL3_CFLAGS="-I/usr/include/libnl3"])
13261382
fi
13271383

13281384
htop_save_CFLAGS=$CFLAGS

0 commit comments

Comments
 (0)