]> sourceware.org Git - lvm2.git/commitdiff
Alasdair correctly pointed out that if the two closes are concurrent (I haven't
authorPetr Rockai <prockai@redhat.com>
Wed, 27 Oct 2010 11:40:14 +0000 (11:40 +0000)
committerPetr Rockai <prockai@redhat.com>
Wed, 27 Oct 2010 11:40:14 +0000 (11:40 +0000)
checked, so they *might*), there is still a race possibility with the last
fix. This patch fixes that.

daemons/clvmd/clvmd.c

index b1500ab62fa981c3be53e2754e6fbc46fadbc9f9..706f15bcc1492015296b491bfe97f719320f9449 100644 (file)
@@ -188,6 +188,14 @@ static void child_init_signal(int status)
                exit(status);
 }
 
+static void safe_close(int *fd)
+{
+       if (*fd >= 0) {
+               int to_close = *fd;
+               *fd = -1;
+               close(to_close);
+       }
+}
 
 void debuglog(const char *fmt, ...)
 {
@@ -838,10 +846,7 @@ static void main_loop(int local_sock, int cmd_timeout)
                                                lastfd->next = thisfd->next;
                                                free_fd = thisfd;
                                                thisfd = lastfd;
-                                               if (free_fd->fd >= 0) {
-                                                       close(free_fd->fd);
-                                                       free_fd->fd = -1;
-                                               }
+                                               safe_close(&(free_fd->fd));
 
                                                /* Queue cleanup, this also frees the client struct */
                                                add_to_lvmqueue(free_fd, NULL, 0, NULL);
@@ -1091,10 +1096,7 @@ static int read_from_local_sock(struct local_client *thisfd)
                        thisfd->bits.localsock.pipe_client->bits.pipe.client =
                            NULL;
 
-               if (thisfd->fd >= 0) {
-                       close(thisfd->fd);
-                       thisfd->fd = -1;
-               }
+               safe_close(&(thisfd->fd));
                return 0;
        } else {
                int comms_pipe[2];
This page took 0.038475 seconds and 5 git commands to generate.