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:
Jed Davis 2018-09-22 02:31:24 +00:00
parent fa3590f449
commit 8724a9004a
2 changed files with 0 additions and 40 deletions

View File

@ -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

View File

@ -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));