mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 1400042 - Remove SetAllFDsToCloseOnExec r=mccr8
As the comments indicate, it has unavoidable race conditions in a multithreaded program, and its call sites have all been removed. Differential Revision: https://phabricator.services.mozilla.com/D6561 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
fa3590f449
commit
8724a9004a
@ -83,12 +83,6 @@ void CloseProcessHandle(ProcessHandle process);
|
||||
ProcessId GetProcId(ProcessHandle process);
|
||||
|
||||
#if defined(OS_POSIX)
|
||||
// Sets all file descriptors to close on exec except for stdin, stdout
|
||||
// and stderr.
|
||||
// TODO(agl): remove this function
|
||||
// WARNING: do not use. It's inherently race-prone in the face of
|
||||
// multi-threading.
|
||||
void SetAllFDsToCloseOnExec();
|
||||
// Close all file descriptors, except for std{in,out,err} and those
|
||||
// for which the given function returns true. Only call this function
|
||||
// in a child process where you know that there aren't any other
|
||||
|
@ -206,40 +206,6 @@ void CloseSuperfluousFds(void* aCtx, bool (*aShouldPreserve)(void*, int))
|
||||
}
|
||||
}
|
||||
|
||||
// Sets all file descriptors to close on exec except for stdin, stdout
|
||||
// and stderr.
|
||||
// TODO(agl): Remove this function. It's fundamentally broken for multithreaded
|
||||
// apps.
|
||||
void SetAllFDsToCloseOnExec() {
|
||||
#if defined(OS_LINUX) || defined(OS_SOLARIS)
|
||||
const char fd_dir[] = "/proc/self/fd";
|
||||
#elif defined(OS_MACOSX) || defined(OS_BSD)
|
||||
const char fd_dir[] = "/dev/fd";
|
||||
#endif
|
||||
ScopedDIR dir_closer(opendir(fd_dir));
|
||||
DIR *dir = dir_closer.get();
|
||||
if (NULL == dir) {
|
||||
DLOG(ERROR) << "Unable to open " << fd_dir;
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir(dir))) {
|
||||
// Skip . and .. entries.
|
||||
if (ent->d_name[0] == '.')
|
||||
continue;
|
||||
int i = atoi(ent->d_name);
|
||||
// We don't close stdin, stdout or stderr.
|
||||
if (i <= STDERR_FILENO)
|
||||
continue;
|
||||
|
||||
int flags = fcntl(i, F_GETFD);
|
||||
if ((flags == -1) || (fcntl(i, F_SETFD, flags | FD_CLOEXEC) == -1)) {
|
||||
DLOG(ERROR) << "fcntl failure.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DidProcessCrash(bool* child_exited, ProcessHandle handle) {
|
||||
int status;
|
||||
const int result = HANDLE_EINTR(waitpid(handle, &status, WNOHANG));
|
||||
|
Loading…
Reference in New Issue
Block a user