checked, so they *might*), there is still a race possibility with the last
fix. This patch fixes that.
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, ...)
{
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);
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];