Skip to content

Commit 7720dbd

Browse files
committed
Implement fallback for old MacOS versions
1 parent 01226cf commit 7720dbd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

configure.ac

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,25 @@ AC_CHECK_HEADERS([execinfo.h])
186186

187187
if test "$my_htop_platform" = darwin; then
188188
AC_CHECK_HEADERS([mach/mach_time.h])
189+
AC_CHECK_HEADERS([mach/thread_info.h])
190+
191+
AC_MSG_CHECKING(for thread_extended_info_data_t)
192+
AC_COMPILE_IFELSE(
193+
AC_LANG_PROGRAM(
194+
[#include <mach/thread_info.h>],
195+
[
196+
thread_extended_info_data_t teid;
197+
(void)teid;
198+
]
199+
),
200+
[
201+
AC_DEFINE([HAVE_THREAD_EXTENDED_INFO_DATA_T], 1, [Define if thread_extended_info_data_t is available from <mach/thread_info.h>])
202+
AC_MSG_RESULT(yes)
203+
],
204+
[
205+
AC_MSG_RESULT(no)
206+
]
207+
)
189208
fi
190209

191210
# ----------------------------------------------------------------------

darwin/DarwinProcess.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Released under the GNU GPLv2+, see the COPYING file
55
in the source distribution for its full text.
66
*/
77

8+
#include "config.h" // IWYU pragma: keep
9+
810
#include "darwin/DarwinProcess.h"
911

1012
#include <libproc.h>
@@ -476,6 +478,7 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
476478
tprocess->st_uid = proc->st_uid;
477479
tprocess->user = proc->user;
478480

481+
#ifdef HAVE_THREAD_EXTENDED_INFO_DATA_T
479482
thread_extended_info_data_t extended_info;
480483
mach_msg_type_number_t extended_info_count = THREAD_EXTENDED_INFO_COUNT;
481484
ret = thread_info(thread_list[i], THREAD_EXTENDED_INFO, (thread_info_t) &extended_info, &extended_info_count);
@@ -495,9 +498,15 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
495498
isProcessStuck |= true;
496499
tdproc->super.state = UNINTERRUPTIBLE_WAIT;
497500
}
501+
#endif
498502

499503
// TODO: depend on setting
504+
#ifdef HAVE_THREAD_EXTENDED_INFO_DATA_T
500505
const char* name = extended_info.pth_name[0] != '\0' ? extended_info.pth_name : proc->procComm;
506+
#else
507+
// Not provided in thread_basic_info_data_t; fall back to the process name
508+
const char* name = proc->procComm;
509+
#endif
501510
Process_updateCmdline(tprocess, name, 0, name ? strlen(name) : 0);
502511

503512
if (!preExisting)

0 commit comments

Comments
 (0)