Commit 8bdd2efd authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

let AsyncBase not use PATH_MAX

Summary:
We may both improve portability and simplify impleementation by using `std::filesystem` in this case, which is just constructing a path and reading the corresponding symlink.

Pure runtime performance is not critical here - this codepath is mostly used for logging - so the extra allocations are not really a problem.

Reviewed By: Gownta

Differential Revision: D32942561

fbshipit-source-id: 6d24b9ba900dcfd8653a843cce539627f7f57735
parent abfe994f
......@@ -28,6 +28,7 @@
#include <folly/Format.h>
#include <folly/Likely.h>
#include <folly/String.h>
#include <folly/portability/Filesystem.h>
#include <folly/portability/Unistd.h>
#if __has_include(<sys/eventfd.h>)
......@@ -85,11 +86,8 @@ void AsyncBaseOp::init() {
}
std::string AsyncBaseOp::fd2name(int fd) {
std::string path = folly::to<std::string>("/proc/self/fd/", fd);
char link[PATH_MAX];
const ssize_t length =
std::max<ssize_t>(readlink(path.c_str(), link, PATH_MAX), 0);
return path.assign(link, length);
auto link = fs::path{"/proc/self/fd"} / folly::to<std::string>(fd);
return fs::read_symlink(link);
}
AsyncBase::AsyncBase(size_t capacity, PollMode pollMode) : capacity_(capacity) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment