summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-06 15:43:38 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-06 15:43:38 +0000
commitb76263fa09f778179e277b234b0057aadbcba6f9 (patch)
tree6e291216f2c8ed4b7652d7f557dbc48b5fc418d9 /win32
parent1fc2d3e4a9d4374df91976a83ce4bd0969222612 (diff)
* win32/win32.c (kill): check the process exited or not before
teminationg it. [Bug #4943] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/win32/win32.c b/win32/win32.c
index b3ffcffa07..e3bba4412f 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3847,7 +3847,14 @@ kill(int pid, int sig)
case SIGKILL:
RUBY_CRITICAL({
- HANDLE hProc = OpenProcess(PROCESS_TERMINATE, FALSE, (DWORD)pid);
+ HANDLE hProc;
+ struct ChildRecord* child = FindChildSlot(pid);
+ if (child) {
+ hProc = child->hProcess;
+ }
+ else {
+ hProc = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION, FALSE, (DWORD)pid);
+ }
if (hProc == NULL || hProc == INVALID_HANDLE_VALUE) {
if (GetLastError() == ERROR_INVALID_PARAMETER) {
errno = ESRCH;
@@ -3858,11 +3865,24 @@ kill(int pid, int sig)
ret = -1;
}
else {
- if (!TerminateProcess(hProc, 0)) {
- errno = EPERM;
+ DWORD status;
+ if (!GetExitCodeProcess(hProc, &status)) {
+ errno = map_errno(GetLastError());
ret = -1;
}
- CloseHandle(hProc);
+ else if (status == STILL_ACTIVE) {
+ if (!TerminateProcess(hProc, 0)) {
+ errno = EPERM;
+ ret = -1;
+ }
+ }
+ else {
+ errno = ESRCH;
+ ret = -1;
+ }
+ if (!child) {
+ CloseHandle(hProc);
+ }
}
});
break;
@@ -5629,6 +5649,11 @@ wunlink(const WCHAR *path)
SetFileAttributesW(path, attr);
}
}
+ else {
+ while (GetFileAttributesW(path) != (DWORD)-1 || GetLastError() != ERROR_FILE_NOT_FOUND) {
+ Sleep(0);
+ }
+ }
});
return ret;
}