commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfcl...@apache.org
Subject cvs commit: jakarta-commons-sandbox/daemon/src/native/nt/procrun procrun.c
Date Thu, 14 Aug 2003 15:52:31 GMT
jfclere     2003/08/14 08:52:31

  Modified:    daemon/src/native/nt/procrun procrun.c
  Log:
  - Arrange the code so that on win9x the hidden window waits for the main
    thread.
  - Improve the traces.
  - Add DuplicateHandle to allow to the thread/process handle in other
    thread/process. I use it to wait for the  main thread.
  Note: I have only tested procrun using "--Java auto" option feelings about
  using other "--Java" options are no very good.
  
  Revision  Changes    Path
  1.27      +58 -12    jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.c
  
  Index: procrun.c
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/nt/procrun/procrun.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- procrun.c	9 Aug 2003 01:59:42 -0000	1.26
  +++ procrun.c	14 Aug 2003 15:52:31 -0000	1.27
  @@ -136,6 +136,8 @@
       if (fd == NULL)
   	return;
       fprintf(fd,string);
  +    if (string[strlen(string)-1]!='\n')
  +        fprintf(fd,"\n");
       fclose(fd);
   }
   void dbprintf(char *format, ...)
  @@ -161,7 +163,7 @@
           va_end(args);
       }
       if (len > 0) {
  -        sprintf(tid, "[%04X] %s", GetCurrentThreadId(), buffer);
  +        sprintf(tid, "[%04X:%08d] %s", GetCurrentThreadId(),time(NULL), buffer);
           if (g_proc_stderr_file > 0)
               write(g_proc_stderr_file, tid, strlen(tid));
           else
  @@ -308,10 +310,10 @@
       }
       if (!GetExitCodeProcess(child->hProcess, &stat) || 
           (stat != STILL_ACTIVE)) {
  -            child->hProcess = NULL;
  -            child->dwProcessId = 0;
               DBPRINTF1("The child process %d isn't active any more\n",
                        child->dwProcessId);
  +            child->hProcess = NULL;
  +            child->dwProcessId = 0;
               return;
       } 
       GenerateConsoleCtrlEvent(CTRL_C_EVENT, child->dwProcessId);
  @@ -1082,10 +1084,12 @@
           DBPRINTF1("jvm dll path %s\n", proc->java.path);
           DBPRINTF1("java    path %s\n", proc->java.jpath);
           DBPRINTF1("java    bin  %s\n", proc->java.jbin);
  -        if (!proc->java.path || !proc->java.start_method)
  +        if (!proc->java.path || !proc->java.start_method) {
  +            DBPRINTF0("java path or start method missing\n");
               return -1;
  -        else if (proc->java.jbin != NULL) {
  -	        return 0; // If forking, don't bother with the load.
  +        } else if (proc->java.jbin != NULL) {
  +            DBPRINTF0("forking no need to load java dll\n");
  +	    return 0; // If forking, don't bother with the load.
           }
           /* Try to load the jvm dll */ 
           em = SetErrorMode(SEM_FAILCRITICALERRORS);
  @@ -1094,8 +1098,11 @@
               proc->java.dll = LoadLibraryEx(proc->java.path, NULL,
                                              LOAD_WITH_ALTERED_SEARCH_PATH);
           SetErrorMode(em);
  -        if (!proc->java.dll)
  +        if (!proc->java.dll) {
  +            DBPRINTF0(NULL);
  +            DBPRINTF0("Cannot load java dll\n");
               return -1;
  +        }
           /* resolve symbols */
           jni_JNI_GetDefaultJavaVMInitArgs = (JNI_GETDEFAULTJAVAVMINITARGS)
                                               GetProcAddress(proc->java.dll,
  @@ -1109,6 +1116,8 @@
           if (jni_JNI_GetDefaultJavaVMInitArgs == NULL ||
               jni_JNI_CreateJavaVM == NULL ||
               jni_JNI_GetCreatedJavaVMs == NULL) {
  +            DBPRINTF0(NULL);
  +            DBPRINTF0("Cannot find JNI routines in java dll\n");
               FreeLibrary(proc->java.dll);
               proc->java.dll = NULL;
               return -1;
  @@ -1179,6 +1188,7 @@
       int err;
       JNIEnv *env;
   
  +    DBPRINTF2("procrun_destroy_jvm dll %08x jvm %08x\n",proc->java.dll,proc->java.jvm);
       if (!proc->java.dll || !jvm) {
           if(proc->java.stop_class != NULL && proc->java.stop_method != NULL
&& g_env->c->pinfo.dwProcessId) {
               process_t tc = *g_env->c, tm = *g_env->m;
  @@ -1196,8 +1206,10 @@
           return 0;
       }
       env = jni_attach(proc);
  -    if (!env)
  +    if (!env) {
  +        DBPRINTF0("jni_attach failed\n");
           goto cleanup;
  +    }
       if (proc->java.stop_bridge && proc->java.stop_mid) {
           jclass strclass;
           jarray jargs = NULL;
  @@ -1640,8 +1652,10 @@
       si.wShowWindow = SW_HIDE;
   
       if(starting) {
  -        if (procrun_create_pipes(env))
  +        if (procrun_create_pipes(env)) {
  +            DBPRINTF0("Create pipe failed.\n");
               return -1;
  +        }
           si.hStdOutput = env->c->h_stdout[1];
           si.hStdError  = env->c->h_stderr[1];
           si.hStdInput  = env->c->h_stdin[0]; 
  @@ -1719,6 +1733,7 @@
               return -1;
           }
       }
  +    DBPRINTF1("started java thread %08x",env->c->pinfo.hThread);
       if(starting) {
           pool_handle(env->c->pool, env->c->pinfo.hThread);
           pool_handle(env->c->pool, env->c->pinfo.hProcess);
  @@ -2415,6 +2430,14 @@
               DBPRINTF0("ttyConsoleCtrlWndProc SHUTDOWN\n");
               SetEvent(g_env->m->events[0]);
   
  +            /* Wait for the JVM to stop */
  +            DBPRINTF1("Stopping: main thread %08x\n",g_env->m->pinfo.hThread);
  +            if (g_env->m->pinfo.hThread != NULL) {
  +                DBPRINTF0("ttyConsoleCtrlWndProc waiting for main\n");
  +                WaitForSingleObject(g_env->m->pinfo.hThread, 60000); 
  +                DBPRINTF0("ttyConsoleCtrlWndProc main thread finished\n");
  +            }
  +
               return(1); /* Otherwise it cancels the shutdown. */
           }
       }
  @@ -2542,7 +2565,7 @@
         if (g_is_windows_nt)
            fResult = SetServiceStatus(proc->service.h_status, &proc->service.status);
         if (!fResult) {
  -         DBPRINTF0("SetServiceStatus\tFailed\n");
  +         DBPRINTF0("SetServiceStatus Failed\n");
            DBPRINTF0(NULL);
         }
      }
  @@ -2691,6 +2714,8 @@
       DWORD fired;
       int   rv = -1;
       OSVERSIONINFO osver;
  +    HANDLE handle;
  +    BOOL isok;
   
       SERVICE_TABLE_ENTRY dispatch_table[] = {
           {NULL, NULL},
  @@ -2718,9 +2743,30 @@
   
       env->m->pinfo.dwProcessId = GetCurrentProcessId();
       env->m->pinfo.dwThreadId = GetCurrentThreadId();
  -    env->m->pinfo.hProcess = GetCurrentProcess();
  -    env->m->pinfo.hThread = GetCurrentThread();
  +
  +    isok = DuplicateHandle(GetCurrentProcess(),GetCurrentProcess(),
  +                    GetCurrentProcess(),&handle,PROCESS_ALL_ACCESS,
  +                    FALSE,0);
  +    if (isok)
  +        env->m->pinfo.hProcess = handle;
  +    else {
  +        DBPRINTF0("DuplicateHandle failed on Process\n");
  +        env->m->pinfo.hProcess = GetCurrentProcess();
  +    }
  +
  +
  +    isok = DuplicateHandle(GetCurrentProcess(),GetCurrentThread(),
  +                    GetCurrentProcess(),&handle,PROCESS_ALL_ACCESS,
  +                    FALSE,0);
  +    if (isok)
  +        env->m->pinfo.hThread = handle;
  +    else {
  +        DBPRINTF0("DuplicateHandle failed on Thread\n");
  +        env->m->pinfo.hThread = GetCurrentThread();
  +    }
       env->m->envp = envp;
  +
  +    DBPRINTF2("handles: proc %08x thread %08x\n",env->m->pinfo.hProcess,env->m->pinfo.hThread);
   
       SetProcessShutdownParameters(0x300, SHUTDOWN_NORETRY);
       if (argc > 1)
  
  
  

Mime
View raw message