threads / patch / 2043

patchclose clobbers mmap's errno in read_cache

Subject: [PATCH] close clobbers mmap's errno in read_cache

## tl;dr

3 messages between Oct 7, 2005 and Oct 7, 2005. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Alex Riesen· Oct 7, 2005, 21:45 UTC · lore
Save errno before close(fd) for strerror in die().
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Show changes to read-cache.c +2 −1
--- a/read-cache.c	2005-10-03 09:16:31.000000000 +0200
+++ b/read-cache.c	2005-10-07 23:23:40.000000000 +0200
@@ -482,9 +482,10 @@ int read_cache(void)
 		if (size >= sizeof(struct cache_header) + 20)
 			map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
 	}
+	i = errno;
 	close(fd);
 	if (map == MAP_FAILED)
-		die("index file mmap failed (%s)", strerror(errno));
+		die("index file mmap failed (%s)", strerror(i));
 
 	hdr = map;
 	if (verify_hdr(hdr, size) < 0)
Sven Verdoolaege· Oct 7, 2005, 21:48 UTC · re: Alex Riesen · lore

Re: [PATCH] close clobbers mmap's errno in read_cache

On Fri, Oct 07, 2005 at 11:45:51PM +0200, Alex Riesen wrote:
Show 7 quoted lines
>  	}
> +	i = errno;
>  	close(fd);
>  	if (map == MAP_FAILED)
> -		die("index file mmap failed (%s)", strerror(errno));
> +		die("index file mmap failed (%s)", strerror(i));
>  

Why don't you just move the close after the test ? There's no point in closing if you're going to die.

skimo
Alex Riesen· Oct 7, 2005, 23:50 UTC · re: Sven Verdoolaege · lore

Re: [PATCH] close clobbers mmap's errno in read_cache

Sven Verdoolaege, Fri, Oct 07, 2005 23:48:45 +0200:
Show 10 quoted lines
> On Fri, Oct 07, 2005 at 11:45:51PM +0200, Alex Riesen wrote:
> >  	}
> > +	i = errno;
> >  	close(fd);
> >  	if (map == MAP_FAILED)
> > -		die("index file mmap failed (%s)", strerror(errno));
> > +		die("index file mmap failed (%s)", strerror(i));
> >  
> 
> Why don't you just move the close after the test ?
I don't know.
> There's no point in closing if you're going to die.
> 
> skimo
Of course you're right :) I'm just blind after eight.

← back to recent threads