commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r923066 - in /commons/proper/daemon/trunk/src/native/nt/procrun: apps/prunmgr/ apps/prunsrv/ include/ src/
Date Mon, 15 Mar 2010 06:01:51 GMT
Author: mturk
Date: Mon Mar 15 06:01:51 2010
New Revision: 923066

URL: http://svn.apache.org/viewvc?rev=923066&view=rev
Log:
Fix DAEMON-137, DAEMON-138 and DAEMON-139

Modified:
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.c
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.h
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.rc
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/nt/procrun/include/apxwin.h
    commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h
    commons/proper/daemon/trunk/src/native/nt/procrun/include/log.h
    commons/proper/daemon/trunk/src/native/nt/procrun/include/rprocess.h
    commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c
    commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c
    commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.c?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.c Mon Mar 15 06:01:51
2010
@@ -377,6 +377,8 @@ BOOL __generalLoggingSave(HWND hDlg)
     apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Path", szB);
     GetDlgItemTextW(hDlg, IDC_PPLGPREFIX,  szB, SIZ_DESMAX);
     apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"Prefix", szB);
+    GetDlgItemTextW(hDlg, IDC_PPLGPIDFILE,  szB, SIZ_DESMAX);
+    apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"PidFile", szB);
     GetDlgItemTextW(hDlg, IDC_PPLGSTDOUT,  szB, SIZ_DESMAX);
     apxRegistrySetStrW(hRegserv, APXREG_PARAMSOFTWARE, _s_log, L"StdOutput", szB);
     GetDlgItemTextW(hDlg, IDC_PPLGSTDERR,  szB, SIZ_DESMAX);
@@ -873,7 +875,12 @@ LRESULT CALLBACK __loggingProperty(HWND 
                     apxFree(b);
                 }
                 else
-                    SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, L"jakarta_service_");
+                    SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, L"commons-daemon");
+                if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
+                                               _s_log, L"PidFile")) != NULL) {
+                    SetDlgItemTextW(hDlg, IDC_PPLGPIDFILE, b);
+                    apxFree(b);
+                }
                 if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
                                                _s_log, L"StdOutput")) != NULL) {
                     SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, b);
@@ -906,6 +913,12 @@ LRESULT CALLBACK __loggingProperty(HWND 
                         SET_BIT_FLAG(_propertyChanged, 3);
                     }
                 break;
