restore signals in error case (shm allocation)
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 Aug 2011 14:12:43 +0000 (10:12 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 Aug 2011 14:12:43 +0000 (10:12 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libringbuffer/shm.c

index d86abb98e210fadece1e35a01e55fd7d29a07f90..0d92572d7b5b6170d79ed7e457e115bba957b7ef 100644 (file)
@@ -31,7 +31,7 @@ struct shm_object_table *shm_object_table_create(size_t max_nb_obj)
 struct shm_object *shm_object_table_append(struct shm_object_table *table,
                                           size_t memory_map_size)
 {
-       int shmfd, waitfd[2], ret, i;
+       int shmfd, waitfd[2], ret, i, sigblocked = 0;
        struct shm_object *obj;
        char *memory_map;
        char tmp_name[NAME_MAX] = "ust-shm-tmp-XXXXXX";
@@ -75,6 +75,7 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table,
                PERROR("pthread_sigmask");
                goto error_pthread_sigmask;
        }
+       sigblocked = 1;
 
        /*
         * Allocate shm, and immediately unlink its shm oject, keeping
@@ -107,10 +108,11 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table,
                PERROR("shm_unlink");
                goto error_shm_release;
        }
+       sigblocked = 0;
        ret = pthread_sigmask(SIG_SETMASK, &orig_sigs, NULL);
        if (ret == -1) {
                PERROR("pthread_sigmask");
-               goto error_shm_release;
+               goto error_sigmask_release;
        }
        ret = ftruncate(shmfd, memory_map_size);
        if (ret) {
@@ -136,12 +138,19 @@ struct shm_object *shm_object_table_append(struct shm_object_table *table,
 error_mmap:
 error_ftruncate:
 error_shm_release:
+error_sigmask_release:
        ret = close(shmfd);
        if (ret) {
                PERROR("close");
                assert(0);
        }
 error_shm_open:
+       if (sigblocked) {
+               ret = pthread_sigmask(SIG_SETMASK, &orig_sigs, NULL);
+               if (ret == -1) {
+                       PERROR("pthread_sigmask");
+               }
+       }
 error_pthread_sigmask:
 error_fcntl:
        for (i = 0; i < 2; i++) {
This page took 0.024393 seconds and 4 git commands to generate.