commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r907592 - in /commons/proper/daemon/trunk/src/native/nt/procrun: apps/prunmgr/prunmgr.c apps/prunsrv/prunsrv.c apps/prunsrv/prunsrv.h apps/prunsrv/prunsrv.x86 include/apxwin.h src/javajni.c src/log.c src/mclib.c
Date Mon, 08 Feb 2010 09:34:02 GMT
Author: mturk
Date: Mon Feb  8 09:33:58 2010
New Revision: 907592

URL: http://svn.apache.org/viewvc?rev=907592&view=rev
Log:
Use safer strcpy/strcat and make log preffix a real preffix

Modified:
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunmgr/prunmgr.c
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.h
    commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.x86
    commons/proper/daemon/trunk/src/native/nt/procrun/include/apxwin.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/mclib.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=907592&r1=907591&r2=907592&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 Feb  8 09:33:58
2010
@@ -869,6 +869,8 @@
                     SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, b);
                     apxFree(b);
                 }
+                else
+                    SetDlgItemTextW(hDlg, IDC_PPLGPREFIX, L"jakarta_service_");
                 if ((b = apxRegistryGetStringW(hRegserv, APXREG_PARAMSOFTWARE,
                                                _s_log, L"StdOutput")) != NULL) {
                     SetDlgItemTextW(hDlg, IDC_PPLGSTDOUT, b);
@@ -1424,10 +1426,10 @@
                 __stopProperty);
 
     if (_currentEntry && _currentEntry->lpConfig)
-        lstrcpyW(szT, _currentEntry->lpConfig->lpDisplayName);
+        lstrlcpyW(szT, 1024, _currentEntry->lpConfig->lpDisplayName);
     else
         return;
-    lstrcatW(szT, L" Properties");
+    lstrlcatW(szT, 1024, L" Properties");
 
     psH.dwSize           = sizeof(PROPSHEETHEADER);
     psH.dwFlags          = PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK | PSH_NOCONTEXTHELP;
@@ -1454,9 +1456,9 @@
     WCHAR en[SIZ_DESLEN];
     int i;
 
-    lstrcpyW(en, L"Global\\");
-    lstrcatW(en, szServiceName);
-    lstrcatW(en, L"SIGNAL");
+    lstrlcpyW(en, SIZ_DESLEN, L"Global\\");
+    lstrlcatW(en, SIZ_DESLEN, szServiceName);
+    lstrlcatW(en, SIZ_DESLEN, L"SIGNAL");
     for (i = 7; i < lstrlenW(en); i++) {
         if (en[i] >= L'a' && en[i] <= L'z')
             en[i] = en[i] - 32;

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=907592&r1=907591&r2=907592&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 Feb  8 09:33:58
2010
@@ -52,10 +52,8 @@
     LPCWSTR szStdErrFilename;
     HANDLE  hStdOutFile;
     HANDLE  hStdErrFile;
-    FILE    *fpStdOutFile;
-    FILE    *fpStdErrFile;
-    FILE    fpStdOutSave;
-    FILE    fpStdErrSave;
+    int     fdStdOutFile;
+    int     fdStdErrFile;
 } APX_STDWRAP;
 
 /* Use static variables instead of #defines */
@@ -247,14 +245,6 @@
     BOOL aErr = FALSE;
     BOOL aOut = FALSE;
 
