Offset pid_set by 1

PID starts at 1, not 0
This commit is contained in:
topjohnwu 2020-11-08 02:12:35 -08:00
parent ade1597e03
commit b14a260827
2 changed files with 10 additions and 2 deletions

View File

@ -289,5 +289,4 @@ void test_proc_monitor() {
if (procfp == nullptr && (procfp = opendir("/proc")) == nullptr)
exit(1);
proc_monitor();
exit(0);
}

View File

@ -35,7 +35,16 @@ static map<int, vector<string_view>> uid_proc_map; /* uid -> list of process */
pthread_mutex_t monitor_lock;
#define PID_MAX 32768
static bitset<PID_MAX> attaches; /* true if pid is monitored */
struct pid_set {
bitset<PID_MAX>::const_reference operator[](size_t pos) const { return set[pos - 1]; }
bitset<PID_MAX>::reference operator[](size_t pos) { return set[pos - 1]; }
void reset() { set.reset(); }
private:
bitset<PID_MAX> set;
};
// true if pid is monitored
pid_set attaches;
/********
* Utils