Make more code be protected by internal mutex, and now it is fork-safe, in

error case, the file exclusive lock is now released as soon as possible,
in previous code, child process can still hold the exclusive lock.
This commit is contained in:
David Xu 2013-02-17 02:52:42 +00:00
parent d7aa5f02d0
commit 17001e0b94

View File

@ -229,18 +229,18 @@ _sem_open(const char *name, int flags, ...)
ni->open_count = 1;
ni->sem = sem;
LIST_INSERT_HEAD(&sem_list, ni, next);
_pthread_mutex_unlock(&sem_llock);
_close(fd);
_pthread_mutex_unlock(&sem_llock);
return (sem);
error:
errsave = errno;
_pthread_mutex_unlock(&sem_llock);
if (fd != -1)
_close(fd);
if (sem != NULL)
munmap(sem, sizeof(sem_t));
free(ni);
_pthread_mutex_unlock(&sem_llock);
errno = errsave;
return (SEM_FAILED);
}