diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index c063b9cd8..991563bce 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -369,7 +369,8 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps, void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable* dpt, double timeIntervalNS) { struct proc_taskinfo pti; - if (sizeof(pti) != proc_pidinfo(Process_getPid(&proc->super), PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { + if (PROC_PIDTASKINFO_SIZE != proc_pidinfo(Process_getPid(&proc->super), PROC_PIDTASKINFO, 0, &pti, PROC_PIDTASKINFO_SIZE)) { + proc->taskAccess = false; return; } @@ -390,6 +391,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable } Process_updateCPUFieldWidths(proc->super.percent_cpu); + proc->super.state = pti.pti_numrunning > 0 ? RUNNING : SLEEPING; proc->super.time = nanosecondsToCentiseconds(total_current_time_ns); proc->super.nlwp = pti.pti_threadnum; proc->super.m_virt = pti.pti_virtual_size / ONE_K; @@ -435,18 +437,6 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) { return; } - { - task_info_data_t tinfo; - mach_msg_type_number_t task_info_count = TASK_INFO_MAX; - ret = task_info(task, TASK_BASIC_INFO, (task_info_t) &tinfo, &task_info_count); - if (ret != KERN_SUCCESS) { - CRT_debug("task_info(%d) failed: %s", pid, mach_error_string(ret)); - dp->taskAccess = false; - mach_port_deallocate(mach_task_self(), task); - return; - } - } - thread_array_t thread_list; mach_msg_type_number_t thread_count; ret = task_threads(task, &thread_list, &thread_count); diff --git a/darwin/DarwinProcessTable.c b/darwin/DarwinProcessTable.c index 7fb0d4d69..47ef82e90 100644 --- a/darwin/DarwinProcessTable.c +++ b/darwin/DarwinProcessTable.c @@ -28,23 +28,6 @@ in the source distribution for its full text. #include "zfs/ZfsArcStats.h" -static ProcessState ProcessTable_mapDarwinProcessState(int kinfo_proc_state) { - switch(kinfo_proc_state) { - case SRUN: - return RUNNING; - case SSLEEP: - return SLEEPING; - case SSTOP: - return STOPPED; - case SZOMB: - return ZOMBIE; - case SIDL: - return IDLE; - default: - return UNKNOWN; - } -} - static struct kinfo_proc* ProcessTable_getKInfoProcs(size_t* count) { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; struct kinfo_proc* processes = NULL; @@ -124,7 +107,12 @@ void ProcessTable_goThroughEntries(ProcessTable* super) { proc->super.st_uid = ps[i].kp_eproc.e_ucred.cr_uid; proc->super.user = UsersTable_getRef(host->usersTable, proc->super.st_uid); } - proc->super.state = ProcessTable_mapDarwinProcessState(ps[i].kp_proc.p_stat); + + if (ps[i].kp_proc.p_stat == SZOMB) { + proc->super.state = ZOMBIE; + } else if (ps[i].kp_proc.p_stat == SSTOP) { + proc->super.state = STOPPED; + } // Disabled for High Sierra due to bug in macOS High Sierra bool isScanThreadSupported = !Platform_KernelVersionIsBetween((KernelVersion) {17, 0, 0}, (KernelVersion) {17, 5, 0});