PERFORCE change 38205 for review
Hrishikesh Dandekar
hdandeka at FreeBSD.org
Thu Sep 18 00:18:36 GMT 2003
http://perforce.freebsd.org/chv.cgi?CH=38205
Change 38205 by hdandeka at hdandeka_yash on 2003/09/17 17:17:53
Integrate the POSIX global semaphore related changes to the libc.
Affected files ...
.. //depot/projects/trustedbsd/mac/lib/libc/sys/sem.c#5 integrate
.. //depot/projects/trustedbsd/mac/sys/kern/uipc_sem.c#11 edit
.. //depot/projects/trustedbsd/mac/sys/posix4/ksem.h#3 integrate
Differences ...
==== //depot/projects/trustedbsd/mac/lib/libc/sys/sem.c#5 (text+ko) ====
@@ -115,9 +115,11 @@
* Range check the arguments.
*/
if (pshared != 0) {
- retval = ksem_init(&semid, value);
- if (retval == -1)
+ if ((retval = ksem_init(&semid, value))) {
+ errno = retval;
+ retval = -1;
goto RETURN;
+ }
got_system_sem = 1;
}
@@ -128,7 +130,11 @@
retval = 0;
RETURN:
if (retval != 0 && got_system_sem)
- ksem_destroy(semid);
+ if ((retval = ksem_destroy(semid))) {
+ errno = retval;
+ retval = -1;
+ }
+
return retval;
}
@@ -145,8 +151,9 @@
* make sure there are no waiters.
*/
if ((*sem)->syssem != 0) {
- retval = ksem_destroy((*sem)->semid);
- if (retval == -1) {
+ if ((retval = ksem_destroy((*sem)->semid))) {
+ errno = retval;
+ retval = -1;
_pthread_mutex_unlock(&(*sem)->lock);
goto RETURN;
}
@@ -173,6 +180,7 @@
semid_t semid;
mode_t mode;
unsigned int value;
+ int retval;
mode = 0;
value = 0;
@@ -189,8 +197,10 @@
* we can be lazy and let the kernel handle the "oflag",
* we'll just merge duplicate IDs into our list.
*/
- if (ksem_open(&semid, name, oflag, mode, value) == -1)
+ if ((retval = ksem_open(&semid, name, oflag, mode, value))) {
+ errno = retval;
return (SEM_FAILED);
+ }
/*
* search for a duplicate ID, we must return the same sem_t *
* if we locate one.
@@ -214,7 +224,10 @@
return (sem);
err:
_pthread_mutex_unlock(&named_sems_mtx);
- ksem_close(semid);
+ if ((retval = ksem_close(semid))) {
+ errno = retval;
+ return (SEM_FAILED);
+ }
if (sem != NULL) {
if (*sem != NULL)
sem_free(*sem);
@@ -230,13 +243,15 @@
int
sem_close(sem_t *sem)
{
+ int retval;
if ((*sem)->syssem == 0) {
errno = EINVAL;
return (-1);
}
_pthread_mutex_lock(&named_sems_mtx);
- if (ksem_close((*sem)->semid) == -1) {
+ if ((retval = ksem_close((*sem)->semid))) {
+ errno = retval;
_pthread_mutex_unlock(&named_sems_mtx);
return (-1);
}
@@ -250,8 +265,13 @@
int
sem_unlink(const char *name)
{
+ int retval;
- return (ksem_unlink(name));
+ if ((retval = ksem_unlink(name))) {
+ errno = retval;
+ return (-1);
+ }
+ return (0);
}
int
@@ -262,8 +282,10 @@
_SEM_CHECK_VALIDITY(sem);
if ((*sem)->syssem != 0) {
- retval = ksem_wait((*sem)->semid);
- goto RETURN;
+ if ((retval = ksem_wait((*sem)->semid))) {
+ errno = retval;
+ return (-1);
+ }
}
_pthread_mutex_lock(&(*sem)->lock);
@@ -290,8 +312,10 @@
_SEM_CHECK_VALIDITY(sem);
if ((*sem)->syssem != 0) {
- retval = ksem_trywait((*sem)->semid);
- goto RETURN;
+ if ((retval = ksem_trywait((*sem)->semid))) {
+ errno = retval;
+ return (-1);
+ }
}
_pthread_mutex_lock(&(*sem)->lock);
@@ -318,8 +342,10 @@
_SEM_CHECK_VALIDITY(sem);
if ((*sem)->syssem != 0) {
- retval = ksem_post((*sem)->semid);
- goto RETURN;
+ if ((retval = ksem_post((*sem)->semid))) {
+ errno = retval;
+ return (-1);
+ }
}
_pthread_mutex_lock(&(*sem)->lock);
@@ -343,8 +369,10 @@
_SEM_CHECK_VALIDITY(sem);
if ((*sem)->syssem != 0) {
- retval = ksem_getvalue((*sem)->semid, sval);
- goto RETURN;
+ if ((retval = ksem_getvalue((*sem)->semid, sval))) {
+ errno = retval;
+ return (-1);
+ }
}
_pthread_mutex_lock(&(*sem)->lock);
==== //depot/projects/trustedbsd/mac/sys/kern/uipc_sem.c#11 (text+ko) ====
@@ -332,18 +332,15 @@
{
char name[SEM_MAX_NAMELEN + 1];
size_t done;
- int error;
+ int error = 0;
- error = copyinstr(uap->name, name, SEM_MAX_NAMELEN + 1, &done);
- if (error)
- return (-1);
+ if ((error = copyinstr(uap->name, name, SEM_MAX_NAMELEN + 1, &done)))
+ return (error);
DP((">>> sem_open start\n"));
error = kern_sem_open(td, UIO_USERSPACE,
name, uap->oflag, uap->mode, uap->value, uap->idp);
DP(("<<< sem_open end\n"));
- if(error)
- return (-1);
- return (0);
+ return (error);
}
static int
@@ -628,7 +625,7 @@
const char *name;
{
struct ksem *ks;
- int error;
+ int error = 0;
mtx_lock(&sem_lock);
ks = sem_lookup_byname(name);
@@ -676,10 +673,10 @@
struct ksem *ks;
int error;
- error = EINVAL;
mtx_lock(&sem_lock);
ks = ID_TO_SEM(id);
/* this is not a valid operation for unnamed sems */
+ error = EINVAL;
if (ks != NULL && ks->ks_name != NULL) {
#ifdef MAC
if ((error = mac_check_posix_sem_close(td->td_ucred, ks))) {
@@ -826,7 +823,6 @@
goto err_wait;
}
ks->ks_value--;
- error = 0;
err_wait:
mtx_unlock(&ks->ks_mtx);
DP(("<<< kern_sem_wait leaving, error = %d\n", error));
==== //depot/projects/trustedbsd/mac/sys/posix4/ksem.h#3 (text+ko) ====
@@ -69,9 +69,9 @@
struct cv ks_cv; /* waiters sleep here */
int ks_waiters; /* number of waiters */
LIST_HEAD(, kuser) ks_users; /* pids using this sem */
- struct mtx ks_mtx; /* mutex protecting the ks_users list */
+ struct mtx ks_mtx; /* mutex protecting this semaphore */
+ int ks_unlinked; /* Whether the named sem is unlinked */
struct label ks_label; /* MAC label */
- int ks_unlinked; /* Whether the named sem is unlinked */
};
#endif /* _KERNEL */
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list