+                case IDC_PPLGPIDFILE:
+                    if (HIWORD(wParam) == EN_CHANGE) {
+                        PropSheet_Changed(GetParent(hDlg), hDlg);
+                        SET_BIT_FLAG(_propertyChanged, 3);
+                    }
+                break;
                 case IDC_PPLGSTDERR:
                     if (HIWORD(wParam) == EN_CHANGE) {
                         PropSheet_Changed(GetParent(hDlg), hDlg);

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.h?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.h Mon Mar 15 06:01:51
2010
@@ -24,7 +24,7 @@
 #define _PRUNMGR_H
 
 #undef  PRG_VERSION
-#define PRG_VERSION    "1.0.2.0" 
+#define PRG_VERSION    "1.0.3.0" 
 #define PRG_REGROOT   L"Apache Software Foundation\\Procrun 2.0"
 
 #define IDM_TM_EXIT                     2000
@@ -73,10 +73,11 @@
 #define IDC_PPLGPATH                    2642
 #define IDC_PPLGBPATH                   2643
 #define IDC_PPLGPREFIX                  2644
-#define IDC_PPLGSTDOUT                  2645
-#define IDC_PPLGBSTDOUT                 2646
-#define IDC_PPLGSTDERR                  2647
-#define IDC_PPLGBSTDERR                 2648
+#define IDC_PPLGPIDFILE                 2645
+#define IDC_PPLGSTDOUT                  2646
+#define IDC_PPLGBSTDOUT                 2647
+#define IDC_PPLGSTDERR                  2648
+#define IDC_PPLGBSTDERR                 2649
 
 #define IDD_PROPPAGE_JVM                2660
 #define IDC_PPJAUTO                     2661

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.rc
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.rc?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.rc (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.rc Mon Mar 15 06:01:51
2010
@@ -138,13 +138,16 @@ BEGIN
     PUSHBUTTON      "...",IDC_PPLGBPATH,232,44,18,14 
     LTEXT           "Log prefix: ",IDC_STATIC,10,63,50,8
     EDITTEXT        IDC_PPLGPREFIX,70,62,158,12,ES_AUTOHSCROLL
+
+    LTEXT           "Pid file: ",IDC_STATIC,10,81,50,8
+    EDITTEXT        IDC_PPLGPIDFILE,70,82,158,12,ES_AUTOHSCROLL
     
-    LTEXT           "Redirect Stdout: ",IDC_STATIC,10,85,80,8
-    EDITTEXT        IDC_PPLGSTDOUT,10,97,218,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",IDC_PPLGBSTDOUT,232,96,18,14 
-    LTEXT           "Redirect Stderror: ",IDC_STATIC,10,115,80,8
-    EDITTEXT        IDC_PPLGSTDERR,10,127,218,12,ES_AUTOHSCROLL
-    PUSHBUTTON      "...",IDC_PPLGBSTDERR,232,126,18,14 
+    LTEXT           "Redirect Stdout: ",IDC_STATIC,10,105,80,8
+    EDITTEXT        IDC_PPLGSTDOUT,10,117,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPLGBSTDOUT,232,116,18,14 
+    LTEXT           "Redirect Stderror: ",IDC_STATIC,10,135,80,8
+    EDITTEXT        IDC_PPLGSTDERR,10,147,218,12,ES_AUTOHSCROLL
+    PUSHBUTTON      "...",IDC_PPLGBSTDERR,232,146,18,14 
 END
 
 IDD_PROPPAGE_JVM DIALOGEX 0, 0, 260, 186

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c Mon Mar 15 06:01:51
2010
@@ -51,10 +51,8 @@ typedef struct APX_STDWRAP {
     LPCWSTR szLogPath;
     LPCWSTR szStdOutFilename;
     LPCWSTR szStdErrFilename;
-    HANDLE  hStdOutFile;
-    HANDLE  hStdErrFile;
-    int     fdStdOutFile;
-    int     fdStdErrFile;
+    FILE   *fpStdOutFile;
+    FILE   *fpStdErrFile;
 } APX_STDWRAP;
 
 /* Use static variables instead of #defines */
@@ -123,6 +121,8 @@ static APXCMDLINEOPT _options[] = {
 /* 33 */    { L"LogLevel",          L"Level",           L"Log",         APXCMDOPT_STR | APXCMDOPT_REG,
NULL, 0},
 /* 34 */    { L"StdError",          L"StdError",        L"Log",         APXCMDOPT_STE | APXCMDOPT_REG,
NULL, 0},
 /* 35 */    { L"StdOutput",         L"StdOutput",       L"Log",         APXCMDOPT_STE | APXCMDOPT_REG,
NULL, 0},
+/* 36 */    { L"LogJniMessages",    L"LogJniMessages",  L"Log",         APXCMDOPT_INT | APXCMDOPT_REG,
NULL, 1},
+/* 37 */    { L"PidFile",           L"PidFile",         L"Log",         APXCMDOPT_STR | APXCMDOPT_REG,
NULL, 0},
             /* NULL terminate the array */
             { NULL }
 };
@@ -182,6 +182,8 @@ static APXCMDLINEOPT _options[] = {
 
 #define SO_STDERROR         GET_OPT_V(34)
 #define SO_STDOUTPUT        GET_OPT_V(35)
+#define SO_JNIVFPRINTF      GET_OPT_I(36)
+#define SO_PIDFILE          GET_OPT_V(37)
 
 /* Main servic table entry
  * filled at run-time
@@ -222,6 +224,8 @@ static LPSTR    _jni_sclass             
 static HANDLE gShutdownEvent = NULL;
 static HANDLE gSignalEvent   = NULL;
 static HANDLE gSignalThread  = NULL;
+static HANDLE gPidfileHandle = NULL;
+static LPWSTR gPidfileName   = NULL;
 static BOOL   gSignalValid   = TRUE;
 
 DWORD WINAPI eventThread(LPVOID lpParam)
@@ -250,91 +254,51 @@ static BOOL redirectStdStreams(APX_STDWR
     BOOL aErr = FALSE;
     BOOL aOut = FALSE;
 
+    if (lpWrapper->szStdOutFilename || lpWrapper->szStdErrFilename)
+        AllocConsole();
     /* redirect to file or console */
     if (lpWrapper->szStdOutFilename) {
         if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
             aOut = TRUE;
             lpWrapper->szStdOutFilename = apxLogFile(gPool,
                                                      lpWrapper->szLogPath,
-                                                     L"stdout_",
-                                                     NULL);
+                                                     L"service-stdout",
+                                                     NULL, TRUE);
         }
         /* Delete the file if not in append mode
          * XXX: See if we can use the params instead of that.
          */
         if (!aOut)
             DeleteFileW(lpWrapper->szStdOutFilename);
-        lpWrapper->hStdOutFile = CreateFileW(lpWrapper->szStdOutFilename,
-                                             GENERIC_WRITE,
-                                             FILE_SHARE_READ | FILE_SHARE_WRITE,
-                                             NULL,
-                                             OPEN_ALWAYS,
-                                             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH
| FILE_FLAG_SEQUENTIAL_SCAN,
-                                             NULL);
-        if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
-            return FALSE;
-        /* Allways move to the end of file */
-        SetFilePointer(lpWrapper->hStdOutFile, 0, NULL, FILE_END);
-    }
-    else {
-        lpWrapper->hStdOutFile = CreateFileW(L"CONOUT$",
-                                             GENERIC_WRITE,
-                                             FILE_SHARE_READ | FILE_SHARE_WRITE,
-                                             NULL,
-                                             OPEN_EXISTING,
-                                             0,
-                                             NULL);
-        if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
-            return FALSE;
+        if ((lpWrapper->fpStdOutFile = _wfopen(lpWrapper->szStdOutFilename,
+                                               L"a"))) {
+            _dup2(_fileno(lpWrapper->fpStdOutFile), 1);
+            *stdout = *lpWrapper->fpStdOutFile;
+            setvbuf(stdout, NULL, _IONBF, 0);
+        }
     }
     if (lpWrapper->szStdErrFilename) {
         if (lstrcmpiW(lpWrapper->szStdErrFilename, PRSRV_AUTO) == 0) {
             aErr = TRUE;
             lpWrapper->szStdErrFilename = apxLogFile(gPool,
                                                      lpWrapper->szLogPath,
-                                                     L"stderr_",
-                                                     NULL);
+                                                     L"service-stderr",
+                                                     NULL, TRUE);
         }
         if (!aErr)
             DeleteFileW(lpWrapper->szStdErrFilename);
-        lpWrapper->hStdErrFile = CreateFileW(lpWrapper->szStdErrFilename,
-                                             GENERIC_WRITE,
-                                             FILE_SHARE_READ | FILE_SHARE_WRITE,
-                                             NULL,
-                                             OPEN_ALWAYS,
-                                             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH
| FILE_FLAG_SEQUENTIAL_SCAN,
-                                             NULL);
-        if (IS_INVALID_HANDLE(lpWrapper->hStdErrFile))
-            return FALSE;
-        SetFilePointer(lpWrapper->hStdErrFile, 0, NULL, FILE_END);
-    }
-    else if (lpWrapper->szStdOutFilename) {
-        /* Use the same file handle for stderr as for stdout */
-        lpWrapper->szStdErrFilename = lpWrapper->szStdOutFilename;
-        lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
-    }
-    else {
-        lpWrapper->hStdErrFile = lpWrapper->hStdOutFile;
-    }
-    /* Open the stream buffers
-     * This will redirect all printf to go to the redirected files.
-     * It is used for JNI vprintf functionality.
-     */
-    lpWrapper->fdStdOutFile = _open_osfhandle((ptrdiff_t)lpWrapper->hStdOutFile,
-                                              _O_WRONLY | _O_TEXT);
-    if (lpWrapper->fdStdOutFile > 0) {
-        lpWrapper->fdStdOutFile = dup2(lpWrapper->fdStdOutFile, 1);
-        if (lpWrapper->fdStdOutFile > 0)
-            setvbuf(stdout, NULL, _IONBF, 0);
-    }
-    lpWrapper->fdStdErrFile = _open_osfhandle((ptrdiff_t)lpWrapper->hStdErrFile,
-                                              _O_WRONLY | _O_TEXT);
-    if (lpWrapper->fdStdErrFile > 0) {
-        lpWrapper->fdStdErrFile = dup2(lpWrapper->fdStdErrFile, 2);
-        if (lpWrapper->fdStdErrFile > 0)
+        if ((lpWrapper->fpStdErrFile = _wfopen(lpWrapper->szStdErrFilename,
+                                              L"a"))) {
+            _dup2(_fileno(lpWrapper->fpStdErrFile), 2);
+            *stderr = *lpWrapper->fpStdErrFile;
             setvbuf(stderr, NULL, _IONBF, 0);
+        }
+    }
+    else if (lpWrapper->fpStdOutFile) {
+        _dup2(_fileno(lpWrapper->fpStdOutFile), 2);
+        *stderr = *lpWrapper->fpStdOutFile;
+         setvbuf(stderr, NULL, _IONBF, 0);
     }
