for (;;) {
if (!(flags & O_EXCL)) {
- fd = shm_open(name, flags&~O_CREAT, mode);
+ fd = shm_open(name, flags&~O_CREAT, 0);
if (fd >= 0 || errno != ENOENT) {
if (flags & O_CREAT) {
close(dir);
close(tfd);
unlink(tmp);
}
- if (fstat(fd, &st) < 0) {
+ if (fd >= 0 && fstat(fd, &st) < 0) {
close(fd);
fd = -1;
}
break;
}
}
+ if (!(flags & O_CREAT)) {
+ pthread_spin_unlock(&lock);
+ return SEM_FAILED;
+ }
if (!linkat(AT_FDCWD, tmp, dir, name, 0)) {
fd = tfd;
close(dir);