You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/08/19 18:01:09 UTC

svn commit: r805854 - in /commons/sandbox/runtime/trunk/src: main/native/os/win32/pmutex.c main/native/os/win32/psema.c main/native/test/testcase.c test/org/apache/commons/runtime/TestSemaphore.java

Author: mturk
Date: Wed Aug 19 16:01:09 2009
New Revision: 805854

URL: http://svn.apache.org/viewvc?rev=805854&view=rev
Log:
Make sure exception is thrown in case of failure

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c?rev=805854&r1=805853&r2=805854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pmutex.c Wed Aug 19 16:01:09 2009
@@ -75,9 +75,17 @@
                                                 GENERIC_READ | GENERIC_WRITE | MUTEX_MODIFY_STATE);
     sa.bInheritHandle = FALSE;
     m = CreateMutexW(&sa, FALSE, reskey);
-    if (!m)
+    if (!m) {
+        if (!IS_INVALID_HANDLE(_E)) {
+            rc = ACR_GET_OS_ERROR();
+            if (rc == EACCES)
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+            else
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+            ACR_SET_OS_ERROR(rc);
+        }
         return -1;
-
+    }
     rc = acr_ioh_open(m, ACR_DT_MUTEX, 0, mutex_cleanup);
     return rc;
 }
@@ -100,8 +108,17 @@
     res_name_from_filenamew(ACR_DT_MUTEX, reskey, fname);
 
     m = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, reskey);
-    if (!m)
+    if (!m) {
+        if (!IS_INVALID_HANDLE(_E)) {
+            rc = ACR_GET_OS_ERROR();
+            if (rc == EACCES)
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+            else
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+            ACR_SET_OS_ERROR(rc);
+        }
         return -1;
+    }
 
     rc = acr_ioh_open(m, ACR_DT_MUTEX, 0, mutex_cleanup);
     return rc;
@@ -212,4 +229,3 @@
 {
     ACR_UnloadClass(_E, &_clazzn);
 }
-

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c?rev=805854&r1=805853&r2=805854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/psema.c Wed Aug 19 16:01:09 2009
@@ -57,7 +57,7 @@
     wchar_t *reskey;
     wchar_t  keybuf[128];
 
-    if (value < 1) {
+    if (value < 0) {
         ACR_SET_OS_ERROR(ACR_EINVAL);
         return -1;
     }
@@ -83,9 +83,17 @@
                                             GENERIC_READ | GENERIC_WRITE | SEMAPHORE_MODIFY_STATE);
     sa.bInheritHandle = FALSE;
     s = CreateSemaphoreW(&sa, (LONG)value, (LONG)maxval, reskey);
-    if (!s)
+    if (!s) {
+        if (!IS_INVALID_HANDLE(_E)) {
+            rc = ACR_GET_OS_ERROR();
+            if (rc == EACCES)
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+            else
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+            ACR_SET_OS_ERROR(rc);
+        }
         return -1;
-
+    }
     rc = acr_ioh_open(s, ACR_DT_SEMAPHORE, 0, semaphore_cleanup);
     return rc;
 }
@@ -111,8 +119,17 @@
     }
 
     s = OpenSemaphoreW(READ_CONTROL | SEMAPHORE_MODIFY_STATE, FALSE, reskey);
-    if (!s)
+    if (!s) {
+        if (!IS_INVALID_HANDLE(_E)) {
+            rc = ACR_GET_OS_ERROR();
+            if (rc == EACCES)
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+            else
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+            ACR_SET_OS_ERROR(rc);
+        }
         return -1;
+    }
 
     rc = acr_ioh_open(s, ACR_DT_SEMAPHORE, 0, semaphore_cleanup);
     return rc;

Modified: commons/sandbox/runtime/trunk/src/main/native/test/testcase.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/test/testcase.c?rev=805854&r1=805853&r2=805854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Wed Aug 19 16:01:09 2009
@@ -695,7 +695,7 @@
         rc = ACR_ShmAttach(_E, shr_name);
         fprintf(stdout, "\n\nRunning inside child process ...\n");
         fprintf(stdout, "Attach returned %d (errno=%d)\n", rc, errno);
-        fprintf(stdout, "Child process finished ...\n\n");        
+        fprintf(stdout, "Child process finished ...\n\n");
         fflush(stdout);
         exit(0);
     }

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java?rev=805854&r1=805853&r2=805854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestSemaphore.java Wed Aug 19 16:01:09 2009
@@ -46,21 +46,21 @@
     public void testTestSemaphoreCreate()
         throws Throwable
     {
-        boolean owner = true;
+        boolean owner = false;
         int s = -1;
         System.out.println();
         try {
             s = test002(0);
-            System.out.println("Semaphore attached");
-            owner = false;
-        } catch (Exception e) {
+        } catch (Throwable t) {
             // Ignore
         }
-        if (owner) {
+        if (s < 0) {
             s = test001(0);
-            System.out.println("Semaphore created");
+            if (s > 0) {
+                owner = true;
+            }
         }
-        assertTrue("Create Semaphore", s > 0);
+        assertTrue("Invalid Semaphore", s > 0);
         if (owner) {
             // Wait until child attaches
             System.out.println("Waiting ....");