ruby-changes:6043
From: usa <ko1@a...>
Date: Tue, 24 Jun 2008 11:14:14 +0900 (JST)
Subject: [ruby-changes:6043] Ruby:r17553 (trunk): * include/ruby/win32.h, win32/win32.c (rb_w32_getppid): now support
usa 2008-06-24 11:14:00 +0900 (Tue, 24 Jun 2008)
New Revision: 17553
Modified files:
trunk/ChangeLog
trunk/include/ruby/win32.h
trunk/process.c
trunk/win32/win32.c
Log:
* include/ruby/win32.h, win32/win32.c (rb_w32_getppid): now support
getppid() on win32 (but only Win2k or later).
* process.c (get_ppid): remove win32 special logic.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/win32/win32.c?r1=17553&r2=17552&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/include/ruby/win32.h?r1=17553&r2=17552&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=17553&r2=17552&diff_format=u
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/process.c?r1=17553&r2=17552&diff_format=u
Index: include/ruby/win32.h
===================================================================
--- include/ruby/win32.h (revision 17552)
+++ include/ruby/win32.h (revision 17553)
@@ -140,6 +140,7 @@
#define read(f, b, s) rb_w32_read(f, b, s)
#define write(f, b, s) rb_w32_write(f, b, s)
#define getpid() rb_w32_getpid()
+#define getppid() rb_w32_getppid()
#define sleep(x) rb_w32_Sleep((x)*1000)
#define Sleep(msec) (void)rb_w32_Sleep(msec)
#define fstat(fd,st) _fstati64(fd,st)
@@ -262,6 +263,7 @@
extern int kill(int, int);
extern int fcntl(int, int, ...);
extern rb_pid_t rb_w32_getpid(void);
+extern rb_pid_t rb_w32_getppid(void);
#if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
extern int rb_w32_isatty(int);
#endif
Index: ChangeLog
===================================================================
--- ChangeLog (revision 17552)
+++ ChangeLog (revision 17553)
@@ -1,3 +1,10 @@
+Tue Jun 24 11:12:33 2008 NAKAMURA Usaku <usa@r...>
+
+ * include/ruby/win32.h, win32/win32.c (rb_w32_getppid): now support
+ getppid() on win32 (but only Win2k or later).
+
+ * process.c (get_ppid): remove win32 special logic.
+
Tue Jun 24 09:40:47 2008 NAKAMURA Usaku <usa@r...>
* ext/socket/socket.c (init_sock): socket is binmode on platforms
Index: win32/win32.c
===================================================================
--- win32/win32.c (revision 17552)
+++ win32/win32.c (revision 17553)
@@ -3829,6 +3829,40 @@
return pid;
}
+
+rb_pid_t
+rb_w32_getppid(void)
+{
+ static long (WINAPI *pNtQueryInformationProcess)(HANDLE, int, void *, ULONG, ULONG *) = NULL;
+ rb_pid_t ppid = 0;
+
+ if (!IsWin95() && rb_w32_osver() >= 5) {
+ if (!pNtQueryInformationProcess) {
+ HANDLE hNtDll = GetModuleHandle("ntdll.dll");
+ if (hNtDll) {
+ pNtQueryInformationProcess = (long (WINAPI *)(HANDLE, int, void *, ULONG, ULONG *))GetProcAddress(hNtDll, "NtQueryInformationProcess");
+ if (pNtQueryInformationProcess) {
+ struct {
+ long ExitStatus;
+ void* PebBaseAddress;
+ ULONG AffinityMask;
+ ULONG BasePriority;
+ ULONG UniqueProcessId;
+ ULONG ParentProcessId;
+ } pbi;
+ ULONG len;
+ long ret = pNtQueryInformationProcess(GetCurrentProcess(), 0, &pbi, sizeof(pbi), &len);
+ if (!ret) {
+ ppid = pbi.ParentProcessId;
+ }
+ }
+ }
+ }
+ }
+
+ return ppid;
+}
+
int
rb_w32_fclose(FILE *fp)
{
Index: process.c
===================================================================
--- process.c (revision 17552)
+++ process.c (revision 17553)
@@ -179,11 +179,7 @@
get_ppid(void)
{
rb_secure(2);
-#ifdef _WIN32
- return INT2FIX(0);
-#else
return PIDT2NUM(getppid());
-#endif
}
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/