-
     return TRUE;
 }
 
@@ -818,7 +782,7 @@ static DWORD WINAPI serviceStop(LPVOID l
             return 1;
         }
         if (!apxJavaInitialize(hWorker, _jni_classpath, _jni_jvmoptions,
-                               SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
+                               SO_JVMMS, SO_JVMMX, SO_JVMSS, SO_JNIVFPRINTF)) {
             rv = 2;
             apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
             goto cleanup;
@@ -971,6 +935,14 @@ static DWORD serviceStart()
         apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
         return TRUE;    /* Nothing to do */
     }
+    if (SO_PIDFILE) {
+        gPidfileName = apxLogFile(gPool, SO_LOGPATH, SO_PIDFILE, NULL, FALSE);
+        if (GetFileAttributesW(gPidfileName) !=  INVALID_FILE_ATTRIBUTES) {
+            /* Pid file exists */
+            apxLogWrite(APXLOG_MARK_ERROR "Pid file '%S' exists", gPidfileName);
+            return 1;
+        }
+    }
     GetSystemTimeAsFileTime(&fts);
     if (_jni_startup) {
         if (SO_STARTPATH) {
@@ -986,7 +958,7 @@ static DWORD serviceStart()
             return 1;
         }
         if (!apxJavaInitialize(gWorker, _jni_classpath, _jni_jvmoptions,
-                               SO_JVMMS, SO_JVMMX, SO_JVMSS)) {
+                               SO_JVMMS, SO_JVMMX, SO_JVMSS, SO_JNIVFPRINTF)) {
             rv = 2;
             apxLogWrite(APXLOG_MARK_ERROR "Failed initializing java %s", _jni_classpath);
             goto cleanup;
@@ -1060,6 +1032,27 @@ static DWORD serviceStart()
         FILETIME fte;
         ULARGE_INTEGER s, e;
         DWORD    nms;
+        /* Create pidfile */
+        if (gPidfileName) {
+            char pids[32];
+            gPidfileHandle = CreateFileW(gPidfileName,
+                                         GENERIC_READ | GENERIC_WRITE,
+                                         FILE_SHARE_READ,
+                                         NULL,
+                                         CREATE_NEW,
+                                         FILE_ATTRIBUTE_NORMAL,
+                                         NULL);
+
+            if (gPidfileHandle != INVALID_HANDLE_VALUE) {
+                DWORD wr = 0;
+                if (_jni_startup)
+                    _snprintf(pids, 32, "%d\r\n", GetCurrentProcessId());
+                else
+                    _snprintf(pids, 32, "%d\r\n", apxProcessGetPid(gWorker));
+                WriteFile(gPidfileHandle, pids, (DWORD)strlen(pids), &wr, NULL);
+                FlushFileBuffers(gPidfileName);
+            }
+        }
         GetSystemTimeAsFileTime(&fte);
         s.LowPart  = fts.dwLowDateTime;
         s.HighPart = fts.dwHighDateTime;
@@ -1322,7 +1315,9 @@ BOOL docmdDebugService(LPAPXCMDLINE lpCm
     apxLogWrite(APXLOG_MARK_INFO "Debugging Service...");
     serviceMain(0, NULL);
     apxLogWrite(APXLOG_MARK_INFO "Debug service finished.");
-
+    SAFE_CLOSE_HANDLE(gPidfileHandle);
+    if (gPidfileName)
+        DeleteFileW(gPidfileName);
     return rv;
 }
 
@@ -1337,6 +1332,9 @@ BOOL docmdRunService(LPAPXCMDLINE lpCmdl
     _service_table[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTIONW)serviceMain;
     rv = (StartServiceCtrlDispatcherW(_service_table) == FALSE);
     apxLogWrite(APXLOG_MARK_INFO "Run service finished.");
+    SAFE_CLOSE_HANDLE(gPidfileHandle);
+    if (gPidfileName)
+        DeleteFileW(gPidfileName);
     return rv;
 }
 
@@ -1390,6 +1388,18 @@ void __cdecl main(int argc, char **argv)
         gStdwrap.szStdErrFilename = SO_STDERROR;
     }
     redirectStdStreams(&gStdwrap);
