13 #ifndef __STOUT_OS_POSIX_LSOF_HPP__ 14 #define __STOUT_OS_POSIX_LSOF_HPP__ 35 DIR* dir = ::fdopendir(fdDir);
43 std::vector<int_fd> result;
49 while ((entry = ::readdir(dir)) !=
nullptr) {
50 if (strcmp(entry->d_name,
".") == 0 || strcmp(entry->d_name,
"..") == 0) {
57 "Could not interpret file descriptor '" +
58 std::string(entry->d_name) +
"': " + fd.
error());
61 if (fd.
get() != fdDir) {
62 result.push_back(fd.
get());
73 if (::closedir(dir) == -1) {
74 return ErrnoError(
"Failed to close directory");
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:80
Try< int_fd > open(const std::string &path, int oflag, mode_t mode=0)
Definition: open.hpp:35
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
constexpr int O_CLOEXEC
Definition: open.hpp:41
Try< Nothing > close(int fd)
Definition: close.hpp:24
static Try error(const E &e)
Definition: try.hpp:43
bool isError() const
Definition: try.hpp:78
std::string error(const std::string &msg, uint32_t code)
Try< std::vector< int_fd > > lsof()
Definition: lsof.hpp:28