#include "launchpad-process-pool/process_pool.hh"
+#include <dlog-redirect-stdout.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
+#include <filesystem>
#include <utility>
+#include <vector>
#include <util.hh>
#include "launchpad-process-pool/launchpad_args.hh"
#include "launchpad-process-pool/log_private.hh"
+namespace fs = std::filesystem;
+
namespace launchpad {
namespace {
constexpr const char kProcessPool[] = "process-pool";
+std::vector<int> GetDlogFds() {
+ std::vector<int> fds;
+ try {
+ fs::path proc_path("/proc/self/fd");
+ for (const auto& entry : fs::directory_iterator(proc_path)) {
+ if (!isdigit(entry.path().filename().string()[0]))
+ continue;
+
+ int fd = std::stoi(entry.path().filename().string());
+ if (dlog_is_log_fd(fd))
+ fds.push_back(fd);
+ }
+ } catch (const fs::filesystem_error& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+
+ return fds;
+}
+
} // namespace
ProcessPool::ProcessPool(std::string name, int num_processes,
snprintf(args[0], length, "/usr/bin/%s <%s>", kProcessPool, name_.c_str());
close(pipe_fd_[1]);
- std::vector<int> except_fds { pipe_fd_[0] };
+ std::vector<int> except_fds = GetDlogFds();
+ except_fds.push_back(pipe_fd_[0]);
Util::CloseAllFds(except_fds);
int ret = WaitForRequest(std::make_unique<Socket>(pipe_fd_[0]));
exit(ret);