Skip to content

Commit

Permalink
Fix ProcStat::is_stale for gone PIDs
Browse files Browse the repository at this point in the history
Modify ProcStat::getinode_ to properly report error instead of returning
-1 (which does not work, since its return type ino_t is unsigned).

This enables ProcStat::is_stale to correctly report false when the PID is
gone, as intended in commit 552f4c6.
  • Loading branch information
lenticularis39 authored and yonghong-song committed Oct 8, 2022
1 parent 536155a commit 12e5312
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/cc/bcc_syms.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,24 @@

#include "syms.h"

ino_t ProcStat::getinode_() {
bool ProcStat::getinode_(ino_t &inode) {
struct stat s;
return (!stat(procfs_.c_str(), &s)) ? s.st_ino : -1;
if (!stat(procfs_.c_str(), &s)) {
inode = s.st_ino;
return true;
} else {
return false;
}
}

bool ProcStat::is_stale() {
ino_t cur_inode = getinode_();
return (cur_inode > 0) && (cur_inode != inode_);
ino_t cur_inode;
return getinode_(cur_inode) && (cur_inode != inode_);
}

ProcStat::ProcStat(int pid)
: procfs_(tfm::format("/proc/%d/exe", pid)), inode_(getinode_()) {}
ProcStat::ProcStat(int pid) : procfs_(tfm::format("/proc/%d/exe", pid)) {
getinode_(inode_);
}

void KSyms::_add_symbol(const char *symname, const char *modname, uint64_t addr, void *p) {
KSyms *ks = static_cast<KSyms *>(p);
Expand Down
6 changes: 3 additions & 3 deletions src/cc/syms.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
class ProcStat {
std::string procfs_;
ino_t inode_;
ino_t getinode_();
bool getinode_(ino_t &inode);

public:
public:
ProcStat(int pid);
bool is_stale();
void reset() { inode_ = getinode_(); }
void reset() { getinode_(inode_); }
};

class SymbolCache {
Expand Down

0 comments on commit 12e5312

Please sign in to comment.