mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
8562306c97
Move VecStringToCharPtrArr before fork, so that it cannot deadlock when other thread holds allocation lock. PiperOrigin-RevId: 414661912 Change-Id: Ie8aa5c36693e6f86c69d67a1da51b7e7ff1ec30b
33 lines
749 B
C++
33 lines
749 B
C++
#include <fcntl.h>
|
|
#include <linux/fs.h>
|
|
#include <unistd.h>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <glog/logging.h>
|
|
#include "absl/container/flat_hash_set.h"
|
|
#include "absl/strings/numbers.h"
|
|
#include "sandboxed_api/sandbox2/sanitizer.h"
|
|
|
|
bool IsFdOpen(int fd) {
|
|
int ret = fcntl(fd, F_GETFD);
|
|
if (ret == -1) {
|
|
CHECK(errno == EBADF);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
absl::flat_hash_set<int> exceptions;
|
|
for (int i = 0; i < argc; ++i) {
|
|
int fd;
|
|
CHECK(absl::SimpleAtoi(argv[i], &fd));
|
|
exceptions.insert(fd);
|
|
}
|
|
CHECK(sandbox2::sanitizer::CloseAllFDsExcept(exceptions).ok());
|
|
for (int i = 0; i < INR_OPEN_MAX; i++) {
|
|
CHECK_EQ(IsFdOpen(i), exceptions.find(i) != exceptions.end());
|
|
}
|
|
}
|