Skip to content
Snippets Groups Projects
Commit 86e1d97c authored by George Nachman's avatar George Nachman
Browse files

Don't allow two threads to call proc_pidinfo at the same time. Issue 6142

parent c49c4ebb
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -9,6 +9,7 @@
#import "PTYTask.h"
#import "TaskNotifier.h"
#import "iTermAdvancedSettingsModel.h"
#import "iTermLSOF.h"
#import "iTermOrphanServerAdopter.h"
#import <OpenDirectory/OpenDirectory.h>
 
Loading
Loading
@@ -1056,11 +1057,11 @@ static int MyForkPty(int *amaster,
pid_t oldestPid = -1;
for (int i = 0; i < numPids; ++i) {
struct proc_taskallinfo taskAllInfo;
int rc = proc_pidinfo(pids[i],
PROC_PIDTASKALLINFO,
0,
&taskAllInfo,
sizeof(taskAllInfo));
int rc = iTermProcPidInfoWrapper(pids[i],
PROC_PIDTASKALLINFO,
0,
&taskAllInfo,
sizeof(taskAllInfo));
if (rc <= 0) {
continue;
}
Loading
Loading
@@ -1100,13 +1101,13 @@ static int MyForkPty(int *amaster,
// This only works if the child process is owned by our uid
// Notably it seems to work (at least on 10.10) even if the process ID is
// not owned by us.
ret = proc_pidinfo(self.pid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi));
ret = iTermProcPidInfoWrapper(self.pid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi));
if (ret <= 0) {
// The child was probably owned by root (which is expected if it's
// a login shell. Use the cwd of its oldest child instead.
pid_t childPid = [self getFirstChildOfPid:self.pid];
if (childPid > 0) {
ret = proc_pidinfo(childPid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi));
ret = iTermProcPidInfoWrapper(childPid, PROC_PIDVNODEPATHINFO, 0, &vpi, sizeof(vpi));
}
}
if (ret <= 0) {
Loading
Loading
Loading
Loading
@@ -66,6 +66,7 @@
 
#import "ProcessCache.h"
#import "iTerm.h"
#import "iTermLSOF.h"
#import "iTermProcessCollection.h"
#include <libproc.h>
#include <sys/sysctl.h>
Loading
Loading
@@ -179,11 +180,11 @@ NSString *PID_INFO_NAME = @"name";
struct proc_bsdshortinfo taskShortInfo;
memset(&taskShortInfo, 0, sizeof(taskShortInfo));
int rc;
rc = proc_pidinfo(thePid,
PROC_PIDT_SHORTBSDINFO,
0,
&taskShortInfo,
sizeof(taskShortInfo));
rc = iTermProcPidInfoWrapper(thePid,
PROC_PIDT_SHORTBSDINFO,
0,
&taskShortInfo,
sizeof(taskShortInfo));
if (rc <= 0) {
return 0;
} else {
Loading
Loading
Loading
Loading
@@ -10,6 +10,8 @@
 
@class iTermSocketAddress;
 
int iTermProcPidInfoWrapper(int pid, int flavor, uint64_t arg, void *buffer, int buffersize);
@interface iTermLSOF : NSObject
 
+ (pid_t)processIDWithConnectionFromAddress:(iTermSocketAddress *)socketAddress;
Loading
Loading
Loading
Loading
@@ -17,6 +17,12 @@
#include <string.h>
#include <sys/sysctl.h>
 
int iTermProcPidInfoWrapper(int pid, int flavor, uint64_t arg, void *buffer, int buffersize) {
@synchronized([iTermLSOF class]) {
return proc_pidinfo(pid, flavor, arg, buffer, buffersize);
}
}
@implementation iTermLSOF {
iTermSocketAddress *_socketAddress;
}
Loading
Loading
@@ -206,7 +212,7 @@
+ (size_t)maximumNumberOfFileDescriptorsForProcess:(pid_t)pid {
struct proc_taskallinfo tai;
memset(&tai, 0, sizeof(tai));
int numBytes = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &tai, sizeof(tai));
int numBytes = iTermProcPidInfoWrapper(pid, PROC_PIDTASKALLINFO, 0, &tai, sizeof(tai));
if (numBytes <= 0) {
return 0;
}
Loading
Loading
@@ -214,7 +220,7 @@
}
 
+ (int)numberOfFilePortsForProcess:(pid_t)pid {
int numBytes = proc_pidinfo(pid, PROC_PIDLISTFILEPORTS, 0, NULL, 0);
int numBytes = iTermProcPidInfoWrapper(pid, PROC_PIDLISTFILEPORTS, 0, NULL, 0);
if (numBytes <= 0) {
return 0;
}
Loading
Loading
@@ -227,7 +233,7 @@
return NULL;
}
struct proc_fdinfo *fds = malloc(maxSize);
int numBytes = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, fds, maxSize);
int numBytes = iTermProcPidInfoWrapper(pid, PROC_PIDLISTFDS, 0, fds, maxSize);
if (numBytes <= 0) {
free(fds);
return NULL;
Loading
Loading
@@ -243,7 +249,7 @@
return NULL;
}
struct proc_fileportinfo *filePortInfoArray = malloc(size);
int numBytes = proc_pidinfo(pid, PROC_PIDLISTFILEPORTS, 0, filePortInfoArray, size);
int numBytes = iTermProcPidInfoWrapper(pid, PROC_PIDLISTFILEPORTS, 0, filePortInfoArray, size);
if (numBytes <= 0) {
free(filePortInfoArray);
return NULL;
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment