bool FileSys::Upward() { if( callStack.size() - 1 < 1 ) return false; else { callStack.pop_back(); OpenDIR(); return true; } }
bool ProcFS::EnumerateThreads(pid_t pid, std::function<void(pid_t)> const &cb) { DIR *dir = OpenDIR(pid, "task"); if (dir == nullptr) return false; while (struct dirent *dp = readdir(dir)) { pid_t pid = strtol(dp->d_name, nullptr, 0); if (pid == 0) continue; cb(pid); } closedir(dir); return true; }
bool ProcFS::EnumerateProcesses(bool allUsers, uid_t uid, std::function<void(pid_t, uid_t)> const &cb) { DIR *dir = OpenDIR(""); if (dir == nullptr) return false; while (struct dirent *dp = readdir(dir)) { pid_t pid = strtol(dp->d_name, nullptr, 0); if (pid == 0) continue; // // Get the uid. // struct stat stbuf; char path[PATH_MAX + 1]; MakePath(path, PATH_MAX, pid, ""); if (stat(path, &stbuf) < 0) continue; // // Compare if necessary. // if (!allUsers && stbuf.st_uid != uid) continue; // // We don't want kernel threads, so exclude them from the list, // we know they are kernel threads because "exe" points to nothing. // if (GetProcessExecutablePath(pid).empty()) continue; cb(pid, stbuf.st_uid); } closedir(dir); return true; }
DIR *ProcFS::OpenDIR(pid_t pid, char const *what) { return OpenDIR(pid, pid, what); }
void FileSys::SetDefaultDir() { callStack.clear(); callStack.push_back( "/home/user" ); OpenDIR(); }