about summary refs log tree commit diff
path: root/src/thread/sem_open.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-03-10 22:05:16 -0500
committerRich Felker <dalias@aerifal.cx>2011-03-10 22:05:16 -0500
commit682a0f271f8b9a5842679a0f7070139a1f456c0d (patch)
treea185a4c831fe0351e4c56a14ae7476d790bab136 /src/thread/sem_open.c
parentcfe581b6bc795e3f00ac30791314ec0f9be4b4ad (diff)
downloadmusl-682a0f271f8b9a5842679a0f7070139a1f456c0d.tar.gz
musl-682a0f271f8b9a5842679a0f7070139a1f456c0d.tar.xz
musl-682a0f271f8b9a5842679a0f7070139a1f456c0d.zip
fix failure behavior of sem_open when sem does not exist
Diffstat (limited to 'src/thread/sem_open.c')
-rw-r--r--src/thread/sem_open.c6
1 files changed, 5 insertions, 1 deletions
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);