commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1137965 - in /commons/proper/daemon/trunk/src/native/windows: apps/prunsrv/prunsrv.c include/apxwin.h src/utils.c
Date Tue, 21 Jun 2011 11:47:56 GMT
Author: mturk
Date: Tue Jun 21 11:47:56 2011
New Revision: 1137965

URL: http://svn.apache.org/viewvc?rev=1137965&view=rev
Log:
Add macro for checking valid strings

Modified:
    commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c
    commons/proper/daemon/trunk/src/native/windows/include/apxwin.h
    commons/proper/daemon/trunk/src/native/windows/src/utils.c

Modified: commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c?rev=1137965&r1=1137964&r2=1137965&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/apps/prunsrv/prunsrv.c Tue Jun 21 11:47:56
2011
@@ -544,7 +544,7 @@ static BOOL docmdInstallService(LPAPXCMD
         dwType |= SERVICE_INTERACTIVE_PROCESS;
 
     /* Check if --Install is provided */
-    if (!SO_INSTALL) {
+    if (!IS_VALID_STRING(SO_INSTALL)) {
         lstrlcpyW(szImage, SIZ_HUGLEN, lpCmdline->szExePath);
         lstrlcatW(szImage, SIZ_HUGLEN, L"\\");
         lstrlcatW(szImage, SIZ_HUGLEN, lpCmdline->szExecutable);
@@ -833,7 +833,7 @@ static DWORD WINAPI serviceStop(LPVOID l
         return TRUE;    /* Nothing to do */
     }
     if (_jni_shutdown) {
-        if (!SO_STARTPATH && SO_STOPPATH) {
+        if (!IS_VALID_STRING(SO_STARTPATH) && IS_VALID_STRING(SO_STOPPATH)) {
             /* If the Working path is specified change the current directory
              * but only if the start path wasn't specified already.
              */
@@ -878,11 +878,11 @@ static DWORD WINAPI serviceStop(LPVOID l
         }
         wait_to_die = TRUE;
     }
-    else if (SO_STOPMODE) { /* Only in case we have a stop mode */
+    else if (IS_VALID_STRING(SO_STOPMODE)) { /* Only in case we have a stop mode */
         DWORD nArgs;
         LPWSTR *pArgs;
 
-        if (!SO_STOPIMAGE) {
+        if (!IS_VALID_STRING(SO_STOPIMAGE)) {
             apxLogWrite(APXLOG_MARK_ERROR "Missing service ImageFile");
             if (!_service_mode)
                 apxDisplayError(FALSE, NULL, 0, "Service '%S' is missing the ImageFile",
@@ -1015,7 +1015,7 @@ static DWORD serviceStart()
         apxLogWrite(APXLOG_MARK_INFO "Worker is not defined");
         return TRUE;    /* Nothing to do */
     }
-    if (SO_PIDFILE) {
+    if (IS_VALID_STRING(SO_PIDFILE)) {
         gPidfileName = apxLogFile(gPool, SO_LOGPATH, SO_PIDFILE, NULL, FALSE);
         if (GetFileAttributesW(gPidfileName) !=  INVALID_FILE_ATTRIBUTES) {
             /* Pid file exists */
@@ -1029,13 +1029,13 @@ static DWORD serviceStart()
     }
     GetSystemTimeAsFileTime(&fts);
     if (_jni_startup) {
-        if (SO_STARTPATH) {
+        if (IS_VALID_STRING(SO_STARTPATH)) {
             /* If the Working path is specified change the current directory */
             SetCurrentDirectoryW(SO_STARTPATH);
         }
-        if (lstrlenW(SO_LIBPATH) > 0) {
+        if (IS_VALID_STRING(SO_LIBPATH)) {
             /* Add LibraryPath to the PATH */
-           apxAddEnvironmentVariableW(gPool, L"PATH", SO_LIBPATH);
+           apxAddToPathW(gPool, SO_LIBPATH);
         }
         /* Set the environment using putenv, so JVM can use it */
         setInprocEnvironment();
@@ -1067,16 +1067,16 @@ static DWORD serviceStart()
         apxLogWrite(APXLOG_MARK_DEBUG "Java started %s", _jni_rclass);
     }
     else {
-        if (!SO_STARTIMAGE) {
+        if (!IS_VALID_STRING(SO_STARTIMAGE)) {
             apxLogWrite(APXLOG_MARK_ERROR "Missing service ImageFile");
             if (!_service_mode)
                 apxDisplayError(FALSE, NULL, 0, "Service '%S' is missing the ImageFile",
                                 _service_name ? _service_name : L"unknown");
             return 1;
         }
-        if (lstrlenW(SO_LIBPATH) > 0) {
+        if (IS_VALID_STRING(SO_LIBPATH)) {
             /* Add LibraryPath to the PATH */
-           apxAddEnvironmentVariableW(gPool, L"PATH", SO_LIBPATH);
+           apxAddToPathW(gPool, SO_LIBPATH);
         }
         /* Redirect process */
         gWorker = apxCreateProcessW(gPool,
@@ -1258,7 +1258,7 @@ void WINAPI serviceMain(DWORD argc, LPTS
 
     apxLogWrite(APXLOG_MARK_DEBUG "Inside ServiceMain...");
 
-    if (_service_name) {
+    if (IS_VALID_STRING(_service_name)) {
         WCHAR en[SIZ_HUGLEN];
         int i;
         PSECURITY_ATTRIBUTES sa = GetNullACL();
@@ -1278,7 +1278,7 @@ void WINAPI serviceMain(DWORD argc, LPTS
         }
     }
     /* Check the StartMode */
-    if (SO_STARTMODE) {
+    if (IS_VALID_STRING(SO_STARTMODE)) {
         if (!lstrcmpiW(SO_STARTMODE, PRSRV_JVM)) {
             _jni_startup = TRUE;
             _jni_rclass  = WideToUTF8(SO_STARTCLASS);
@@ -1320,7 +1320,7 @@ void WINAPI serviceMain(DWORD argc, LPTS
         }
     }
     /* Check the StopMode */
-    if (SO_STOPMODE) {
+    if (IS_VALID_STRING(SO_STOPMODE)) {
         if (!lstrcmpiW(SO_STOPMODE, PRSRV_JVM)) {
             _jni_shutdown = TRUE;
             _jni_sclass = WideToUTF8(SO_STOPCLASS);
@@ -1362,15 +1362,15 @@ void WINAPI serviceMain(DWORD argc, LPTS
     }
     /* Find the classpath */
     if (_jni_shutdown || _jni_startup) {
-        if (SO_JVM) {
+        if (IS_VALID_STRING(SO_JVM)) {
             if (lstrcmpW(SO_JVM, PRSRV_AUTO))
                 _jni_jvmpath = SO_JVM;
         }
-        if (SO_CLASSPATH)
+        if (IS_VALID_STRING(SO_CLASSPATH))
             _jni_classpath = WideToUTF8(SO_CLASSPATH);
-        if (SO_STARTMETHOD)
+        if (IS_VALID_STRING(SO_STARTMETHOD))
             _jni_rmethod   = WideToAscii(SO_STARTMETHOD, (LPSTR)SO_STARTMETHOD);
-        if (SO_STOPMETHOD)
+        if (IS_VALID_STRING(SO_STOPMETHOD))
             _jni_smethod   = WideToAscii(SO_STOPMETHOD, (LPSTR)SO_STOPMETHOD);
         _jni_jvmoptions    = MzWideToUTF8(SO_JVMOPTIONS);
     }

Modified: commons/proper/daemon/trunk/src/native/windows/include/apxwin.h
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/include/apxwin.h?rev=1137965&r1=1137964&r2=1137965&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/include/apxwin.h (original)
+++ commons/proper/daemon/trunk/src/native/windows/include/apxwin.h Tue Jun 21 11:47:56 2011
@@ -62,6 +62,7 @@ typedef _W64 int            intptr_t;
 #define TST_BIT_FLAG(x, b) ((x) & (1 << b))
 
 #define IS_INVALID_HANDLE(h) (((h) == NULL || (h) == INVALID_HANDLE_VALUE))
+#define IS_VALID_STRING(s)   ((s) != NULL && *(s) != 0)
 
 #define DYNOLAD_TYPE_DECLARE(fnName, callconv, retType)             \
     typedef retType (callconv *PFN_##fnName)                        \
@@ -187,7 +188,7 @@ LPSTR           apxExpandStrA(APXHANDLE 
 LPWSTR          apxExpandStrW(APXHANDLE hPool, LPCWSTR szString);
 void            apxStrCharReplaceA(LPSTR szString, CHAR chReplace, CHAR chReplaceWith);
 void            apxStrCharReplaceW(LPWSTR szString, WCHAR chReplace, WCHAR chReplaceWith);
-BOOL            apxAddEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName, LPCWSTR szAdd);
+BOOL            apxAddToPathW(APXHANDLE hPool, LPCWSTR szAdd);
 
 
 LPVOID  AplFillMemory(PVOID Destination, SIZE_T Length, BYTE Fill);

Modified: commons/proper/daemon/trunk/src/native/windows/src/utils.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/windows/src/utils.c?rev=1137965&r1=1137964&r2=1137965&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/windows/src/utils.c (original)
+++ commons/proper/daemon/trunk/src/native/windows/src/utils.c Tue Jun 21 11:47:56 2011
@@ -107,13 +107,13 @@ LPSTR __apxGetEnvironmentVariableA(APXHA
     return szRet;
 }
 
-BOOL apxAddEnvironmentVariableW(APXHANDLE hPool, LPCWSTR wsName, LPCWSTR szAdd)
+BOOL apxAddToPathW(APXHANDLE hPool, LPCWSTR szAdd)
 {
     LPWSTR wsAdd;
     DWORD  rc;
     DWORD  al;
     
-    rc = GetEnvironmentVariableW(wsName, NULL, 0);
+    rc = GetEnvironmentVariableW(L"PATH", NULL, 0);
     if (rc == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
         return FALSE;
     al = lstrlenW(szAdd) + 6;
@@ -122,12 +122,12 @@ BOOL apxAddEnvironmentVariableW(APXHANDL
     lstrcpyW(wsAdd, L"PATH=");        
     lstrcatW(wsAdd, szAdd);        
     lstrcatW(wsAdd, L";");        
-    if (!GetEnvironmentVariableW(wsName, wsAdd + al, rc - al)) {
+    if (!GetEnvironmentVariableW(L"PATH", wsAdd + al, rc - al)) {
         apxLogWrite(APXLOG_MARK_SYSERR);
         apxFree(wsAdd);
         return FALSE;
     }
-    SetEnvironmentVariableW(wsName, wsAdd + 5);
+    SetEnvironmentVariableW(L"PATH", wsAdd + 5);
     _wputenv(wsAdd);
     apxFree(wsAdd);
     return TRUE;



Mime
View raw message