Skip to content

Commit

Permalink
Fixup in parent process handle getter for windows
Browse files Browse the repository at this point in the history
Summary: GetCurrentProcess actually returns something weird but understood by Windows api, so there's no need to wrap it into UniqueWrapper and check for validity

Reviewed By: Orvid

Differential Revision: D46934157

fbshipit-source-id: da0ab6af56159afc28db6111060ffac87b32c288
  • Loading branch information
mlogachev authored and facebook-github-bot committed Jun 23, 2023
1 parent 0a6e373 commit c82d4fb
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions folly/portability/Unistd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ struct UniqueHandleWrapper {
HANDLE get() const { return handle_; }
bool valid() const { return handle_ != INVALID_HANDLE_VALUE; }

UniqueHandleWrapper(UniqueHandleWrapper&& other) : handle_(other.handle_) {
UniqueHandleWrapper(UniqueHandleWrapper&& other) {
handle_ = other.handle_;
other.handle_ = INVALID_HANDLE_VALUE;
}
UniqueHandleWrapper& operator=(UniqueHandleWrapper&& other) {
Expand Down Expand Up @@ -153,12 +154,7 @@ int64_t getProcessStartTime(HANDLE processHandle) {

ProcessHandleWrapper getParentProcessHandle() {
DWORD ppid = 1;
UniqueHandleWrapper currentProcess = GetCurrentProcess();
if (!currentProcess.valid()) {
return INVALID_HANDLE_VALUE;
}

DWORD pid = GetProcessId(currentProcess.get());
DWORD pid = GetCurrentProcessId();

UniqueHandleWrapper hSnapshot =
CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Expand Down Expand Up @@ -191,7 +187,7 @@ ProcessHandleWrapper getParentProcessHandle() {
// We need this logic because we can't guarantee that parent id hasn't been
// reused before getting process handle to this process.

int64_t currentProcessStartTime = getProcessStartTime(currentProcess.get());
int64_t currentProcessStartTime = getProcessStartTime(GetCurrentProcess());
int64_t parentProcessStartTime = getProcessStartTime(parent.get());
if (currentProcessStartTime == -1 || parentProcessStartTime == -1 ||
currentProcessStartTime < parentProcessStartTime) {
Expand Down

0 comments on commit c82d4fb

Please sign in to comment.