From a91b25dc1ccdc74ed92f7887caf8a7a6c8b1fcdb Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Tue, 14 Jan 2003 03:36:45 +0000 Subject: [PATCH] Add the newly created semaphore to the named semaphore list in sem_open() so that multiple opens of the same semaphore without an intervening sem_close() return the same object, and so that sem_close() does not segfault while trying to remove the item from the list. --- lib/libc/gen/sem.c | 3 ++- lib/libc/sys/sem.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/libc/gen/sem.c b/lib/libc/gen/sem.c index fbed62a7138b..d1cf10e1f7e2 100644 --- a/lib/libc/gen/sem.c +++ b/lib/libc/gen/sem.c @@ -206,8 +206,9 @@ sem_open(const char *name, int oflag, ...) *sem = sem_alloc(value, semid, 1); if ((*sem) == NULL) goto err; - _pthread_mutex_unlock(&named_sems_mtx); + LIST_INSERT_HEAD(&named_sems, *sem, entry); (*sem)->backpointer = sem; + _pthread_mutex_unlock(&named_sems_mtx); return (sem); err: _pthread_mutex_unlock(&named_sems_mtx); diff --git a/lib/libc/sys/sem.c b/lib/libc/sys/sem.c index fbed62a7138b..d1cf10e1f7e2 100644 --- a/lib/libc/sys/sem.c +++ b/lib/libc/sys/sem.c @@ -206,8 +206,9 @@ sem_open(const char *name, int oflag, ...) *sem = sem_alloc(value, semid, 1); if ((*sem) == NULL) goto err; - _pthread_mutex_unlock(&named_sems_mtx); + LIST_INSERT_HEAD(&named_sems, *sem, entry); (*sem)->backpointer = sem; + _pthread_mutex_unlock(&named_sems_mtx); return (sem); err: _pthread_mutex_unlock(&named_sems_mtx);