use O_CLOEXEC to open semaphore files in sem_open
authorRich Felker <dalias@aerifal.cx>
Sat, 29 Sep 2012 20:48:52 +0000 (16:48 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 29 Sep 2012 20:48:52 +0000 (16:48 -0400)
src/thread/sem_open.c

index d8d68392add362538a2c5c619db56c9792faba0c..0361a7695e387ce56e0e33fc3527878cb6a86b61 100644 (file)
@@ -75,9 +75,9 @@ sem_t *sem_open(const char *name, int flags, ...)
                clock_gettime(CLOCK_REALTIME, &ts);
                snprintf(tmp, sizeof(tmp), "/dev/shm/%p-%p-%d-%d",
                        &name, name, (int)getpid(), (int)ts.tv_nsec);
-               tfd = open(tmp, O_CREAT|O_EXCL|O_RDWR, mode);
+               tfd = open(tmp, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC, mode);
                if (tfd<0) return SEM_FAILED;
-               dir = open("/dev/shm", O_DIRECTORY|O_RDONLY);
+               dir = open("/dev/shm", O_DIRECTORY|O_RDONLY|O_CLOEXEC);
                if (dir<0 || write(tfd,&newsem,sizeof newsem)!=sizeof newsem) {
                        if (dir >= 0) close(dir);
                        close(tfd);