ruby-changes:55621
From: NAKAMURA <ko1@a...>
Date: Tue, 30 Apr 2019 03:33:55 +0900 (JST)
Subject: [ruby-changes:55621] NAKAMURA Usaku:09022b6d70 (trunk): Use CreateToolhelp32Snapshot instead of NtQueryInformationProcess to get ppid on Windows
https://git.ruby-lang.org/ruby.git/commit/?id=09022b6d70 From 09022b6d70ad16737964e58db039aac00a1488ea Mon Sep 17 00:00:00 2001 From: NAKAMURA Usaku <usa@r...> Date: Tue, 30 Apr 2019 03:32:41 +0900 Subject: Use CreateToolhelp32Snapshot instead of NtQueryInformationProcess to get ppid on Windows Try to get rid of a spec error. diff --git a/win32/win32.c b/win32/win32.c index d28bd56..2e3f6c4 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -42,6 +42,7 @@ https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L42 #include <shlobj.h> #include <mbstring.h> #include <shlwapi.h> +#include <tlhelp32.h> #if _MSC_VER >= 1400 #include <crtdbg.h> #include <rtcapi.h> @@ -6139,6 +6140,26 @@ rb_w32_getppid(void) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L6140 static query_func *pNtQueryInformationProcess = (query_func *)-1; rb_pid_t ppid = 0; + HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (hSnap != INVALID_HANDLE_VALUE) { + BOOL ok; + PROCESSENTRY32 pe; + DWORD pid = GetCurrentProcessId(); + pe.dwSize = sizeof(pe); + ok = Process32First(hSnap, &pe); + while (ok) { + if (pe.th32ProcessID == pid) { + ppid = (rb_pid_t)pe.th32ParentProcessID; + break; + } + ok = Process32Next(hSnap, &pe); + } + CloseHandle(hSnap); + if (ppid != 0) { + return ppid; + } + } + if (pNtQueryInformationProcess == (query_func *)-1) pNtQueryInformationProcess = (query_func *)get_proc_address("ntdll.dll", "NtQueryInformationProcess", NULL); if (pNtQueryInformationProcess) { -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/