Skip to content
This repository has been archived by the owner on Jan 15, 2025. It is now read-only.

Commit

Permalink
(maint) Merge up 170e094 to master
Browse files Browse the repository at this point in the history
Generated by CI

* commit '170e0941cbbe6251a02ba15fa1f25e891c5f579d':
  (LTH-162) Don't check for /proc when running CMake
  (LTH-162) Use /proc to close file descriptors
  (LTH-160) Use closefrom(2) when available (#291)
  • Loading branch information
puppetlabs-jenkins committed Sep 4, 2019
2 parents 83ad3f7 + 170e094 commit 291c6be
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions execution/src/posix/execution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,26 @@ namespace leatherman { namespace execution {
#ifdef HAS_CLOSEFROM
closefrom(STDERR_FILENO + 1);
#else
for (uint64_t i = (STDERR_FILENO + 1); i < max_fd; ++i) {
close(i);
uint64_t fd;
const char* fdpath = "/proc/self/fd";
std::list<uint64_t> fd_list;

if (is_directory(fdpath)) {
for (const directory_entry& dent : directory_iterator(fdpath)) {
fd = atol(dent.path().filename().c_str());
if (fd >= (STDERR_FILENO + 1)) {
fd_list.push_back(fd);
}
}
for (auto fd : fd_list) {
close(fd);
}
} else {
for (uint64_t i = (STDERR_FILENO + 1); i < max_fd; ++i) {
close(i);
}
}
#endif
#endif // HAS_CLOSEFROM

// Execute the given program; this should not return if successful
execve(program, const_cast<char* const*>(argv), const_cast<char* const*>(envp));
Expand Down

0 comments on commit 291c6be

Please sign in to comment.