src/windows/native/java/lang/ProcessImpl_md.c

Print this page


   1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 279 Java_java_lang_ProcessImpl_getExitCodeProcess(JNIEnv *env, jclass ignored, jlong handle)
 280 {
 281     DWORD exit_code;
 282     if (GetExitCodeProcess((HANDLE) handle, &exit_code) == 0)
 283         win32Error(env, "GetExitCodeProcess");
 284     return exit_code;
 285 }
 286 
 287 JNIEXPORT jint JNICALL
 288 Java_java_lang_ProcessImpl_getStillActive(JNIEnv *env, jclass ignored)
 289 {
 290     return STILL_ACTIVE;
 291 }
 292 
 293 JNIEXPORT void JNICALL
 294 Java_java_lang_ProcessImpl_waitForInterruptibly(JNIEnv *env, jclass ignored, jlong handle)
 295 {
 296     HANDLE events[2];
 297     events[0] = (HANDLE) handle;
 298     events[1] = JVM_GetThreadInterruptEvent();
 299 
 300     if (WaitForMultipleObjects(sizeof(events)/sizeof(events[0]), events,
 301                                FALSE,    /* Wait for ANY event */
 302                                INFINITE) /* Wait forever */
 303         == WAIT_FAILED)
 304         win32Error(env, "WaitForMultipleObjects");
 305 }
 306 
 307 JNIEXPORT void JNICALL



















 308 Java_java_lang_ProcessImpl_terminateProcess(JNIEnv *env, jclass ignored, jlong handle)
 309 {
 310     TerminateProcess((HANDLE) handle, 1);
 311 }
 312 








 313 JNIEXPORT jboolean JNICALL
 314 Java_java_lang_ProcessImpl_closeHandle(JNIEnv *env, jclass ignored, jlong handle)
 315 {
 316     return CloseHandle((HANDLE) handle);
 317 }
 318 
 319 /**
 320  * Returns a copy of the Unicode characters of a string. Fow now this
 321  * function doesn't handle long path names and other issues.
 322  */
 323 static WCHAR* getPath(JNIEnv *env, jstring ps) {
 324     WCHAR *pathbuf = NULL;
 325     const jchar *chars = (*(env))->GetStringChars(env, ps, NULL);
 326     if (chars != NULL) {
 327         size_t pathlen = wcslen(chars);
 328         pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
 329         if (pathbuf == NULL) {
 330             JNU_ThrowOutOfMemoryError(env, NULL);
 331         } else {
 332             wcscpy(pathbuf, chars);


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 279 Java_java_lang_ProcessImpl_getExitCodeProcess(JNIEnv *env, jclass ignored, jlong handle)
 280 {
 281     DWORD exit_code;
 282     if (GetExitCodeProcess((HANDLE) handle, &exit_code) == 0)
 283         win32Error(env, "GetExitCodeProcess");
 284     return exit_code;
 285 }
 286 
 287 JNIEXPORT jint JNICALL
 288 Java_java_lang_ProcessImpl_getStillActive(JNIEnv *env, jclass ignored)
 289 {
 290     return STILL_ACTIVE;
 291 }
 292 
 293 JNIEXPORT void JNICALL
 294 Java_java_lang_ProcessImpl_waitForInterruptibly(JNIEnv *env, jclass ignored, jlong handle)
 295 {
 296     HANDLE events[2];
 297     events[0] = (HANDLE) handle;
 298     events[1] = JVM_GetThreadInterruptEvent();

 299     if (WaitForMultipleObjects(sizeof(events)/sizeof(events[0]), events,
 300                                FALSE,    /* Wait for ANY event */
 301                                INFINITE)  /* Wait forever */
 302         == WAIT_FAILED)
 303         win32Error(env, "WaitForMultipleObjects");
 304 }
 305 
 306 JNIEXPORT void JNICALL
 307 Java_java_lang_ProcessImpl_waitForTimeoutInterruptibly(JNIEnv *env, 
 308                                                        jclass ignored, 
 309                                                        jlong handle,
 310                                                        jlong timeout)
 311 {
 312     HANDLE events[2];
 313     DWORD dwTimeout = (DWORD)timeout;
 314     DWORD result;
 315     events[0] = (HANDLE) handle;
 316     events[1] = JVM_GetThreadInterruptEvent();
 317     result = WaitForMultipleObjects(sizeof(events)/sizeof(events[0]), events,
 318                                     FALSE,    /* Wait for ANY event */
 319                                     dwTimeout);  /* Wait for dwTimeout */
 320 
 321     if (result == WAIT_FAILED)
 322         win32Error(env, "WaitForMultipleObjects");
 323 }
 324 
 325 JNIEXPORT void JNICALL
 326 Java_java_lang_ProcessImpl_terminateProcess(JNIEnv *env, jclass ignored, jlong handle)
 327 {
 328     TerminateProcess((HANDLE) handle, 1);
 329 }
 330 
 331 JNIEXPORT jboolean JNICALL
 332 Java_java_lang_ProcessImpl_isProcessAlive(JNIEnv *env, jclass ignored, jlong handle)
 333 {
 334     DWORD dwExitStatus;
 335     GetExitCodeProcess(handle, &dwExitStatus);
 336     return dwExitStatus == STILL_ACTIVE;
 337 }
 338 
 339 JNIEXPORT jboolean JNICALL
 340 Java_java_lang_ProcessImpl_closeHandle(JNIEnv *env, jclass ignored, jlong handle)
 341 {
 342     return CloseHandle((HANDLE) handle);
 343 }
 344 
 345 /**
 346  * Returns a copy of the Unicode characters of a string. Fow now this
 347  * function doesn't handle long path names and other issues.
 348  */
 349 static WCHAR* getPath(JNIEnv *env, jstring ps) {
 350     WCHAR *pathbuf = NULL;
 351     const jchar *chars = (*(env))->GetStringChars(env, ps, NULL);
 352     if (chars != NULL) {
 353         size_t pathlen = wcslen(chars);
 354         pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
 355         if (pathbuf == NULL) {
 356             JNU_ThrowOutOfMemoryError(env, NULL);
 357         } else {
 358             wcscpy(pathbuf, chars);