#include <dlog-redirect-stdout.h>
#include <errno.h>
#include <fcntl.h>
+#include <linux/limits.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
constexpr const char kProcessPool[] = "process-pool";
-std::vector<int> GetDlogFds() {
+bool IsExceptable(const std::string& path) {
+ static char buf[PATH_MAX];
+ ssize_t len = readlink(path.c_str(), buf, sizeof(buf));
+ if (len < 0) {
+ _E("readlink() is failed. errno: %d", errno);
+ return false;
+ }
+
+ buf[len] = '\0';
+ if (strstr(buf, "log") != nullptr ||
+ strstr(buf, "trace") != nullptr ||
+ strstr(buf, "dev") != nullptr)
+ return true;
+
+ return false;
+}
+
+std::vector<int> GetExceptableFds() {
std::vector<int> fds;
try {
fs::path proc_path("/proc/self/fd");
continue;
int fd = std::stoi(entry.path().filename().string());
- if (dlog_is_log_fd(fd))
+ if (dlog_is_log_fd(fd) || IsExceptable(entry.path().string()))
fds.push_back(fd);
}
} catch (const fs::filesystem_error& e) {
snprintf(args[0], length, "/usr/bin/%s <%s>", kProcessPool, name_.c_str());
close(pipe_fd_[1]);
- std::vector<int> except_fds = GetDlogFds();
+ std::vector<int> except_fds = GetExceptableFds();
except_fds.push_back(pipe_fd_[0]);
Util::CloseAllFds(except_fds);
int ret = WaitForRequest(std::make_unique<Socket>(pipe_fd_[0]));