Mercurial > minori
diff dep/animia/src/fd/proc.cc @ 180:5be17d636aee
deps/animia/fd/proc: patch for new filename getter
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 04 Dec 2023 12:08:29 -0500 |
parents | 54c5d80a737e |
children | d26cd2c00270 |
line wrap: on
line diff
--- 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;