# HG changeset patch # User Paper # Date 1701709709 18000 # Node ID 5be17d636aee68222d3e7b5fda36b98a4059de75 # Parent 9c4645100fece2ab28ed84cf739b4ce2a8a89e63 deps/animia/fd/proc: patch for new filename getter diff -r 9c4645100fec -r 5be17d636aee dep/animia/src/fd/proc.cc --- a/dep/animia/src/fd/proc.cc Mon Dec 04 12:03:36 2023 -0500 +++ b/dep/animia/src/fd/proc.cc Mon Dec 04 12:08:29 2023 -0500 @@ -75,7 +75,8 @@ static bool GetFilenameFromFd(std::string link, std::string& out) { /* gets around stupid linux limitation where /proc doesn't - give actual filesize readings */ + * give actual size readings of the string + */ constexpr size_t OUT_MAX = (1 << 15); // 32KiB out.resize(1024); @@ -84,27 +85,21 @@ out.resize(out.length() * 2)) { exe_used = readlink(link.c_str(), &out.front(), out.length()); if (exe_used == (ssize_t)-1 || exe_used < (ssize_t)1) - return false; + return false; // we got a bad result, i think } + + return true; } static std::string GetProcessName(pid_t pid) { std::string result; -#ifdef FREEBSD - struct kinfo_proc* proc = kinfo_getproc(pid); - if (!proc) - return ""; - result = proc->ki_comm; - free(proc); -#elif defined(LINUX) const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/comm"; if (!util::ReadFile(path, result)) return ""; result.erase(std::remove(result.begin(), result.end(), '\n'), result.end()); -#endif return result; } @@ -136,7 +131,9 @@ if (!AreFlagsOk(pid, std::stoi(Basename(dir)))) continue; - std::string name = GetFilenameFromFd(dir); + std::string name; + if (!GetFilenameFromFd(dir, name)) + continue; if (!IsRegularFile(name)) continue;