- if (fstat(fd, &st) < 0) return 0;
- if (!(f = fopen("/proc/self/maps", "rb"))) return 0;
-
- while (fgets(buf, sizeof buf, f)) {
- sscanf(buf, "%lx-%*lx %*s %llx %*x:%*x %llu /dev/shm%c",
- (long *)&addr, &off, &ino, &c);
- while (!strchr(buf, '\n') && fgets(buf, sizeof buf, f));
- if (c!='/') continue;
- c = 0;
- if (!off && st.st_ino == ino) {
- fclose(f);
- return addr;
- }
- }
- fclose(f);
- return 0;
+static sem_t *find_map(ino_t ino)
+{
+ int i;
+ for (i=0; i<SEM_NSEMS_MAX && semtab[i].ino != ino; i++);
+ if (i==SEM_NSEMS_MAX) return 0;
+ if (semtab[i].refcnt == INT_MAX) return (sem_t *)-1;
+ semtab[i].refcnt++;
+ return semtab[i].sem;