+    if (lpCmdline->dwCmdIndex == 2) {
+        SYSTEMTIME t;
+        GetLocalTime(&t);
+        fprintf(stdout, "\n%d-%02d-%02d %02d:%02d:%02d "
+                        "Commons Daemon procrun stdout initialized\n",
+                        t.wYear, t.wMonth, t.wDay,
+                        t.wHour, t.wMinute, t.wSecond);
+        fprintf(stderr, "\n%d-%02d-%02d %02d:%02d:%02d "
+                        "Commons Daemon procrun stderr initialized\n",
+                        t.wYear, t.wMonth, t.wDay,
+                        t.wHour, t.wMinute, t.wSecond);
+    }
     switch (lpCmdline->dwCmdIndex) {
         case 1: /* Run Service as console application */
             if (!docmdDebugService(lpCmdline))

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/include/apxwin.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/include/apxwin.h?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/include/apxwin.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/include/apxwin.h Mon Mar 15 06:01:51
2010
@@ -95,6 +95,8 @@ typedef _W64 int            intptr_t;
 #define SIZ_DESMAX         (SIZ_DESLEN -1)
 #define SIZ_HUGLEN         8192
 #define SIZ_HUGMAX         (SIZ_HUGLEN -1)
+#define SIZ_PATHLEN        4096
+#define SIZ_PATHMAX        4095
 
 #include "handles.h"
 #include "log.h"

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/include/javajni.h Mon Mar 15 06:01:51
2010
@@ -25,7 +25,7 @@ APXHANDLE   apxCreateJava(APXHANDLE hPoo
 
 BOOL        apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
                               LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
-                              DWORD dwSs);
+                              DWORD dwSs, DWORD bJniVfprintf);
 DWORD
 apxJavaCmdInitialize(APXHANDLE hPool, LPCWSTR szClassPath, LPCWSTR szClass,
                      LPCWSTR szOptions, DWORD dwMs, DWORD dwMx,

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/include/log.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/include/log.h?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/include/log.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/include/log.h Mon Mar 15 06:01:51 2010
@@ -13,8 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
-/* Logfile handling 
+
+/* Logfile handling
  * Use Systemdir/Logfiles/Apache as a default path
  */
 
@@ -54,7 +54,8 @@ LPWSTR apxLogFile(
     APXHANDLE hPool,
     LPCWSTR szPath,
     LPCWSTR szPrefix,
-    LPCWSTR szName
+    LPCWSTR szName,
+    BOOL bTimeStamp
 );
 
 HANDLE apxLogOpen(

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/include/rprocess.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/include/rprocess.h?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/include/rprocess.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/include/rprocess.h Mon Mar 15 06:01:51
2010
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #ifndef _RPROCESS_H_INCLUDED_
 #define _RPROCESS_H_INCLUDED_
 
@@ -69,6 +69,7 @@ DWORD       apxProcessWait(APXHANDLE hPr
                            BOOL bKill);
 
 BOOL        apxProcessRunning(APXHANDLE hProcess);
+DWORD       apxProcessGetPid(APXHANDLE hProcess);
 
 
 __APXEND_DECLS

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c Mon Mar 15 06:01:51 2010
@@ -183,10 +183,10 @@ static BOOL __apxLoadJvmDll(LPCWSTR szJv
                                               LOAD_WITH_ALTERED_SEARCH_PATH);
 
     if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
-        WCHAR  jreBinPath[1024];
+        WCHAR  jreBinPath[SIZ_PATHLEN];
         DWORD  i, l = 0;
 
-        lstrlcpyW(jreBinPath, 1024, dllJvmPath);
+        lstrlcpyW(jreBinPath, SIZ_PATHLEN, dllJvmPath);
         DYNLOAD_FPTR_ADDRESS(SetDllDirectoryW, KERNEL32);
         for (i = lstrlenW(jreBinPath); i > 0, l < 2; i--) {
             if (jreBinPath[i] == L'\\' || jreBinPath[i] == L'/') {
@@ -375,12 +375,12 @@ static jint JNICALL __apxJniVfprintf(FIL
 BOOL
 apxJavaInitialize(APXHANDLE hJava, LPCSTR szClassPath,
                   LPCVOID lpOptions, DWORD dwMs, DWORD dwMx,
-                  DWORD dwSs)
+                  DWORD dwSs, DWORD bJniVfprintf)
 {
     LPAPXJAVAVM     lpJava;
     JavaVMInitArgs  vmArgs;
     JavaVMOption    *lpJvmOptions;
-    DWORD           i, nOptions, sOptions = 2;
+    DWORD           i, nOptions, sOptions = 1;
     BOOL            rv = FALSE;
     if (hJava->dwType != APXHANDLE_TYPE_JVM)
         return FALSE;
@@ -408,6 +408,7 @@ apxJavaInitialize(APXHANDLE hJava, LPCST
         rv = TRUE;
     }
     else {
+        int   o = 0;
         CHAR  iB[3][64];
         LPSTR szCp;
         lpJava->iVersion = JNI_VERSION_DEFAULT;
@@ -417,6 +418,8 @@ apxJavaInitialize(APXHANDLE hJava, LPCST
             ++sOptions;
         if (dwSs)
             ++sOptions;
+        if (bJniVfprintf)
+            ++sOptions;
         nOptions = __apxMultiSzToJvmOptions(hJava->hPool, lpOptions,
                                             &lpJvmOptions, sOptions);
         szCp = apxPoolAlloc(hJava->hPool, sizeof(JAVA_CLASSPATH) + lstrlenA(szClassPath));
@@ -424,27 +427,33 @@ apxJavaInitialize(APXHANDLE hJava, LPCST
         lstrcatA(szCp, szClassPath);
         lpJvmOptions[nOptions - sOptions].optionString = szCp;
         --sOptions;
-        /* default JNI error printer */
-        lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
-        lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniVfprintf;
-        --sOptions;
+        if (bJniVfprintf) {
+            /* default JNI error printer */
+            lpJvmOptions[nOptions - sOptions].optionString = "vfprintf";
+            lpJvmOptions[nOptions - sOptions].extraInfo    = __apxJniVfprintf;
+            --sOptions;
+            apxLogWrite(APXLOG_MARK_DEBUG "Adding JNI vfprintf hook");
+        }
         if (dwMs) {
             wsprintfA(iB[0], "-Xms%dm", dwMs);
             lpJvmOptions[nOptions - sOptions].optionString = iB[0];
             --sOptions;
+            apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", o++, iB[0]);
         }
         if (dwMx) {
             wsprintfA(iB[1], "-Xmx%dm", dwMx);
             lpJvmOptions[nOptions - sOptions].optionString = iB[1];
             --sOptions;
+            apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", o++, iB[1]);
         }
         if (dwSs) {
             wsprintfA(iB[2], "-Xss%dk", dwSs);
             lpJvmOptions[nOptions - sOptions].optionString = iB[2];
             --sOptions;
+            apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", o++, iB[2]);
         }
         for (i = 0; i < nOptions; i++) {
-            apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", i,
+            apxLogWrite(APXLOG_MARK_DEBUG "Jvm Option[%d] %s", o++,
                         lpJvmOptions[i].optionString);
         }
         vmArgs.options  = lpJvmOptions;

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/log.c Mon Mar 15 06:01:51 2010
@@ -18,6 +18,7 @@
 #include "private.h"
 
 #define LINE_SEP    "\n"
+#define LOGF_EXT    L".%04d-%02d-%02d.log"
 
 static LPCSTR _log_level[] = {
     "[debug] ",
@@ -32,7 +33,7 @@ typedef struct apx_logfile_st {
     DWORD       dwLogLevel;
     BOOL        bRotate;
     SYSTEMTIME  sysTime;
-    WCHAR       szPath[MAX_PATH + 1];
+    WCHAR       szPath[SIZ_PATHLEN];
     WCHAR       szPrefix[MAX_PATH];
 } apx_logfile_st;
 
@@ -46,11 +47,12 @@ LPWSTR apxLogFile(
     APXHANDLE hPool,
     LPCWSTR szPath,
     LPCWSTR szPrefix,
-    LPCWSTR szName)
+    LPCWSTR szName,
+    BOOL bTimeStamp)
 {
     LPWSTR sRet;
-    WCHAR sPath[MAX_PATH+1];
-    WCHAR sName[MAX_PATH+1];
+    WCHAR sPath[SIZ_PATHLEN];
+    WCHAR sName[SIZ_PATHLEN];
     SYSTEMTIME sysTime;
 
     GetLocalTime(&sysTime);
@@ -66,20 +68,26 @@ LPWSTR apxLogFile(
         szPrefix = L"";
     if (!szName)
         szName   = L"";
-    wsprintfW(sName,
-              L"\\%s%s%04d%02d%02d.log",
-              szPrefix,
-              szName,
-              sysTime.wYear,
-              sysTime.wMonth,
-              sysTime.wDay);
+    if (bTimeStamp)
+        wsprintfW(sName,
+                  L"\\%s%s" LOGF_EXT,
+                  szPrefix,
+                  szName,
+                  sysTime.wYear,
+                  sysTime.wMonth,
+                  sysTime.wDay);
+    else
+        wsprintfW(sName,
+                  L"\\%s%s",
+                  szPrefix,
+                  szName);
 
-    sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
+    sRet = apxPoolAlloc(hPool, (SIZ_PATHLEN) * sizeof(WCHAR));
     /* Set default level to info */
     CreateDirectoryW(sPath, NULL);
 
-    lstrlcpyW(sRet, MAX_PATH, sPath);
-    lstrlcatW(sRet, MAX_PATH, sName);
+    lstrlcpyW(sRet, SIZ_PATHMAX, sPath);
+    lstrlcatW(sRet, SIZ_PATHMAX, sName);
 
     return sRet;
 }
@@ -94,8 +102,8 @@ HANDLE apxLogOpen(
     LPCWSTR szPrefix)
 {
 
-    WCHAR sPath[MAX_PATH+1];
-    WCHAR sName[MAX_PATH+1];
+    WCHAR sPath[SIZ_PATHLEN];
+    WCHAR sName[SIZ_PATHLEN];
     SYSTEMTIME sysTime;
     apx_logfile_st *h;
 
@@ -109,8 +117,8 @@ HANDLE apxLogOpen(
         lstrlcpyW(sPath, MAX_PATH, szPath);
     }
     if (!szPrefix)
-        szPrefix = L"jakarta_service_";
-    wsprintfW(sName, L"\\%s%04d%02d%02d.log",
+        szPrefix = L"commons-daemon";
+    wsprintfW(sName, L"\\%s"  LOGF_EXT,
               szPrefix,
               sysTime.wYear,
               sysTime.wMonth,
@@ -184,7 +192,7 @@ void apxLogLevelSetW(HANDLE  hFile,
 static BOOL apx_log_rotate(apx_logfile_st *l,
                            LPSYSTEMTIME lpCtime)
 {
-    WCHAR sPath[MAX_PATH+1];
+    WCHAR sPath[SIZ_PATHLEN];
 
     /* rotate on daily basis */
     if (l->sysTime.wDay == lpCtime->wDay)
@@ -193,7 +201,7 @@ static BOOL apx_log_rotate(apx_logfile_s
     CloseHandle(l->hFile);
     l->sysTime = *lpCtime;
 
-    wsprintfW(sPath, L"%s\\%s%04d%02d%02d.log",
+    wsprintfW(sPath, L"%s\\%s"  LOGF_EXT,
               l->szPath,
               l->szPrefix,
               l->sysTime.wYear,
@@ -226,7 +234,7 @@ apxLogWrite(
     LPSTR   szBp;
     int     len = 0;
     LPCSTR  f = szFile;
-    CHAR    sb[MAX_PATH+1];
+    CHAR    sb[SIZ_PATHLEN];
     DWORD   wr;
     DWORD   err;
     BOOL    dolock = TRUE;
@@ -345,8 +353,8 @@ apxDisplayError(
     ...)
 {
     va_list args;
-    CHAR    buffer[1024+32];
-    CHAR    sysbuf[2048];
+    CHAR    buffer[SIZ_HUGLEN];
+    CHAR    sysbuf[SIZ_HUGLEN];
     int     len = 0, nRet;
     LPCSTR  f = szFile;
     DWORD   err = GetLastError(); /* save the last Error code */
@@ -365,7 +373,7 @@ apxDisplayError(
                              err,
                              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                              sysbuf,
-                             1000,
+                             SIZ_DESLEN,
                              NULL);
         sysbuf[len] = 0;
     }
@@ -374,12 +382,12 @@ apxDisplayError(
         wvsprintfA(buffer, szFormat, args);
         va_end(args);
         if (f) {
-            CHAR sb[MAX_PATH+1];
+            CHAR sb[SIZ_PATHLEN];
             wsprintfA(sb, "\n%s (%d)", f, dwLine);
             lstrcatA(sysbuf, sb);
         }
-        lstrlcatA(sysbuf, 2048, "\n");
-        lstrlcatA(sysbuf, 2048, buffer);
+        lstrlcatA(sysbuf, SIZ_HUGLEN, "\n");
+        lstrlcatA(sysbuf, SIZ_HUGLEN, buffer);
     }
     len = lstrlenA(sysbuf);
 #ifdef _DEBUG_FULL

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c?rev=923066&r1=923065&r2=923066&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/rprocess.c Mon Mar 15 06:01:51 2010
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #include "apxwin.h"
 #include "private.h"
 
@@ -24,7 +24,7 @@
 #define CHILD_TERMINATE_CODE        19640323 /* Could be any value like my birthday ;-)*/
 
 DYNOLAD_TYPE_DECLARE(CreateRemoteThread,
-                     __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES, 
+                     __stdcall, HANDLE)(HANDLE, LPSECURITY_ATTRIBUTES,
                                         DWORD, LPTHREAD_START_ROUTINE,
                                         LPVOID, DWORD, LPDWORD);
 
@@ -83,13 +83,13 @@ typedef struct APXPROCESS {
     HANDLE                  hChildInpWr;
     HANDLE                  hChildOutRd;
     HANDLE                  hChildErrRd;
-    /* Saved console pipes */    
+    /* Saved console pipes */
     HANDLE                  hParentStdSave[3];
     HANDLE                  hWorkerThreads[3];
     HANDLE                  hUserToken;
     HANDLE                  hCurrentProcess;
     BOOL                    bSaveHandles;
-    /** callback function */ 
+    /** callback function */
     LPAPXFNCALLBACK         fnUserCallback;
     LPSECURITY_ATTRIBUTES   lpSA;
     LPVOID                  lpSD;
@@ -135,13 +135,13 @@ static DWORD WINAPI __apxProcStdoutThrea
     LPAPXPROCESS lpProc;
     APXCALLHOOK *lpCall;
     INT ch;
-    DWORD dwReaded; 
+    DWORD dwReaded;
     lpProc = APXHANDLE_DATA(hProcess);
     while (lpProc->dwChildStatus & CHILD_RUNNING) {
         ch = 0;
         if (!ReadFile(lpProc->hChildOutRd, &ch, lpProc->chSize,
                       &dwReaded, NULL) || !dwReaded) {
-            
+
             break;
         }
         if (lpProc->fnUserCallback)
@@ -162,7 +162,7 @@ static DWORD WINAPI __apxProcStderrThrea
     LPAPXPROCESS lpProc;
     APXCALLHOOK *lpCall;
     INT ch;
-    DWORD dwReaded; 
+    DWORD dwReaded;
     lpProc = APXHANDLE_DATA(hProcess);
     while (lpProc->dwChildStatus & CHILD_RUNNING) {
         if (!ReadFile(lpProc->hChildErrRd, &ch, lpProc->chSize,
@@ -193,7 +193,7 @@ static DWORD __apxProcessPutc(LPAPXPROCE
             return 1;
         }
     }
-    
+
     return 0;
 }
 
@@ -221,7 +221,7 @@ static DWORD __apxProcessPuts(LPAPXPROCE
                 break;
         }
     }
-    
+
     return n;
 }
 
@@ -231,7 +231,7 @@ static DWORD __apxProcessWrite(LPAPXPROC
     DWORD  n = 0;
     if (!lpData || !dwLen)
         return 0;
-    
+
     if (lpProc->dwChildStatus & CHILD_RUNNING) {
         DWORD wr = 0;
         while (lpProc->dwChildStatus & CHILD_RUNNING) {
@@ -249,7 +249,7 @@ static DWORD __apxProcessWrite(LPAPXPROC
                 break;
         }
     }
-    
+
     return n;
 }
 
@@ -316,33 +316,33 @@ static BOOL __apxProcessClose(APXHANDLE 
 
     lpProc = APXHANDLE_DATA(hProcess);
     CHECK_IF_ACTIVE(lpProc);
-    
+
     /* Try to close the child's stdin first */
     SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
-    /* Wait 1 sec for child process to 
+    /* Wait 1 sec for child process to
      * recognize that the stdin has been closed.
      */
     if (WaitForSingleObject(lpProc->stProcInfo.hProcess, 1000) == WAIT_OBJECT_0)
         goto cleanup;
 
     CHECK_IF_ACTIVE(lpProc);
-    
+
     /* Try to create the remote thread in the child address space */
     DYNLOAD_FPTR_ADDRESS(CreateRemoteThread, KERNEL32);
-    if (DuplicateHandle(lpProc->hCurrentProcess, 
-                        lpProc->stProcInfo.hProcess, 
-                        lpProc->hCurrentProcess, 
-                        &hDup, 
-                        PROCESS_ALL_ACCESS, 
+    if (DuplicateHandle(lpProc->hCurrentProcess,
+                        lpProc->stProcInfo.hProcess,
+                        lpProc->hCurrentProcess,
+                        &hDup,
+                        PROCESS_ALL_ACCESS,
                         FALSE, 0)) {
         DYNLOAD_FPTR_ADDRESS(ExitProcess, KERNEL32);
         /* Now call the ExitProcess from inside the client
          * This will safely unload all the dll's.
          */
-        hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup, 
-                                NULL, 0, 
+        hRemote = DYNLOAD_CALL(CreateRemoteThread)(hDup,
+                                NULL, 0,
                                 (LPTHREAD_START_ROUTINE)DYNLOAD_FPTR(ExitProcess),
-                                (PVOID)&uExitCode, 0, NULL); 
+                                (PVOID)&uExitCode, 0, NULL);
         if (!IS_INVALID_HANDLE(hRemote)) {
             if (WaitForSingleObject(lpProc->stProcInfo.hProcess,
                     2000) == WAIT_OBJECT_0) {
@@ -356,9 +356,9 @@ static BOOL __apxProcessClose(APXHANDLE 
         CloseHandle(hDup);
         goto cleanup;
     }
-  
+
     TerminateProcess(lpProc->stProcInfo.hProcess, CHILD_TERMINATE_CODE);
-    
+
 cleanup:
      /* Close the process handle */
     SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
@@ -384,8 +384,8 @@ static BOOL __apxProcessCallback(APXHAND
             }
             SAFE_CLOSE_HANDLE(lpProc->stProcInfo.hProcess);
 
-            /* Close parent side of the pipes */    
-            SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);  
+            /* Close parent side of the pipes */
+            SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
             SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
             SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
 
@@ -401,7 +401,7 @@ static BOOL __apxProcessCallback(APXHAND
             if (lpProc->lpEnvironment)
                 FreeEnvironmentStringsW(lpProc->lpEnvironment);
 
-        case WM_QUIT: 
+        case WM_QUIT:
             /* The process has finished
              * This is a WorkerThread message
              */
@@ -414,7 +414,7 @@ static BOOL __apxProcessCallback(APXHAND
             if (wParam)
                 __apxProcessWrite(lpProc, (LPCVOID)lParam, (DWORD)wParam);
             else
-                __apxProcessPuts(lpProc, (LPCTSTR)lParam);            
+                __apxProcessPuts(lpProc, (LPCTSTR)lParam);
         break;
         default:
         break;
@@ -439,8 +439,8 @@ apxCreateProcessW(APXHANDLE hPool, DWORD
 #ifndef _UNICODE
         WCHAR wsUsername[256];
         WCHAR wsPassword[256];
-        AsciiToWide(szUsername, wsUsername); 
-        AsciiToWide(szPassword, wsPassword); 
+        AsciiToWide(szUsername, wsUsername);
+        AsciiToWide(szPassword, wsPassword);
 #else
         LPCWSTR wsUsername = szUsername;
         LPCWSTR wsPassword = szPassword;
@@ -459,8 +459,8 @@ apxCreateProcessA(APXHANDLE hPool, DWORD
     if (szUsername && szPassword) {
         WCHAR wsUsername[256];
         WCHAR wsPassword[256];
-        AsciiToWide(szUsername, wsUsername); 
-        AsciiToWide(szPassword, wsPassword); 
+        AsciiToWide(szUsername, wsUsername);
+        AsciiToWide(szPassword, wsPassword);
         return apxCreateProcessW(hPool, dwOptions, fnCallback,
                                  wsUsername, wsPassword, bLogonAsService);
     }
@@ -481,9 +481,9 @@ apxCreateProcessW(APXHANDLE hPool, DWORD
     /* CreateProcessAsUser is supported only on NT */
     if (szUsername && (APX_GET_OSLEVEL() >= APX_WINVER_NT_4)) {
         HANDLE hUser;
-        if (!LogonUserW(szUsername, 
-                        NULL, 
-                        szPassword, 
+        if (!LogonUserW(szUsername,
+                        NULL,
+                        szPassword,
                         bLogonAsService ? LOGON32_LOGON_SERVICE : LOGON32_LOGON_NETWORK,
                         LOGON32_PROVIDER_DEFAULT,
                         &hUser)) {
@@ -491,8 +491,8 @@ apxCreateProcessW(APXHANDLE hPool, DWORD
             ErrorMessage(NULL, TRUE);
             return NULL;
         }
-        if (!DuplicateTokenEx(hUser, 
-                              TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY, 
+        if (!DuplicateTokenEx(hUser,
+                              TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY,
                               NULL,
                               SecurityImpersonation,
                               TokenPrimary,
@@ -534,7 +534,7 @@ apxCreateProcessW(APXHANDLE hPool, DWORD
                     &lpProc->hCurrentProcess,
                     PROCESS_ALL_ACCESS,
                     FALSE,
-                    0); 
+                    0);
 #else
     lpProc->hCurrentProcess = GetCurrentProcess();
 #endif
@@ -551,7 +551,7 @@ apxCreateProcessW(APXHANDLE hPool, DWORD
     return hProcess;
 }
 
-static WCHAR _desktop_name[] = 
+static WCHAR _desktop_name[] =
     {'W', 'i', 'n', 's', 't', 'a', '0', '\\', 'D', 'e', 'f', 'a', 'u', 'l', 't', 0};
 
 BOOL
@@ -564,7 +564,7 @@ apxProcessExecute(APXHANDLE hProcess)
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     /* don't allow multiple execute calls on the same object */
     if (lpProc->dwChildStatus & PROC_INITIALIZED)
@@ -582,7 +582,7 @@ apxProcessExecute(APXHANDLE hProcess)
     /* Set the redirected handles */
     si.hStdOutput = lpProc->hChildStdOut;
     si.hStdError  = lpProc->hChildStdErr;
-    si.hStdInput  = lpProc->hChildStdInp;  
+    si.hStdInput  = lpProc->hChildStdInp;
 
     if (lpProc->lpEnvironment)
         FreeEnvironmentStringsW(lpProc->lpEnvironment);
@@ -618,7 +618,7 @@ apxProcessExecute(APXHANDLE hProcess)
                             &(lpProc->stProcInfo));
     }
     /* Close unused sides of pipes */
-    SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);  
+    SAFE_CLOSE_HANDLE(lpProc->hChildStdInp);
     SAFE_CLOSE_HANDLE(lpProc->hChildStdOut);
     SAFE_CLOSE_HANDLE(lpProc->hChildStdErr);
     if (!bS)
@@ -627,10 +627,10 @@ apxProcessExecute(APXHANDLE hProcess)
     lpProc->dwChildStatus |= (CHILD_RUNNING | PROC_INITIALIZED);
 
     lpProc->hWorkerThreads[0] = CreateThread(NULL, 0, __apxProcStdoutThread,
-                                             hProcess, 0, &id);     
+                                             hProcess, 0, &id);
     lpProc->hWorkerThreads[1] = CreateThread(NULL, 0, __apxProcStderrThread,
-                                             hProcess, 0, &id);     
-    ResumeThread(lpProc->stProcInfo.hThread);    
+                                             hProcess, 0, &id);
+    ResumeThread(lpProc->stProcInfo.hThread);
     lpProc->hWorkerThreads[2] = CreateThread(NULL, 0, __apxProcWorkerThread,
                                             hProcess, 0, &id);
 
@@ -638,8 +638,8 @@ apxProcessExecute(APXHANDLE hProcess)
     /* Close child handles first */
     return TRUE;
 cleanup:
-    /* Close parent side of the pipes */    
-    SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);  
+    /* Close parent side of the pipes */
+    SAFE_CLOSE_HANDLE(lpProc->hChildInpWr);
     SAFE_CLOSE_HANDLE(lpProc->hChildOutRd);
     SAFE_CLOSE_HANDLE(lpProc->hChildErrRd);
 
@@ -653,7 +653,7 @@ apxProcessSetExecutableA(APXHANDLE hProc
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     apxFree(lpProc->szApplicationExec);
     lpProc->szApplicationExec = apxPoolWStrdupA(hProcess->hPool, szName);
@@ -668,7 +668,7 @@ apxProcessSetExecutableW(APXHANDLE hProc
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     apxFree(lpProc->szApplicationExec);
     lpProc->szApplicationExec = apxPoolStrdupW(hProcess->hPool, szName);
@@ -683,11 +683,11 @@ apxProcessSetCommandLineA(APXHANDLE hPro
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     apxFree(lpProc->szCommandLine);
     lpProc->szCommandLine = apxPoolWStrdupA(hProcess->hPool, szCmdline);
-    
+
     return lpProc->szCommandLine != NULL;
 }
 
@@ -698,11 +698,11 @@ apxProcessSetCommandLineW(APXHANDLE hPro
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     apxFree(lpProc->szCommandLine);
     lpProc->szCommandLine = apxPoolStrdupW(hProcess->hPool, szCmdline);
-    
+
     return lpProc->szCommandLine != NULL;
 }
 
@@ -713,11 +713,11 @@ apxProcessSetWorkingPathA(APXHANDLE hPro
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     apxFree(lpProc->szWorkingPath);
     lpProc->szWorkingPath = apxPoolWStrdupA(hProcess->hPool, szPath);
-    
+
     return lpProc->szWorkingPath != NULL;
 }
 
@@ -728,7 +728,7 @@ apxProcessSetWorkingPathW(APXHANDLE hPro
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     apxFree(lpProc->szWorkingPath);
     if (!szPath) {
@@ -737,7 +737,7 @@ apxProcessSetWorkingPathW(APXHANDLE hPro
         return TRUE;
     }
     lpProc->szWorkingPath = apxPoolWStrdupW(hProcess->hPool, szPath);
-    
+
     return lpProc->szWorkingPath != NULL;
 }
 
@@ -748,7 +748,7 @@ apxProcessPutcA(APXHANDLE hProcess, INT 
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return 0;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     return __apxProcessPutc(lpProc, ch, sizeof(CHAR));
 }
@@ -760,7 +760,7 @@ apxProcessPutcW(APXHANDLE hProcess, INT 
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return 0;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     return __apxProcessPutc(lpProc, ch, sizeof(WCHAR));
 }
@@ -807,7 +807,7 @@ apxProcessWrite(APXHANDLE hProcess, LPCV
     LPAPXPROCESS lpProc;
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return 0;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
 
     return __apxProcessWrite(lpProc, lpData, dwLen);
@@ -820,13 +820,13 @@ apxProcessFlushStdin(APXHANDLE hProcess)
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
-    
+
     if (lpProc->dwChildStatus & CHILD_RUNNING) {
         return FlushFileBuffers(lpProc->hChildInpWr);
     }
-    
+
     return FALSE;
 }
 
@@ -847,9 +847,9 @@ apxProcessWait(APXHANDLE hProcess, DWORD
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return WAIT_ABANDONED;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
-    
+
     if (lpProc->dwChildStatus & CHILD_RUNNING) {
         DWORD rv = WaitForMultipleObjects(3, lpProc->hWorkerThreads,
                                           TRUE, dwMilliseconds);
@@ -869,10 +869,23 @@ apxProcessRunning(APXHANDLE hProcess)
 
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
+    lpProc = APXHANDLE_DATA(hProcess);
+
+    return (lpProc->dwChildStatus & CHILD_RUNNING);
+}
+
+DWORD
+apxProcessGetPid(APXHANDLE hProcess)
+{
+   LPAPXPROCESS lpProc;
+
+    if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
+        return 0;
+
     lpProc = APXHANDLE_DATA(hProcess);
-    
-    return (lpProc->dwChildStatus & CHILD_RUNNING);    
+
+    return lpProc->stProcInfo.dwProcessId;
 }
 
 static LPWSTR __apxStrQuote(LPWSTR lpDest, LPCWSTR szSrc)
@@ -880,7 +893,7 @@ static LPWSTR __apxStrQuote(LPWSTR lpDes
     LPWSTR p;
     BOOL   space = FALSE, quote = FALSE;
 
-    /* Find if string has embeded spaces, add quotes only if no quotes found 
+    /* Find if string has embeded spaces, add quotes only if no quotes found
      */
     for (p = (LPWSTR)szSrc; *p; p++) {
         if (*p == L' ' || *p == '\t') {
@@ -907,13 +920,13 @@ apxProcessSetCommandArgsW(APXHANDLE hPro
     LPWSTR p;
     if (hProcess->dwType != APXHANDLE_TYPE_PROCESS)
         return FALSE;
-    
+
     lpProc = APXHANDLE_DATA(hProcess);
     apxFree(lpProc->szCommandLine);
-    
+
     l = lstrlenW(szTitle) + 3;
     for (i = 0; i < dwArgc; i++) {
-        int x, q = 0;
+        int q = 0;
         l += (lstrlenW(lpArgs[i]) + 3);
         l += q;
     }



Mime
View raw message