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/14 17:03:50 UTC

svn commit: r804251 - in /commons/sandbox/runtime/trunk/src/main/native: os/hpux/shm.c os/unix/shm.c os/win32/shm.c test/testcase.c

Author: mturk
Date: Fri Aug 14 15:03:50 2009
New Revision: 804251

URL: http://svn.apache.org/viewvc?rev=804251&view=rev
Log:
Close descriptor when detaching

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c
    commons/sandbox/runtime/trunk/src/main/native/test/testcase.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c?rev=804251&r1=804250&r2=804251&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/hpux/shm.c Fri Aug 14 15:03:50 2009
@@ -94,8 +94,7 @@
         }
     }
 cleanup:
-    if (m->filename)
-        free((void *)(m->filename));
+    x_free((void *)(m->filename));
     free(m);
     return rc;
 }
@@ -116,12 +115,11 @@
         rc = ACR_EINVAL;
     }
     else {
+        free((void *)(m->filename));
         if (m->base && shmdt(m->base) == -1) {
             rc = ACR_GET_OS_ERROR();
         }
     }
-    if (m->filename)
-        free((void *)(m->filename));
     free(m);
     return rc;
 }
@@ -140,20 +138,6 @@
     return rv;
 }
 
-ACR_DECLARE(int) ACR_ShmDetach(JNIEnv *_E, int shm)
-{
-    acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm);
-
-    if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) {
-        return ACR_EINVAL;
-    }        
-    if (m->base && shmdt(m->base) == -1) {
-        return ACR_GET_OS_ERROR();
-    }
-    m->base = NULL;
-    return 0;
-}
-
 ACR_DECLARE(int) ACR_ShmRemove(JNIEnv *_E, const acr_pchar_t *filename)
 {
     int     rc = 0;
@@ -449,6 +433,29 @@
         return -1;
 }
 
+ACR_DECLARE(int) ACR_ShmDetach(JNIEnv *_E, int shm)
+{
+    int rc = 0;
+    acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm);
+
+    if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) {
+        rc = ACR_EINVAL;
+        goto cleanup;
+    }
+    x_free((void *)(m->filename));
+    m->filename = NULL;
+
+    rc = acr_ioh_close(shm);
+cleanup:
+    if (rc  && !IS_INVALID_HANDLE(_E)) {
+        if (rc == EACCES)
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+        else
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+    }
+    return rc;
+}
+
 ACR_DECLARE(int) ACR_ShmPermSet(JNIEnv *_E, int shm, int perms,
                                 acr_uid_t uid, acr_uid_t gid)
 {

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c?rev=804251&r1=804250&r2=804251&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/shm.c Fri Aug 14 15:03:50 2009
@@ -72,7 +72,7 @@
         }
     }
     /* name-based shared memory */
-    else if (m->base) {
+    else {
         /* Indicate that the segment is to be destroyed as soon
          * as all processes have detached. This also disallows any
          * new attachments to the segment.
@@ -94,8 +94,7 @@
         }
     }
 cleanup:
-    if (m->filename)
-        free((void *)(m->filename));
+    x_free((void *)(m->filename));
     free(m);
     return rc;
 }
@@ -116,12 +115,11 @@
         rc = ACR_EINVAL;
     }
     else {
+        free((void *)(m->filename));
         if (m->base && shmdt(m->base) == -1) {
             rc = ACR_GET_OS_ERROR();
         }
     }
-    if (m->filename)
-        free((void *)(m->filename));
     free(m);
     return rc;
 }
@@ -418,16 +416,25 @@
 
 ACR_DECLARE(int) ACR_ShmDetach(JNIEnv *_E, int shm)
 {
+    int rc = 0;
     acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm);
 
     if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) {
-        return ACR_EINVAL;
-    }        
-    if (m->base && shmdt(m->base) == -1) {
-        return ACR_GET_OS_ERROR();
+        rc = ACR_EINVAL;
+        goto cleanup;
     }
-    m->base = NULL;
-    return 0;
+    x_free((void *)(m->filename));
+    m->filename = NULL;
+
+    rc = acr_ioh_close(shm);
+cleanup:
+    if (rc  && !IS_INVALID_HANDLE(_E)) {
+        if (rc == EACCES)
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+        else
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+    }
+    return rc;
 }
 
 ACR_DECLARE(int) ACR_ShmPermSet(JNIEnv *_E, int shm, int perms,

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c?rev=804251&r1=804250&r2=804251&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/shm.c Fri Aug 14 15:03:50 2009
@@ -60,8 +60,8 @@
         /* Remove file if file backed */
         if (!DeleteFileW(m->filename) && rc)
             rc = ACR_GET_OS_ERROR();
+        free((void *)(m->filename));
     }
-    x_free((void *)(m->filename));
     x_free(m);
     return rc;
 }
@@ -298,17 +298,25 @@
 
 ACR_DECLARE(int) ACR_ShmDetach(JNIEnv *_E, int shm)
 {
+    int rc;
     acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm);
 
     if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) {
-        return ACR_EINVAL;
-    }        
-    if (m->memblk && !UnmapViewOfFile(m->memblk)) {
-        return ACR_GET_OS_ERROR();
-    }
-    m->memblk = NULL;
-    m->usrmem = NULL;
-    return 0;
+        rc = ACR_EINVAL;
+        goto cleanup;
+    }
+    x_free((void *)(m->filename));
+    m->filename = NULL;
+
+    rc = acr_ioh_close(shm);
+cleanup:
+    if (rc && !IS_INVALID_HANDLE(_E)) {
+        if (rv == EACCES)
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+        else
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rc);
+    }
+    return rc;
 }
 
 ACR_DECLARE(int) ACR_ShmPermSet(JNIEnv *_E, int shm, int perms,

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=804251&r1=804250&r2=804251&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/test/testcase.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/test/testcase.c Fri Aug 14 15:03:50 2009
@@ -693,10 +693,6 @@
         rc = ACR_ShmAttach(_E, shr_name);
         fprintf(stdout, "\n\nRunning inside child process ...\n");
         fprintf(stdout, "Attach returned %d (errno=%d)\n", rc, errno);
-        if (rc > 0) {
-            rc = ACR_ShmClose(_E, rc);
-            fprintf(stdout, "Close returned %d\n", rc);
-        }
         fprintf(stdout, "Child process finished ...\n\n");        
         fflush(stdout);
         exit(0);