Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions darwin/DarwinMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ in the source distribution for its full text.
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <mach/mach_init.h>
#include <sys/mman.h>
#include <sys/sysctl.h>

Expand Down
15 changes: 15 additions & 0 deletions darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ in the source distribution for its full text.

#include "darwin/DarwinProcess.h"

#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
#include <libproc.h>
#endif
Comment on lines +11 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See docs/styleguide.md. Conditional includes should be below headers that are always included.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mach/mach_init.h>
#include <mach/mach.h>
#include <sys/dirent.h>

Expand Down Expand Up @@ -105,16 +110,19 @@ static int DarwinProcess_compareByKey(const Process* v1, const Process* v2, Proc
}

static void DarwinProcess_updateExe(pid_t pid, Process* proc) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
char path[PROC_PIDPATHINFO_MAXSIZE];

int r = proc_pidpath(pid, path, sizeof(path));
if (r <= 0)
return;

Process_updateExe(proc, path);
#endif
Comment on lines +113 to +121
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaves Process_updateExe uninitialized; at least call this explicitly as NULL, so things can be set up correctly as "unavailable".

}

static void DarwinProcess_updateCwd(pid_t pid, Process* proc) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
struct proc_vnodepathinfo vpi;

int r = proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi));
Expand All @@ -131,6 +139,7 @@ static void DarwinProcess_updateCwd(pid_t pid, Process* proc) {
}

free_and_xStrdup(&proc->procCwd, vpi.pvi_cdir.vip_path);
#endif
Comment on lines 141 to +142
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. at least call free_and_xStrdup(&proc->procCwd, NULL); so things are defined.

}

static void DarwinProcess_updateCmdLine(const struct kinfo_proc* k, Process* proc) {
Expand Down Expand Up @@ -360,6 +369,7 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
}

void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable* dpt, double timeIntervalNS) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
struct proc_taskinfo pti;

if (PROC_PIDTASKINFO_SIZE != proc_pidinfo(Process_getPid(&proc->super), PROC_PIDTASKINFO, 0, &pti, PROC_PIDTASKINFO_SIZE)) {
Expand Down Expand Up @@ -398,6 +408,9 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable
dpt->super.userlandThreads += pti.pti_threadnum; /*pti.pti_threads_user;*/
dpt->super.totalTasks += pti.pti_threadnum;
dpt->super.runningTasks += pti.pti_numrunning;
#else
proc->taskAccess = false;
#endif
Comment on lines +411 to +413
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to fill all the other fields here too; and be it with sensible "defaults" like "no time passed" for "one task"/"none running". Mark a todo to implement these with older APIs as necessary.

}

/*
Expand All @@ -406,6 +419,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable
* and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c
*/
void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
Process* proc = (Process*) dp;
kern_return_t ret;

Expand Down Expand Up @@ -510,6 +524,7 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {

vm_deallocate(mach_task_self(), (vm_address_t) thread_list, sizeof(thread_port_array_t) * thread_count);
mach_port_deallocate(mach_task_self(), task);
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. If there's not even essential information filled in we can also just declare things fully incompatible with such old versions of MacOS …

}


Expand Down
6 changes: 5 additions & 1 deletion darwin/DarwinProcessTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ in the source distribution for its full text.

#include "darwin/DarwinProcessTable.h"

#include <errno.h>
#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
#include <libproc.h>
#endif

#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down
1 change: 1 addition & 0 deletions darwin/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ in the source distribution for its full text.
#include <net/if_types.h>
#include <net/route.h>
#include <sys/socket.h>
#include <mach/mach_init.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here, when it's not used through new code? Or is was this missing before; and by which code?

#include <mach/port.h>

#include <CoreFoundation/CFBase.h>
Expand Down