From: Rich Felker Date: Fri, 11 Mar 2011 03:05:16 +0000 (-0500) Subject: fix failure behavior of sem_open when sem does not exist X-Git-Tag: v0.7.0~9 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=682a0f271f8b9a5842679a0f7070139a1f456c0d;p=oweals%2Fmusl.git fix failure behavior of sem_open when sem does not exist --- diff --git a/src/thread/sem_open.c b/src/thread/sem_open.c index 6fff71a8..809925d2 100644 --- a/src/thread/sem_open.c +++ b/src/thread/sem_open.c @@ -100,7 +100,7 @@ sem_t *sem_open(const char *name, int flags, ...) close(tfd); unlink(tmp); } - if (fstat(fd, &st) < 0) { + if (fd >= 0 && fstat(fd, &st) < 0) { close(fd); fd = -1; } @@ -118,6 +118,10 @@ sem_t *sem_open(const char *name, int flags, ...) break; } } + if (!(flags & O_CREAT)) { + pthread_spin_unlock(&lock); + return SEM_FAILED; + } if (!linkat(AT_FDCWD, tmp, dir, name, 0)) { fd = tfd; close(dir);