-    /* Clear up the handles */
-    lpWrapper->fpStdErrFile = NULL;
-    lpWrapper->fpStdOutFile = NULL;
-
-    /* Save the original streams */
-    lpWrapper->fpStdOutSave = *stdout;
-    lpWrapper->fpStdErrSave = *stderr;
-
     /* redirect to file or console */
     if (lpWrapper->szStdOutFilename) {
         if (lstrcmpiW(lpWrapper->szStdOutFilename, PRSRV_AUTO) == 0) {
@@ -270,11 +260,11 @@
         if (!aOut)
             DeleteFileW(lpWrapper->szStdOutFilename);
         lpWrapper->hStdOutFile = CreateFileW(lpWrapper->szStdOutFilename,
-                                             GENERIC_WRITE | GENERIC_READ,
+                                             GENERIC_WRITE,
                                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                                              NULL,
                                              OPEN_ALWAYS,
-                                             FILE_ATTRIBUTE_NORMAL,
+                                             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH
| FILE_FLAG_SEQUENTIAL_SCAN,
                                              NULL);
         if (IS_INVALID_HANDLE(lpWrapper->hStdOutFile))
             return FALSE;
@@ -283,7 +273,7 @@
     }
     else {
         lpWrapper->hStdOutFile = CreateFileW(L"CONOUT$",
-                                             GENERIC_READ | GENERIC_WRITE,
+                                             GENERIC_WRITE,
                                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                                              NULL,
                                              OPEN_EXISTING,
@@ -303,11 +293,11 @@
         if (!aErr)
             DeleteFileW(lpWrapper->szStdErrFilename);
         lpWrapper->hStdErrFile = CreateFileW(lpWrapper->szStdErrFilename,
-                                             GENERIC_WRITE | GENERIC_READ,
+                                             GENERIC_WRITE,
                                              FILE_SHARE_READ | FILE_SHARE_WRITE,
                                              NULL,
                                              OPEN_ALWAYS,
-                                             FILE_ATTRIBUTE_NORMAL,
+                                             FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH
| FILE_FLAG_SEQUENTIAL_SCAN,
                                              NULL);
         if (IS_INVALID_HANDLE(lpWrapper->hStdErrFile))
             return FALSE;
@@ -325,34 +315,20 @@
      * This will redirect all printf to go to the redirected files.
      * It is used for JNI vprintf functionality.
      */
-    lpWrapper->fpStdOutFile = _fdopen(_open_osfhandle(
-                                      (intptr_t)lpWrapper->hStdOutFile,
-                                      _O_TEXT), "w");
-    lpWrapper->fpStdErrFile = _fdopen(_open_osfhandle(
-                                      (intptr_t)lpWrapper->hStdErrFile,
-                                      _O_TEXT), "w");
-    if (lpWrapper->fpStdOutFile) {
-        *stdout = *lpWrapper->fpStdOutFile;
+    lpWrapper->fdStdOutFile = _open_osfhandle((ptrdiff_t)lpWrapper->hStdOutFile,
+                                              _O_WRONLY | _O_TEXT);
+    if (lpWrapper->fdStdOutFile > 0) {
+        lpWrapper->fdStdOutFile = dup2(lpWrapper->fdStdOutFile, 1);
         setvbuf(stdout, NULL, _IONBF, 0);
     }
-    if (lpWrapper->fpStdErrFile) {
-        *stderr = *lpWrapper->fpStdErrFile;
+    lpWrapper->fdStdErrFile = _open_osfhandle((ptrdiff_t)lpWrapper->hStdErrFile,
+                                              _O_WRONLY | _O_TEXT);
+    if (lpWrapper->fdStdErrFile > 0) {
+        lpWrapper->fdStdErrFile = dup2(lpWrapper->fdStdErrFile, 2);
         setvbuf(stderr, NULL, _IONBF, 0);
     }
-    return TRUE;
-}
 
-static void cleanupStdStreams(APX_STDWRAP *lpWrapper)
-{
-    /* Close the redirectied streams */
-    if (lpWrapper->fpStdOutFile) {
-        fclose(lpWrapper->fpStdOutFile);
-        *stdout = lpWrapper->fpStdOutSave;
-    }
-    if (lpWrapper->fpStdErrFile) {
-        fclose(lpWrapper->fpStdErrFile);
-        *stderr = lpWrapper->fpStdErrSave;
-    }
+    return TRUE;
 }
 
 /* Debugging functions */
@@ -554,18 +530,18 @@
 
     /* Check if --Install is provided */
     if (!SO_INSTALL) {
-        lstrcpyW(szImage, lpCmdline->szExePath);
-        lstrcatW(szImage, L"\\");
-        lstrcatW(szImage, lpCmdline->szExecutable);
-        lstrcatW(szImage, L".exe");
+        lstrlcpyW(szImage, SIZ_HUGLEN, lpCmdline->szExePath);
+        lstrlcatW(szImage, SIZ_HUGLEN, L"\\");
+        lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szExecutable);
+        lstrlcatW(szImage, SIZ_HUGLEN, L".exe");
     }
     else
         lstrcpyW(szImage, SO_INSTALL);
     /* Replace not needed qoutes */
     apxStrQuoteInplaceW(szImage);
     /* Add run-service command line option */
-    lstrcatW(szImage, L" //RS//");
-    lstrcatW(szImage, lpCmdline->szApplication);
+    lstrlcatW(szImage, SIZ_HUGLEN, L" //RS//");
+    lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szApplication);
     SO_INSTALL = apxPoolStrdupW(gPool, szImage);
     /* Ensure that option gets saved in the registry */
     ST_INSTALL |= APXCMDOPT_FOUND;
@@ -632,8 +608,8 @@
     if (apxServiceOpen(hService, lpCmdline->szApplication, SERVICE_ALL_ACCESS)) {
         WCHAR szWndManagerClass[SIZ_RESLEN];
         HANDLE hWndManager = NULL;
-        lstrcpyW(szWndManagerClass, lpCmdline->szApplication);
-        lstrcatW(szWndManagerClass, L"_CLASS");
+        lstrlcpyW(szWndManagerClass, SIZ_RESLEN, lpCmdline->szApplication);
+        lstrlcatW(szWndManagerClass, SIZ_RESLEN, L"_CLASS");
         /* Close the monitor application if running */
         if ((hWndManager = FindWindowW(szWndManagerClass, NULL)) != NULL) {
             SendMessage(hWndManager, WM_CLOSE, 0, 0);
@@ -1171,9 +1147,9 @@
         WCHAR en[SIZ_DESLEN];
         int i;
         PSECURITY_ATTRIBUTES sa = GetNullACL();
-        lstrcpyW(en, L"Global\\");
-        lstrcatW(en, _service_name);
-        lstrcatW(en, PRSRV_SIGNAL);
+        lstrlcpyW(en, SIZ_DESLEN, L"Global\\");
+        lstrlcatW(en, SIZ_DESLEN, _service_name);
+        lstrlcatW(en, SIZ_DESLEN, PRSRV_SIGNAL);
         for (i = 7; i < lstrlenW(en); i++) {
             if (en[i] >= L'a' && en[i] <= L'z')
                 en[i] = en[i] - 32;
@@ -1344,7 +1320,7 @@
         }
         Sleep(ss * 1000);
         ExitProcess(0);
-        return;                        
+        return;
     }
     apxHandleManagerInitialize();
     /* Create the main Pool */
@@ -1420,6 +1396,5 @@
     _service_status_handle = NULL;
     apxLogClose(NULL);
     apxHandleManagerDestroy();
-    cleanupStdStreams(&gStdwrap);
     ExitProcess(rv);
 }

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.h?rev=907592&r1=907591&r2=907592&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.h (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.h Mon Feb  8 09:33:58
2010
@@ -25,7 +25,7 @@
 #define _PRUNSRV_H
 
 #undef  PRG_VERSION
-#define PRG_VERSION    "2.0.6.0" 
+#define PRG_VERSION    "2.0.7.0" 
 #define PRG_REGROOT   L"Apache Software Foundation\\Procrun 2.0"
 
 #endif /* _PRUNSRV_H */

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.x86
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.x86?rev=907592&r1=907591&r2=907592&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.x86 (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/apps/prunsrv/prunsrv.x86 Mon Feb  8
09:33:58 2010
@@ -82,7 +82,7 @@
 
 "$(OUTDIR)\prunsrv.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
     $(LINK32) @<<
-  $(LINK32_FLAGS) $(LINK32_OBJS)
+  $(LINK32_FLAGS) $(LINK32_OBJS) commode.obj
 <<
 	if exist $(OUTDIR)\prunsrv.exe.manifest mt.exe -manifest $(OUTDIR)\prunsrv.exe.manifest
-outputresource:$(OUTDIR)\prunsrv.exe;1
 

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=907592&r1=907591&r2=907592&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 Feb  8 09:33:58
2010
@@ -35,7 +35,6 @@
 #include <shellapi.h>
 #include <zmouse.h>
 #include <richedit.h>
-
 #include <lm.h>
 
 #ifndef _INTPTR_T_DEFINED
@@ -201,6 +200,11 @@
 
 #define AplMoveMemory   AplCopyMemory
 
+LPSTR   lstrlcatA(LPSTR dst, int siz, LPCSTR src);
+LPWSTR  lstrlcatW(LPWSTR dst, int siz, LPCWSTR src);
+LPSTR   lstrlcpyA(LPSTR dst, int siz, LPCSTR src);
+LPWSTR  lstrlcpyW(LPWSTR dst, int siz, LPCWSTR src);
+
 PSECURITY_ATTRIBUTES GetNullACL();
 void CleanNullACL(void *sa);
 

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=907592&r1=907591&r2=907592&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 Feb  8 09:33:58 2010
@@ -98,6 +98,8 @@
         ((*(lpJava->lpEnv))->##fName(lpJava->lpEnv, (a1), (a2), (a3), (a4)))
 
 typedef struct APXJAVASTDCLAZZ {
+    CHAR        sClazz[1024];
+    CHAR        sMethod[512];
     jclass      jClazz;
     jmethodID   jMethod;
     jobject     jObject;
@@ -470,14 +472,13 @@
     lpJava->clWorker.jClazz  = JNICALL_1(NewGlobalRef, jClazz);
     JNI_LOCAL_UNREF(jClazz);
 
-    if (szMethodName)
-        lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
-                                             lpJava->clWorker.jClazz,
-                                             szMethodName, "([Ljava/lang/String;)V");
-    else
-        lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
-                                             lpJava->clWorker.jClazz,
-                                             "main", "([Ljava/lang/String;)V");
+    if (!szMethodName)
+        szMethodName = "main";
+    lstrcpyA(lpJava->clWorker.sClazz,  szClassName);
+    lstrcpyA(lpJava->clWorker.sMethod, szMethodName);
+    lpJava->clWorker.jMethod = JNICALL_3(GetStaticMethodID,
+                                         lpJava->clWorker.jClazz,
+                                         szMethodName, "([Ljava/lang/String;)V");
     if (!lpJava->clWorker.jMethod) {
         JVM_EXCEPTION_CLEAR(lpJava);
         apxLogWrite(APXLOG_MARK_ERROR "Static method 'void main(String[])' in Class %s not
found", szClassName);
@@ -518,6 +519,8 @@
         WORKER_EXIT(2);
     if (!__apxJvmAttach(lpJava))
         WORKER_EXIT(3);
+    apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread started %s:%s",
+                lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
     lpJava->dwWorkerStatus = 1;
     JNICALL_3(CallStaticVoidMethod,
               lpJava->clWorker.jClazz,
@@ -528,7 +531,8 @@
     __apxJvmDetach(lpJava);
 finished:
     lpJava->dwWorkerStatus = 0;
-    apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished");
+    apxLogWrite(APXLOG_MARK_DEBUG "Java Worker thread finished %s:%s",
+                lpJava->clWorker.sClazz, lpJava->clWorker.sMethod);
     ExitThread(rv);
     /* never gets here but keep the compiler happy */
     return 0;

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=907592&r1=907591&r2=907592&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 Feb  8 09:33:58 2010
@@ -12,7 +12,7 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- */ 
+ */
 
 #include "apxwin.h"
 #include "private.h"
@@ -57,11 +57,11 @@
     if (!szPath) {
         if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
             return INVALID_HANDLE_VALUE;
-        lstrcatW(sPath, L"\\LogFiles\\");
+        lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\");
         if (!szPrefix)
-            lstrcatW(sPath, L"Apache");
+            lstrlcatW(sPath, MAX_PATH, L"Apache");
         else
-            lstrcatW(sPath, szPrefix);
+            lstrlcatW(sPath, MAX_PATH, szPrefix);
         wsprintfW(sName, L"\\%s%04d%02d%02d.log",
                   szName,
                   sysTime.wYear,
@@ -69,7 +69,7 @@
                   sysTime.wDay);
     }
     else {
-        lstrcpyW(sPath, szPath);
+        lstrlcpyW(sPath, MAX_PATH, szPath);
         if (szPrefix)
             wsprintfW(sName, L"\\%s", szPrefix);
         else
@@ -82,14 +82,14 @@
     sRet = apxPoolAlloc(hPool, (MAX_PATH + 1) * sizeof(WCHAR));
     /* Set default level to info */
     CreateDirectoryW(sPath, NULL);
-    
-    lstrcpyW(sRet, sPath);
-    lstrcatW(sRet, sName);
+
+    lstrlcpyW(sRet, MAX_PATH, sPath);
+    lstrlcatW(sRet, MAX_PATH, sName);
 
     return sRet;
 }
 
-/* Open the log file 
+/* Open the log file
  * TODO: format like standard apache error.log
  * Add the EventLogger
  */
@@ -108,43 +108,34 @@
     if (!szPath) {
         if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
             return INVALID_HANDLE_VALUE;
-        lstrcatW(sPath, L"\\LogFiles\\");
-        if (!szPrefix)
-            lstrcatW(sPath, L"Apache");
-        else
-            lstrcatW(sPath, szPrefix);
-        wsprintfW(sName, L"\\%04d%02d%02d.log",
-                  sysTime.wYear,
-                  sysTime.wMonth,
-                  sysTime.wDay);
+        lstrlcatW(sPath, MAX_PATH, L"\\LogFiles\\Apache");
     }
     else {
-        lstrcpyW(sPath, szPath);
-        if (szPrefix)
-            wsprintfW(sName, L"\\%s", szPrefix);
-        else
-            wsprintfW(sName, L"\\jakarta_service_%04d%02d%02d.log",
-                      sysTime.wYear,
-                      sysTime.wMonth,
-                      sysTime.wDay);
+        lstrlcpyW(sPath, MAX_PATH, szPath);
     }
+    if (!szPrefix)
+        szPrefix = L"jakarta_service_";
+    wsprintfW(sName, L"\\%s%04d%02d%02d.log",
+              szPrefix,
+              sysTime.wYear,
+              sysTime.wMonth,
+              sysTime.wDay);
     if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st))))
         return NULL;
     /* Set default level to info */
     h->dwLogLevel = APXLOG_LEVEL_INFO;
     CreateDirectoryW(sPath, NULL);
-    
+
     h->sysTime = sysTime;
-    lstrcpyW(h->szPath, sPath);
-    lstrcatW(sPath, sName);
-    if (szPrefix)
-        lstrcpyW(h->szPrefix, szPrefix);
+    lstrlcpyW(h->szPath, MAX_PATH, sPath);
+    lstrlcatW(sPath, MAX_PATH, sName);
+    lstrlcpyW(h->szPrefix, MAX_PATH, szPrefix);
 
     h->hFile =  CreateFileW(sPath,
                       GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
                       NULL,
                       OPEN_ALWAYS,
-                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_SEQUENTIAL_SCAN,
                       NULL);
     /* Set this file as system log file */
     if (!_st_sys_loghandle)
@@ -199,12 +190,12 @@
                            LPSYSTEMTIME lpCtime)
 {
     WCHAR sPath[MAX_PATH+1];
-    
+
     /* rotate on daily basis */
     if (l->sysTime.wDay == lpCtime->wDay)
         return TRUE;
     FlushFileBuffers(l->hFile);
-    CloseHandle(l->hFile);    
+    CloseHandle(l->hFile);
     l->sysTime = *lpCtime;
 
     wsprintfW(sPath, L"%s\\%s%04d%02d%02d.log",
@@ -217,7 +208,7 @@
                       GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
                       NULL,
                       OPEN_ALWAYS,
-                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
+                      FILE_FLAG_NO_BUFFERING | FILE_FLAG_SEQUENTIAL_SCAN,
                       NULL);
     if (IS_INVALID_HANDLE(l->hFile))
         return FALSE;
@@ -257,18 +248,18 @@
     if (dwLevel < lf->dwLogLevel)
         return 0;
     if (f) {
-        f = (szFile + lstrlenA(szFile) - 1);    
+        f = (szFile + lstrlenA(szFile) - 1);
         while(f != szFile && '\\' != *f && '/' != *f)
             f--;
         if(f != szFile)
             f++;
     }
-    lstrcpyA(buffer, _log_level[dwLevel]);
+    lstrlcpyA(buffer, 1056, _log_level[dwLevel]);
     if (!dolock)
-        lstrcatA(buffer, "\n");
+        lstrlcatA(buffer, 1056, "\n");
     szBp = &buffer[lstrlenA(buffer)];
     if (!szFormat) {
-        FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | 
+        FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
                        FORMAT_MESSAGE_IGNORE_INSERTS,
                        NULL,
                        err,
@@ -300,7 +291,7 @@
                 APX_LOGLOCK(lf->hFile);
             }
             if (bTimeStamp) {
-                wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ", 
+                wsprintfA(sb, "[%d-%02d-%02d %02d:%02d:%02d] ",
                           t.wYear, t.wMonth, t.wDay,
                           t.wHour, t.wMinute, t.wSecond);
                 WriteFile(lf->hFile, sb, lstrlenA(sb), &wr, NULL);
@@ -311,7 +302,7 @@
             }
 
             WriteFile(lf->hFile, buffer, len, &wr, NULL);
-            /* Terminate the line */            
+            /* Terminate the line */
             WriteFile(lf->hFile, LINE_SEP, sizeof(LINE_SEP) - 1, &wr, NULL);
 #ifdef _DEBUG_FULL
             FlushFileBuffers(lf->hFile);
@@ -323,7 +314,7 @@
 #ifdef _DEBUG_FULL
         {
             char tid[1024 + 16];
-            wsprintfA(tid, "[%04X] %s", GetCurrentThreadId(), buffer);
+            wsprintfA(tid, "[%04d] %s", GetCurrentThreadId(), buffer);
             OutputDebugStringA(tid);
         }
 #endif
@@ -342,7 +333,7 @@
         lf = _st_sys_loghandle;
     if (IS_INVALID_HANDLE(lf))
         return;
-    
+
     FlushFileBuffers(lf->hFile);
     CloseHandle(lf->hFile);
     if (lf == _st_sys_loghandle)
@@ -359,13 +350,13 @@
     ...)
 {
     va_list args;
-    CHAR    buffer[1024+16];
+    CHAR    buffer[1024+32];
     CHAR    sysbuf[2048];
     int     len = 0, nRet;
     LPCSTR  f = szFile;
     DWORD   err = GetLastError(); /* save the last Error code */
     if (f) {
-        f = (szFile + lstrlenA(szFile) - 1);    
+        f = (szFile + lstrlenA(szFile) - 1);
         while(f != szFile && '\\' != *f && '/' != *f)
             f--;
         if(f != szFile)
@@ -373,7 +364,7 @@
     }
     sysbuf[0] = '\0';
     if (err != ERROR_SUCCESS) {
-        len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | 
+        len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
                              FORMAT_MESSAGE_IGNORE_INSERTS,
                              NULL,
                              err,
@@ -392,15 +383,15 @@
             wsprintfA(sb, "\n%s (%d)", f, dwLine);
             lstrcatA(sysbuf, sb);
         }
-        lstrcatA(sysbuf, "\n");
-        lstrcatA(sysbuf, buffer);
+        lstrlcatA(sysbuf, 2048, "\n");
+        lstrlcatA(sysbuf, 2048, buffer);
     }
     len = lstrlenA(sysbuf);
 #ifdef _DEBUG_FULL
     OutputDebugStringA(sysbuf);
 #endif
     if (len > 0 && bDisplay) {
-        nRet = MessageBoxA(NULL, sysbuf, 
+        nRet = MessageBoxA(NULL, sysbuf,
                            "Application System Error",
                            MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
     }

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/mclib.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/mclib.c?rev=907592&r1=907591&r2=907592&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/mclib.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/mclib.c Mon Feb  8 09:33:58 2010
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 /*
  * Copyright (c) 1994
  *  The Regents of the University of California.  All rights reserved.
@@ -54,7 +54,7 @@
 #define wmask   (wsize - 1)
 
 LPVOID AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill)
-{ 
+{
 
     SIZE_T t;
 #ifdef WIN64
@@ -119,11 +119,11 @@
         do {
             *dst++ = Fill;
         } while (--t != 0);
-    return (Destination); 
+    return (Destination);
 }
 
 void AplZeroMemory(PVOID Destination, SIZE_T Length)
-{ 
+{
 
     SIZE_T t;
     LPBYTE dst;
@@ -237,7 +237,7 @@
     }
 done:
     return (Destination);
-} 
+}
 
 
 INT
@@ -252,7 +252,7 @@
         } while (--nBytes != 0);
     }
     return 0;
-} 
+}
 
 /*
  * Find the first occurrence of lpFind in lpMem.
@@ -277,7 +277,7 @@
         s--;
     }
     return (LPBYTE)s;
-} 
+}
 
 LPSTR
 AplRindexA(LPCSTR lpStr, int ch)
@@ -289,6 +289,121 @@
             save = (LPSTR)lpStr;
         if (!*lpStr)
             return save;
-    } 
+    }
     /* NOTREACHED */
-} 
+}
+
+/*
+ * Appends src to string dst of size siz (unlike strncat, siz is the
+ * full size of dst, not space left).  At most siz-1 characters
+ * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
+ * Returns strlen(src) + MIN(siz, strlen(initial dst)).
+ * If retval >= siz, truncation occurred.
+ */
+LPSTR
+lstrlcatA(LPSTR dst, int siz, LPCSTR src)
+{
+    LPSTR  d = dst;
+    LPCSTR s = src;
+    int n = siz;
+    int dlen;
+
+    /* Find the end of dst and adjust bytes left but don't go past end */
+    while (n-- != 0 && *d != '\0')
+        d++;
+    dlen = d - dst;
+    n = siz - dlen;
+
+    if (n == 0)
+        return NULL;
+    while (*s != '\0') {
+        if (n != 1) {
+            *d++ = *s;
+            n--;
+        }
+        s++;
+    }
+    *d = '\0';
+
+    return dst;
+}
+
+LPWSTR
+lstrlcatW(LPWSTR dst, int siz, LPCWSTR src)
+{
+    LPWSTR  d = dst;
+    LPCWSTR s = src;
+    int n = siz;
+    int dlen;
+
+    /* Find the end of dst and adjust bytes left but don't go past end */
+    while (n-- != 0 && *d != '\0')
+        d++;
+    dlen = d - dst;
+    n = siz - dlen;
+
+    if (n == 0)
+        return NULL;
+    while (*s != L'\0') {
+        if (n != 1) {
+            *d++ = *s;
+            n--;
+        }
+        s++;
+    }
+    *d = L'\0';
+
+    return dst;
+}
+
+LPSTR
+lstrlcpyA(LPSTR dst, int siz, LPCSTR src)
+{
+    LPSTR  d = dst;
+    LPCSTR s = src;
+    int    n = siz;
+
+    /* Copy as many bytes as will fit */
+    if (n != 0) {
+        while (--n != 0) {
+            if ((*d++ = *s++) == '\0')
+                break;
+        }
+    }
+
+    /* Not enough room in dst, add NUL and traverse rest of src */
+    if (n == 0) {
+        if (siz != 0)
+            *d = '\0';      /* NUL-terminate dst */
+        while (*s++)
+            ;
+    }
+
+    return d;
+}
+
+LPWSTR
+lstrlcpyW(LPWSTR dst, int siz, LPCWSTR src)
+{
+    LPWSTR  d = dst;
+    LPCWSTR s = src;
+    int    n = siz;
+
+    /* Copy as many bytes as will fit */
+    if (n != 0) {
+        while (--n != 0) {
+            if ((*d++ = *s++) == L'\0')
+                break;
+        }
+    }
+
+    /* Not enough room in dst, add NUL and traverse rest of src */
+    if (n == 0) {
+        if (siz != 0)
+            *d = L'\0';      /* NUL-terminate dst */
+        while (*s++)
+            ;
+    }
+
+    return d;
+}



Mime
View raw message