fix shm_open wrongly being cancellable
authorRich Felker <dalias@aerifal.cx>
Sat, 20 Jul 2013 17:19:14 +0000 (13:19 -0400)
committerRich Felker <dalias@aerifal.cx>
Sat, 20 Jul 2013 17:19:14 +0000 (13:19 -0400)
src/mman/shm_open.c

index b23eac7fa1df901c42f091fd122e593941448b47..d042a5a882bd347dd937bceb8f851bb98cb418b8 100644 (file)
@@ -4,6 +4,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <limits.h>
+#include <pthread.h>
 
 char *__strchrnul(const char *, int);
 
@@ -27,9 +28,13 @@ char *__shm_mapname(const char *name, char *buf)
 
 int shm_open(const char *name, int flag, mode_t mode)
 {
+       int cs;
        char buf[NAME_MAX+10];
        if (!(name = __shm_mapname(name, buf))) return -1;
-       return open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
+       pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+       int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
+       pthread_setcancelstate(cs, 0);
+       return fd;
 }
 
 int shm_unlink(const char *name)