author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 48 | dc5744ca15ea |
child 5168 | 41e46b5d9b15 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include <assert.h> |
|
27 |
#include "java_lang_ProcessImpl.h" |
|
28 |
||
29 |
#include "jni.h" |
|
30 |
#include "jvm.h" |
|
31 |
#include "jni_util.h" |
|
32 |
#include "io_util.h" |
|
33 |
#include <windows.h> |
|
34 |
#include <io.h> |
|
35 |
||
43
bfccfd41f0fc
6631966: (process) Raise Windows pipe buffer size an extra 24 bytes (win)
martin
parents:
2
diff
changeset
|
36 |
/* We try to make sure that we can read and write 4095 bytes (the |
bfccfd41f0fc
6631966: (process) Raise Windows pipe buffer size an extra 24 bytes (win)
martin
parents:
2
diff
changeset
|
37 |
* fixed limit on Linux) to the pipe on all operating systems without |
bfccfd41f0fc
6631966: (process) Raise Windows pipe buffer size an extra 24 bytes (win)
martin
parents:
2
diff
changeset
|
38 |
* deadlock. Windows 2000 inexplicably appears to need an extra 24 |
bfccfd41f0fc
6631966: (process) Raise Windows pipe buffer size an extra 24 bytes (win)
martin
parents:
2
diff
changeset
|
39 |
* bytes of slop to avoid deadlock. |
bfccfd41f0fc
6631966: (process) Raise Windows pipe buffer size an extra 24 bytes (win)
martin
parents:
2
diff
changeset
|
40 |
*/ |
bfccfd41f0fc
6631966: (process) Raise Windows pipe buffer size an extra 24 bytes (win)
martin
parents:
2
diff
changeset
|
41 |
#define PIPE_SIZE (4096+24) |
2 | 42 |
|
43 |
char * |
|
44 |
extractExecutablePath(JNIEnv *env, char *source) |
|
45 |
{ |
|
46 |
char *p, *r; |
|
47 |
||
48 |
/* If no spaces, then use entire thing */ |
|
49 |
if ((p = strchr(source, ' ')) == NULL) |
|
50 |
return source; |
|
51 |
||
52 |
/* If no quotes, or quotes after space, return up to space */ |
|
53 |
if (((r = strchr(source, '"')) == NULL) || (r > p)) { |
|
54 |
*p = 0; |
|
55 |
return source; |
|
56 |
} |
|
57 |
||
58 |
/* Quotes before space, return up to space after next quotes */ |
|
59 |
p = strchr(r, '"'); |
|
60 |
if ((p = strchr(p, ' ')) == NULL) |
|
61 |
return source; |
|
62 |
*p = 0; |
|
63 |
return source; |
|
64 |
} |
|
65 |
||
66 |
DWORD |
|
67 |
selectProcessFlag(JNIEnv *env, jstring cmd0) |
|
68 |
{ |
|
69 |
char buf[MAX_PATH]; |
|
70 |
DWORD newFlag = 0; |
|
71 |
char *exe, *p, *name; |
|
72 |
unsigned char buffer[2]; |
|
73 |
long headerLoc = 0; |
|
74 |
int fd = 0; |
|
75 |
||
76 |
exe = (char *)JNU_GetStringPlatformChars(env, cmd0, 0); |
|
77 |
exe = extractExecutablePath(env, exe); |
|
78 |
||
79 |
if (exe != NULL) { |
|
80 |
if ((p = strchr(exe, '\\')) == NULL) { |
|
81 |
SearchPath(NULL, exe, ".exe", MAX_PATH, buf, &name); |
|
82 |
} else { |
|
83 |
p = strrchr(exe, '\\'); |
|
84 |
*p = 0; |
|
85 |
p++; |
|
86 |
SearchPath(exe, p, ".exe", MAX_PATH, buf, &name); |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
fd = _open(buf, _O_RDONLY); |
|
91 |
if (fd > 0) { |
|
92 |
_read(fd, buffer, 2); |
|
93 |
if (buffer[0] == 'M' && buffer[1] == 'Z') { |
|
94 |
_lseek(fd, 60L, SEEK_SET); |
|
95 |
_read(fd, buffer, 2); |
|
96 |
headerLoc = (long)buffer[1] << 8 | (long)buffer[0]; |
|
97 |
_lseek(fd, headerLoc, SEEK_SET); |
|
98 |
_read(fd, buffer, 2); |
|
99 |
if (buffer[0] == 'P' && buffer[1] == 'E') { |
|
100 |
newFlag = DETACHED_PROCESS; |
|
101 |
} |
|
102 |
} |
|
103 |
_close(fd); |
|
104 |
} |
|
105 |
JNU_ReleaseStringPlatformChars(env, cmd0, exe); |
|
106 |
return newFlag; |
|
107 |
} |
|
108 |
||
109 |
static void |
|
110 |
win32Error(JNIEnv *env, const char *functionName) |
|
111 |
{ |
|
112 |
static const char * const format = "%s error=%d, %s"; |
|
113 |
static const char * const fallbackFormat = "%s failed, error=%d"; |
|
114 |
char buf[256]; |
|
115 |
char errmsg[sizeof(buf) + 100]; |
|
116 |
const int errnum = GetLastError(); |
|
117 |
const int n = JVM_GetLastErrorString(buf, sizeof(buf)); |
|
118 |
if (n > 0) |
|
119 |
sprintf(errmsg, format, functionName, errnum, buf); |
|
120 |
else |
|
121 |
sprintf(errmsg, fallbackFormat, functionName, errnum); |
|
122 |
JNU_ThrowIOException(env, errmsg); |
|
123 |
} |
|
124 |
||
125 |
static void |
|
126 |
closeSafely(HANDLE handle) |
|
127 |
{ |
|
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
128 |
if (handle != INVALID_HANDLE_VALUE) |
2 | 129 |
CloseHandle(handle); |
130 |
} |
|
131 |
||
132 |
JNIEXPORT jlong JNICALL |
|
133 |
Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored, |
|
134 |
jstring cmd, |
|
135 |
jstring envBlock, |
|
136 |
jstring dir, |
|
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
137 |
jlongArray stdHandles, |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
138 |
jboolean redirectErrorStream) |
2 | 139 |
{ |
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
140 |
HANDLE inRead = INVALID_HANDLE_VALUE; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
141 |
HANDLE inWrite = INVALID_HANDLE_VALUE; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
142 |
HANDLE outRead = INVALID_HANDLE_VALUE; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
143 |
HANDLE outWrite = INVALID_HANDLE_VALUE; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
144 |
HANDLE errRead = INVALID_HANDLE_VALUE; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
145 |
HANDLE errWrite = INVALID_HANDLE_VALUE; |
2 | 146 |
SECURITY_ATTRIBUTES sa; |
147 |
PROCESS_INFORMATION pi; |
|
148 |
STARTUPINFO si; |
|
149 |
LPTSTR pcmd = NULL; |
|
150 |
LPCTSTR pdir = NULL; |
|
151 |
LPVOID penvBlock = NULL; |
|
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
152 |
jlong *handles = NULL; |
2 | 153 |
jlong ret = 0; |
154 |
OSVERSIONINFO ver; |
|
155 |
jboolean onNT = JNI_FALSE; |
|
156 |
DWORD processFlag; |
|
157 |
||
158 |
ver.dwOSVersionInfoSize = sizeof(ver); |
|
159 |
GetVersionEx(&ver); |
|
160 |
if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) |
|
161 |
onNT = JNI_TRUE; |
|
162 |
||
163 |
assert(cmd != NULL); |
|
164 |
pcmd = (LPTSTR) JNU_GetStringPlatformChars(env, cmd, NULL); |
|
165 |
if (pcmd == NULL) goto Catch; |
|
166 |
||
167 |
if (dir != 0) { |
|
168 |
pdir = (LPCTSTR) JNU_GetStringPlatformChars(env, dir, NULL); |
|
169 |
if (pdir == NULL) goto Catch; |
|
170 |
pdir = (LPCTSTR) JVM_NativePath((char *)pdir); |
|
171 |
} |
|
172 |
||
173 |
if (envBlock != NULL) { |
|
174 |
penvBlock = onNT |
|
175 |
? (LPVOID) ((*env)->GetStringChars(env, envBlock, NULL)) |
|
176 |
: (LPVOID) JNU_GetStringPlatformChars(env, envBlock, NULL); |
|
177 |
if (penvBlock == NULL) goto Catch; |
|
178 |
} |
|
179 |
||
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
180 |
assert(stdHandles != NULL); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
181 |
handles = (*env)->GetLongArrayElements(env, stdHandles, NULL); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
182 |
if (handles == NULL) goto Catch; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
183 |
|
2 | 184 |
memset(&si, 0, sizeof(si)); |
185 |
si.cb = sizeof(si); |
|
186 |
si.dwFlags = STARTF_USESTDHANDLES; |
|
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
187 |
|
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
188 |
sa.nLength = sizeof(sa); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
189 |
sa.lpSecurityDescriptor = 0; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
190 |
sa.bInheritHandle = TRUE; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
191 |
|
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
192 |
if (handles[0] != (jlong) -1) { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
193 |
si.hStdInput = (HANDLE) handles[0]; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
194 |
handles[0] = (jlong) -1; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
195 |
} else { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
196 |
if (! CreatePipe(&inRead, &inWrite, &sa, PIPE_SIZE)) { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
197 |
win32Error(env, "CreatePipe"); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
198 |
goto Catch; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
199 |
} |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
200 |
si.hStdInput = inRead; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
201 |
SetHandleInformation(inWrite, HANDLE_FLAG_INHERIT, FALSE); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
202 |
handles[0] = (jlong) inWrite; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
203 |
} |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
204 |
SetHandleInformation(si.hStdInput, HANDLE_FLAG_INHERIT, TRUE); |
2 | 205 |
|
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
206 |
if (handles[1] != (jlong) -1) { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
207 |
si.hStdOutput = (HANDLE) handles[1]; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
208 |
handles[1] = (jlong) -1; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
209 |
} else { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
210 |
if (! CreatePipe(&outRead, &outWrite, &sa, PIPE_SIZE)) { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
211 |
win32Error(env, "CreatePipe"); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
212 |
goto Catch; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
213 |
} |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
214 |
si.hStdOutput = outWrite; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
215 |
SetHandleInformation(outRead, HANDLE_FLAG_INHERIT, FALSE); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
216 |
handles[1] = (jlong) outRead; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
217 |
} |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
218 |
SetHandleInformation(si.hStdOutput, HANDLE_FLAG_INHERIT, TRUE); |
2 | 219 |
|
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
220 |
if (redirectErrorStream) { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
221 |
si.hStdError = si.hStdOutput; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
222 |
handles[2] = (jlong) -1; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
223 |
} else if (handles[2] != (jlong) -1) { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
224 |
si.hStdError = (HANDLE) handles[2]; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
225 |
handles[2] = (jlong) -1; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
226 |
} else { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
227 |
if (! CreatePipe(&errRead, &errWrite, &sa, PIPE_SIZE)) { |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
228 |
win32Error(env, "CreatePipe"); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
229 |
goto Catch; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
230 |
} |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
231 |
si.hStdError = errWrite; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
232 |
SetHandleInformation(errRead, HANDLE_FLAG_INHERIT, FALSE); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
233 |
handles[2] = (jlong) errRead; |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
234 |
} |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
235 |
SetHandleInformation(si.hStdError, HANDLE_FLAG_INHERIT, TRUE); |
2 | 236 |
|
237 |
if (onNT) |
|
238 |
processFlag = CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT; |
|
239 |
else |
|
240 |
processFlag = selectProcessFlag(env, cmd); |
|
241 |
||
242 |
/* Java and Windows are both pure Unicode systems at heart. |
|
243 |
* Windows has both a legacy byte-based API and a 16-bit Unicode |
|
244 |
* "W" API. The Right Thing here is to call CreateProcessW, since |
|
245 |
* that will allow all process-related information like command |
|
246 |
* line arguments to be passed properly to the child. We don't do |
|
247 |
* that currently, since we would first have to have "W" versions |
|
248 |
* of JVM_NativePath and perhaps other functions. In the |
|
249 |
* meantime, we can call CreateProcess with the magic flag |
|
250 |
* CREATE_UNICODE_ENVIRONMENT, which passes only the environment |
|
251 |
* in "W" mode. We will fix this later. */ |
|
252 |
||
253 |
ret = CreateProcess(0, /* executable name */ |
|
254 |
pcmd, /* command line */ |
|
255 |
0, /* process security attribute */ |
|
256 |
0, /* thread security attribute */ |
|
257 |
TRUE, /* inherits system handles */ |
|
258 |
processFlag, /* selected based on exe type */ |
|
259 |
penvBlock, /* environment block */ |
|
260 |
pdir, /* change to the new current directory */ |
|
261 |
&si, /* (in) startup information */ |
|
262 |
&pi); /* (out) process information */ |
|
263 |
||
264 |
if (!ret) { |
|
265 |
win32Error(env, "CreateProcess"); |
|
266 |
goto Catch; |
|
267 |
} |
|
268 |
||
269 |
CloseHandle(pi.hThread); |
|
270 |
ret = (jlong)pi.hProcess; |
|
271 |
||
272 |
Finally: |
|
273 |
/* Always clean up the child's side of the pipes */ |
|
274 |
closeSafely(inRead); |
|
275 |
closeSafely(outWrite); |
|
276 |
closeSafely(errWrite); |
|
277 |
||
278 |
if (pcmd != NULL) |
|
279 |
JNU_ReleaseStringPlatformChars(env, cmd, (char *) pcmd); |
|
280 |
if (pdir != NULL) |
|
281 |
JNU_ReleaseStringPlatformChars(env, dir, (char *) pdir); |
|
282 |
if (penvBlock != NULL) { |
|
283 |
if (onNT) |
|
284 |
(*env)->ReleaseStringChars(env, envBlock, (jchar *) penvBlock); |
|
285 |
else |
|
286 |
JNU_ReleaseStringPlatformChars(env, dir, (char *) penvBlock); |
|
287 |
} |
|
48
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
288 |
if (handles != NULL) |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
289 |
(*env)->ReleaseLongArrayElements(env, stdHandles, handles, 0); |
dc5744ca15ea
4960438: (process) Need IO redirection API for subprocesses
martin
parents:
43
diff
changeset
|
290 |
|
2 | 291 |
return ret; |
292 |
||
293 |
Catch: |
|
294 |
/* Clean up the parent's side of the pipes in case of failure only */ |
|
295 |
closeSafely(inWrite); |
|
296 |
closeSafely(outRead); |
|
297 |
closeSafely(errRead); |
|
298 |
goto Finally; |
|
299 |
} |
|
300 |
||
301 |
JNIEXPORT jint JNICALL |
|
302 |
Java_java_lang_ProcessImpl_getExitCodeProcess(JNIEnv *env, jclass ignored, jlong handle) |
|
303 |
{ |
|
304 |
DWORD exit_code; |
|
305 |
if (GetExitCodeProcess((HANDLE) handle, &exit_code) == 0) |
|
306 |
win32Error(env, "GetExitCodeProcess"); |
|
307 |
return exit_code; |
|
308 |
} |
|
309 |
||
310 |
JNIEXPORT jint JNICALL |
|
311 |
Java_java_lang_ProcessImpl_getStillActive(JNIEnv *env, jclass ignored) |
|
312 |
{ |
|
313 |
return STILL_ACTIVE; |
|
314 |
} |
|
315 |
||
316 |
JNIEXPORT void JNICALL |
|
317 |
Java_java_lang_ProcessImpl_waitForInterruptibly(JNIEnv *env, jclass ignored, jlong handle) |
|
318 |
{ |
|
319 |
HANDLE events[2]; |
|
320 |
events[0] = (HANDLE) handle; |
|
321 |
events[1] = JVM_GetThreadInterruptEvent(); |
|
322 |
||
323 |
if (WaitForMultipleObjects(sizeof(events)/sizeof(events[0]), events, |
|
324 |
FALSE, /* Wait for ANY event */ |
|
325 |
INFINITE) /* Wait forever */ |
|
326 |
== WAIT_FAILED) |
|
327 |
win32Error(env, "WaitForMultipleObjects"); |
|
328 |
} |
|
329 |
||
330 |
JNIEXPORT void JNICALL |
|
331 |
Java_java_lang_ProcessImpl_terminateProcess(JNIEnv *env, jclass ignored, jlong handle) |
|
332 |
{ |
|
333 |
TerminateProcess((HANDLE) handle, 1); |
|
334 |
} |
|
335 |
||
336 |
JNIEXPORT jboolean JNICALL |
|
337 |
Java_java_lang_ProcessImpl_closeHandle(JNIEnv *env, jclass ignored, jlong handle) |
|
338 |
{ |
|
339 |
return CloseHandle((HANDLE) handle); |
|
340 |
} |