1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00

Alasdair correctly pointed out that if the two closes are concurrent (I haven't

checked, so they *might*), there is still a race possibility with the last
fix. This patch fixes that.
This commit is contained in:
Petr Rockai 2010-10-27 11:40:14 +00:00
parent b2959bde18
commit 63b8dfbde7

View File

@ -188,6 +188,14 @@ static void child_init_signal(int status)
exit(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, ...) void debuglog(const char *fmt, ...)
{ {
@ -838,10 +846,7 @@ static void main_loop(int local_sock, int cmd_timeout)
lastfd->next = thisfd->next; lastfd->next = thisfd->next;
free_fd = thisfd; free_fd = thisfd;
thisfd = lastfd; thisfd = lastfd;
if (free_fd->fd >= 0) { safe_close(&(free_fd->fd));
close(free_fd->fd);
free_fd->fd = -1;
}
/* Queue cleanup, this also frees the client struct */ /* Queue cleanup, this also frees the client struct */
add_to_lvmqueue(free_fd, NULL, 0, NULL); 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 = thisfd->bits.localsock.pipe_client->bits.pipe.client =
NULL; NULL;
if (thisfd->fd >= 0) { safe_close(&(thisfd->fd));
close(thisfd->fd);
thisfd->fd = -1;
}
return 0; return 0;
} else { } else {
int comms_pipe[2]; int comms_pipe[2];