summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-24 02:14:00 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-06-24 02:14:00 +0000
commitd3a0ef8198bf3257f37cf1149553b77981b85eab (patch)
treea0cefc7c5255c3c1e47614856633c75f0e07d2c7
parentb6cab6e8f1a443d4b8c56b4936cc454fa75c28f4 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--include/ruby/win32.h2
-rw-r--r--process.c4
-rw-r--r--win32/win32.c34
4 files changed, 43 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 2ab2aade28..ca5fe7ae9b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Tue Jun 24 11:12:33 2008 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* ext/socket/socket.c (init_sock): socket is binmode on platforms
diff --git a/include/ruby/win32.h b/include/ruby/win32.h
index 39dde94c84..12b8276272 100644
--- a/include/ruby/win32.h
+++ b/include/ruby/win32.h
@@ -140,6 +140,7 @@ extern DWORD rb_w32_osid(void);
#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 rb_pid_t rb_w32_aspawn(int, const char *, char *const *);
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
diff --git a/process.c b/process.c
index 0a5e119d1f..1f5fe62f4f 100644
--- a/process.c
+++ b/process.c
@@ -179,11 +179,7 @@ static VALUE
get_ppid(void)
{
rb_secure(2);
-#ifdef _WIN32
- return INT2FIX(0);
-#else
return PIDT2NUM(getppid());
-#endif
}
diff --git a/win32/win32.c b/win32/win32.c
index e79bbf2bad..dec12eb8d2 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3829,6 +3829,40 @@ rb_w32_getpid(void)
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)
{