Module: xenomai-3
Branch: next
Commit: 1853acec4d2a790d47c8f1abebcec8eabb6fa9dc
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=1853acec4d2a790d47c8f1abebcec8eabb6fa9dc

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Tue Jun 30 20:26:08 2015 +0200

cobalt/posix/sem: Do not register named semaphores with process resources

Named semaphores are reclaimed via their own mechanism. Having them
registered also as process-local resource will cause their destruction
on process termination if no other process holds a reference. This is
not conforming to the specification, and the smokey leaks tests fails
due to this right now.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 kernel/cobalt/posix/sem.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/kernel/cobalt/posix/sem.c b/kernel/cobalt/posix/sem.c
index 08c4cc3..1c47f2a 100644
--- a/kernel/cobalt/posix/sem.c
+++ b/kernel/cobalt/posix/sem.c
@@ -50,7 +50,8 @@ int __cobalt_sem_destroy(xnhandle_t handle)
 
        cobalt_mark_deleted(sem);
        xnregistry_remove(sem->resnode.handle);
-       cobalt_del_resource(&sem->resnode);
+       if (!sem->pathname)
+               cobalt_del_resource(&sem->resnode);
        if (xnsynch_destroy(&sem->synchbase) == XNSYNCH_RESCHED) {
                xnsched_run();
                ret = 1;
@@ -106,9 +107,8 @@ __cobalt_sem_init(const char *name, struct 
cobalt_sem_shadow *sm,
        xnlock_get_irqsave(&nklock, s);
 
        semq = &cobalt_current_resources(pshared)->semq;
-       if (!list_empty(semq) &&
-           (sm->magic == COBALT_SEM_MAGIC ||
-            sm->magic == COBALT_NAMED_SEM_MAGIC)) {
+       if ((sm->magic == COBALT_SEM_MAGIC && !list_empty(semq)) ||
+           sm->magic == COBALT_NAMED_SEM_MAGIC) {
                osem = xnregistry_lookup(sm->handle, NULL);
                if (cobalt_obj_active(osem, COBALT_SEM_MAGIC, typeof(*osem))) {
                        ret = -EBUSY;
@@ -126,7 +126,10 @@ __cobalt_sem_init(const char *name, struct 
cobalt_sem_shadow *sm,
                goto err_lock_put;
 
        sem->magic = COBALT_SEM_MAGIC;
-       cobalt_add_resource(&sem->resnode, sem, pshared);
+       if (!name)
+               cobalt_add_resource(&sem->resnode, sem, pshared);
+       else
+               sem->resnode.scope = NULL;
        sflags = flags & SEM_FIFO ? 0 : XNSYNCH_PRIO;
        xnsynch_init(&sem->synchbase, sflags, NULL);
 
@@ -178,7 +181,7 @@ static int sem_destroy(struct cobalt_sem_shadow *sm)
                goto error;
        }
 
-       if (sem_kqueue(sem) != sem->resnode.scope) {
+       if (sem->resnode.scope && sem_kqueue(sem) != sem->resnode.scope) {
                ret = -EPERM;
                goto error;
        }
@@ -210,7 +213,7 @@ static inline int sem_trywait_inner(struct cobalt_sem *sem)
                return -EINVAL;
 
        if (IS_ENABLED(CONFIG_XENO_OPT_DEBUG_POSIX_SYNCHRO) &&
-           sem->resnode.scope != sem_kqueue(sem))
+           sem->resnode.scope && sem->resnode.scope != sem_kqueue(sem))
                return -EPERM;
 
        if (atomic_sub_return(1, &sem->state->value) < 0)
@@ -385,7 +388,7 @@ static int sem_getvalue(xnhandle_t handle, int *value)
                return -EINVAL;
        }
 
-       if (sem->resnode.scope != sem_kqueue(sem)) {
+       if (sem->resnode.scope && sem->resnode.scope != sem_kqueue(sem)) {
                xnlock_put_irqrestore(&nklock, s);
                return -EPERM;
        }


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to