From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27011 invoked by alias); 27 Oct 2010 11:40:16 -0000 Received: (qmail 26989 invoked by uid 9699); 27 Oct 2010 11:40:15 -0000 Date: Wed, 27 Oct 2010 11:40:00 -0000 Message-ID: <20101027114015.26986.qmail@sourceware.org> From: mornfall@sourceware.org To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org Subject: LVM2/daemons/clvmd clvmd.c Mailing-List: contact lvm2-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: lvm2-cvs-owner@sourceware.org X-SW-Source: 2010-10/txt/msg00104.txt.bz2 CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: mornfall@sourceware.org 2010-10-27 11:40:15 Modified files: daemons/clvmd : clvmd.c Log message: 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. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd.c.diff?cvsroot=lvm2&r1=1.81&r2=1.82 --- LVM2/daemons/clvmd/clvmd.c 2010/10/27 09:13:37 1.81 +++ LVM2/daemons/clvmd/clvmd.c 2010/10/27 11:40:14 1.82 @@ -188,6 +188,14 @@ 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 @@ 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 @@ 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];