Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 61410 invoked from network); 22 Aug 2009 08:20:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 22 Aug 2009 08:20:52 -0000 Received: (qmail 80915 invoked by uid 500); 22 Aug 2009 08:21:13 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 80817 invoked by uid 500); 22 Aug 2009 08:21:13 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 80808 invoked by uid 99); 22 Aug 2009 08:21:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Aug 2009 08:21:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 22 Aug 2009 08:21:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4628823888FF; Sat, 22 Aug 2009 08:20:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r806808 - in /commons/sandbox/runtime/trunk/src/main/native/os: unix/dso.c unix/pmutex.c unix/psema.c unix/pshm.c win32/dso.c win32/pshm.c Date: Sat, 22 Aug 2009 08:20:48 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090822082048.4628823888FF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Sat Aug 22 08:20:47 2009 New Revision: 806808 URL: http://svn.apache.org/viewvc?rev=806808&view=rev Log: use EFTYPE/EBADF for descriptor handles Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c commons/sandbox/runtime/trunk/src/main/native/os/win32/pshm.c Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c?rev=806808&r1=806807&r2=806808&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/dso.c Sat Aug 22 08:20:47 2009 @@ -70,7 +70,7 @@ if (ACR_IOH_TYPE(dso) != ACR_DT_DSO) { ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE); - return ACR_EINVAL; + return ACR_EFTYPE; } rc = acr_ioh_close(dso); ACR_THROW_IO_IF_ERR(rc); @@ -82,8 +82,12 @@ int rc; void *handle = ACR_IOH(dso); - if (IS_INVALID_HANDLE(handle) || ACR_IOH_TYPE(dso) != ACR_DT_DSO) { - ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EINVAL); + if (ACR_IOH_TYPE(dso) != ACR_DT_DSO) { + ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE); + return NULL; + } + else if (IS_INVALID_HANDLE(handle)) { + ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EBADF); return NULL; } else { Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c?rev=806808&r1=806807&r2=806808&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pmutex.c Sat Aug 22 08:20:47 2009 @@ -89,23 +89,24 @@ if (m->filedes > 0) { union semun ick; if (m->locked) { + int rr; struct sembuf op; /* Unlock our instance */ op.sem_num = 0; op.sem_op = 1; op.sem_flg = SEM_UNDO; do { - rc = semop(m->filedes, &op, 1); - } while (rc < 0 && errno == EINTR); + rr = semop(m->filedes, &op, 1); + } while (rr < 0 && errno == EINTR); } ick.val = 0; semctl(m->filedes, 0, IPC_RMID, ick); } + else + rc = ACR_EBADF; if (m->filename) { - if (access(m->filename, F_OK)) { - rc = ACR_SUCCESS; - } - else { + if (!access(m->filename, F_OK)) { + /* File exists. Remove it */ if (unlink(m->filename)) rc = ACR_GET_OS_ERROR(); } @@ -114,13 +115,13 @@ free(m); return rc; } - return ACR_EBADF; + return ACR_EFTYPE; } static int mutex_child_cleanup(void *mutex, int type, unsigned int flags) { if (type == ACR_DT_MUTEX) { - int rc; + int rc = ACR_SUCCESS; acr_pmutex_t *m = (acr_pmutex_t *)mutex; if (m->filedes > 0) { if (m->locked) { @@ -134,10 +135,12 @@ } while (rc < 0 && errno == EINTR); } } + else + rc = ACR_EBADF; free(m); - return ACR_SUCCESS; + return rc; } - return ACR_EBADF; + return ACR_EFTYPE; } ACR_DECLARE(int) ACR_ProcMutexCreate(JNIEnv *_E, const acr_pchar_t *fname) @@ -288,9 +291,11 @@ struct sembuf op; acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { - ACR_SET_OS_ERROR(ACR_EINVAL); - return -1; + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { + return ACR_EINVAL; } op.sem_num = 0; op.sem_op = -1; @@ -313,7 +318,10 @@ struct sembuf op; acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { return ACR_EINVAL; } op.sem_num = 0; @@ -343,7 +351,10 @@ struct sembuf op; acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { return ACR_EINVAL; } @@ -368,7 +379,10 @@ struct semid_ds buf; acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { return ACR_EINVAL; } buf.sem_perm.uid = uid; @@ -441,10 +455,12 @@ if (sem_close(m->sem) < 0) rc = ACR_GET_OS_ERROR(); } + else + rc = ACR_EBADF; free(m); return rc; } - return ACR_EBADF; + return ACR_EFTYPE; } ACR_DECLARE(int) ACR_ProcMutexCreate(JNIEnv *_E, const acr_pchar_t *name) @@ -550,9 +566,11 @@ int rc; acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { - ACR_SET_OS_ERROR(ACR_EINVAL); - return -1; + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { + return ACR_EINVAL; } do { rc = sem_wait(m->sem); @@ -570,7 +588,10 @@ int rc; acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { return ACR_EINVAL; } do { @@ -592,7 +613,10 @@ int rc; acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { return ACR_EINVAL; } @@ -612,7 +636,10 @@ { acr_pmutex_t *m = (acr_pmutex_t *)ACR_IOH(mutex); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + if (ACR_IOH_TYPE(mutex) != ACR_DT_MUTEX) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(m)) { return ACR_EINVAL; } return ACR_ENOTIMPL; Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c?rev=806808&r1=806807&r2=806808&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/psema.c Sat Aug 22 08:20:47 2009 @@ -69,10 +69,12 @@ if (sem_close(s->sem) < 0) rc = ACR_GET_OS_ERROR(); } + else + rc = ACR_EBADF; free(s); return rc; } - return ACR_EBADF; + return ACR_EFTYPE; } ACR_DECLARE(int) ACR_SemaphoreCreate(JNIEnv *_E, const acr_pchar_t *name, @@ -205,8 +207,11 @@ { acr_semaphore_t *s = (acr_semaphore_t *)ACR_IOH(sema); - if (IS_INVALID_HANDLE(s) || ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { - return ACR_EINVAL; + if (ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(s)) { + return ACR_EBADF; } return ACR_ENOTIMPL; } @@ -216,8 +221,11 @@ int rc = 0; acr_semaphore_t *s = (acr_semaphore_t *)ACR_IOH(sema); - if (IS_INVALID_HANDLE(s) || ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { - return ACR_EINVAL; + if (ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(s)) { + return ACR_EBADF; } do { @@ -236,8 +244,11 @@ int rc = 0; acr_semaphore_t *s = (acr_semaphore_t *)ACR_IOH(sema); - if (IS_INVALID_HANDLE(s) || ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { - return ACR_EINVAL; + if (ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(s)) { + return ACR_EBADF; } do { @@ -259,8 +270,11 @@ int rc = 0; acr_semaphore_t *s = (acr_semaphore_t *)ACR_IOH(sema); - if (IS_INVALID_HANDLE(s) || ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { - return ACR_EINVAL; + if (ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(s)) { + return ACR_EBADF; } s->locked = 0; @@ -289,7 +303,10 @@ int rc = 0; acr_semaphore_t *s = (acr_semaphore_t *)ACR_IOH(sema); - if (IS_INVALID_HANDLE(s) || ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { + if (ACR_IOH_TYPE(sema) != ACR_DT_SEMAPHORE) { + return ACR_EFTYPE; + } + if (IS_INVALID_HANDLE(s)) { return ACR_EINVAL; } Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c?rev=806808&r1=806807&r2=806808&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/pshm.c Sat Aug 22 08:20:47 2009 @@ -75,7 +75,7 @@ acr_shm_t *m = (acr_shm_t *)shm; if (type != ACR_DT_SHM) { - return ACR_EINVAL; + return ACR_EFTYPE; } /* Anonymous shared memory or * we are calling this from forked child. @@ -97,12 +97,9 @@ } if (shmdt(m->base) == -1) { rc = ACR_GET_OS_ERROR(); - goto finally; - } - if (access(m->filename, F_OK)) { - rc = ACR_SUCCESS; } - else { + if (!access(m->filename, F_OK)) { + /* Remove existing file */ if (unlink(m->filename)) rc = ACR_GET_OS_ERROR(); } @@ -119,7 +116,7 @@ acr_shm_t *m = (acr_shm_t *)shm; if (type != ACR_DT_SHM) { - return ACR_EINVAL; + return ACR_EFTYPE; } if (m->filename == NULL) { @@ -140,16 +137,15 @@ ACR_DECLARE(int) ACR_ShmClose(JNIEnv *_E, int shm) { - int rv; + int rc; - rv = acr_ioh_close(shm); - if (rv && IS_VALID_HANDLE(_E)) { - if (rv == EACCES) - ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0); - else - ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO, rv); + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE); + return ACR_EFTYPE; } - return rv; + rc = acr_ioh_close(shm); + ACR_THROW_IO_IF_ERR(rc); + return rc; } ACR_DECLARE(int) ACR_ShmRemove(JNIEnv *_E, const acr_pchar_t *filename) @@ -407,8 +403,12 @@ 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; + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + rc = ACR_EFTYPE; + goto finally; + } + if (IS_INVALID_HANDLE(m)) { + rc = ACR_EBADF; goto finally; } x_free((void *)(m->filename)); @@ -429,8 +429,12 @@ int shmid; 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; + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + rc = ACR_EFTYPE; + goto finally; + } + if (IS_INVALID_HANDLE(m)) { + rc = ACR_EBADF; goto finally; } if ((shmid = shmget(m->shmkey, 0, SHM_R | SHM_W)) == -1) { @@ -454,8 +458,12 @@ { acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) { - ACR_SET_OS_ERROR(ACR_EINVAL); + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + ACR_SET_OS_ERROR(ACR_EFTYPE); + return NULL; + } + else if (IS_INVALID_HANDLE(m)) { + ACR_SET_OS_ERROR(ACR_EBADF); return NULL; } else @@ -465,8 +473,12 @@ ACR_DECLARE(acr_size_t) ACR_ShmGetSize(int shm) { acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) { - ACR_SET_OS_ERROR(ACR_EINVAL); + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + ACR_SET_OS_ERROR(ACR_EFTYPE); + return 0; + } + else if (IS_INVALID_HANDLE(m)) { + ACR_SET_OS_ERROR(ACR_EBADF); return 0; } else Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c?rev=806808&r1=806807&r2=806808&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/dso.c Sat Aug 22 08:20:47 2009 @@ -77,7 +77,7 @@ if (ACR_IOH_TYPE(dso) != ACR_DT_DSO) { ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE); - return ACR_EINVAL; + return ACR_EFTYPE; } rc = acr_ioh_close(dso); ACR_THROW_IO_IF_ERR(rc); @@ -89,8 +89,12 @@ int rc; void *handle = ACR_IOH(dso); - if (IS_INVALID_HANDLE(handle) || ACR_IOH_TYPE(dso) != ACR_DT_DSO) { - ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EINVAL); + if (ACR_IOH_TYPE(dso) != ACR_DT_DSO) { + ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE); + return NULL; + } + else if (IS_INVALID_HANDLE(handle)) { + ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EBADF); return NULL; } else { Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/pshm.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/pshm.c?rev=806808&r1=806807&r2=806808&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/pshm.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/pshm.c Sat Aug 22 08:20:47 2009 @@ -62,7 +62,7 @@ acr_shm_t *m = (acr_shm_t *)shm; if (type != ACR_DT_SHM) { - return ACR_EBADF; + return ACR_EFTYPE; } if (m->memblk && !UnmapViewOfFile(m->memblk)) { rc = ACR_GET_OS_ERROR(); @@ -87,6 +87,10 @@ { int rv; + if (ACR_IOH_TYPE(dso) != ACR_DT_SHM) { + ACR_THROW_EX_IF_ERR(ACR_EX_EINVAL, ACR_EFTYPE); + return ACR_EINVAL; + } rv = acr_ioh_close(shm); ACR_THROW_IO_IF_ERR(rv); return rv; @@ -311,7 +315,11 @@ int rc; acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + rc = ACR_EFTYPE; + goto finally; + } + if (IS_INVALID_HANDLE(m)) { rc = ACR_EINVAL; goto finally; } @@ -331,7 +339,11 @@ 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) { + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + rc = ACR_EFTYPE; + goto finally; + } + if (IS_INVALID_HANDLE(m)) { rc = ACR_EINVAL; goto finally; } @@ -345,7 +357,11 @@ { acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + ACR_SET_OS_ERROR(ACR_EFTYPE); + return NULL; + } + else if (IS_INVALID_HANDLE(m)) { ACR_SET_OS_ERROR(ACR_EINVAL); return NULL; } @@ -356,7 +372,11 @@ ACR_DECLARE(acr_size_t) ACR_ShmGetSize(int shm) { acr_shm_t *m = (acr_shm_t *)ACR_IOH(shm); - if (IS_INVALID_HANDLE(m) || ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + if (ACR_IOH_TYPE(shm) != ACR_DT_SHM) { + ACR_SET_OS_ERROR(ACR_EFTYPE); + return 0; + } + else if (IS_INVALID_HANDLE(m)) { ACR_SET_OS_ERROR(ACR_EINVAL); return 0; }