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 6fff71a..809925d 100644
--- a/src/thread/sem_open.c
+++ b/src/thread/sem_open.c
@@ -100,7 +100,7 @@
close(tfd);
unlink(tmp);
}
- if (fstat(fd, &st) < 0) {
+ if (fd >= 0 && fstat(fd, &st) < 0) {
close(fd);
fd = -1;
}
@@ -118,6 +118,10 @@
break;
}
}
+ if (!(flags & O_CREAT)) {
+ pthread_spin_unlock(&lock);
+ return SEM_FAILED;
+ }
if (!linkat(AT_FDCWD, tmp, dir, name, 0)) {
fd = tfd;
close(dir);