All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] read_index_from: remove bogus errno assignments
@ 2012-08-06 11:27 Nguyễn Thái Ngọc Duy
  2012-08-06 17:03 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-08-06 11:27 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Thomas Gummerer, Nguyễn Thái Ngọc Duy

These assignments comes from the very first commit e83c516 (Initial
revision of "git", the information manager from hell - 2005-04-07).
Back then we did not die() when errors happened so correct errno was
required.

Since 5d1a5c0 ([PATCH] Better error reporting for "git status" -
2005-10-01), read_index_from() learned to die rather than just return
-1 and these assignments became irrelevant. Remove them.

While at it, move die_errno() next to xmmap() call because it's the
mmap's error code that we care about. Otherwise if close(fd); fails,
it could overwrite mmap's errno.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I saw the last hunk in this patch from 01/16 in Thomas's index v5
 series. But it looks more like an independent change. Thomas moved
 read_index_from code so this patch will cause conflicts with his
 series. It's a good change though, I think.

 read-cache.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index 2f8159f..76513cd 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1414,11 +1414,9 @@ int read_index_from(struct index_state *istate, const char *path)
 	size_t mmap_size;
 	struct strbuf previous_name_buf = STRBUF_INIT, *previous_name;
 
-	errno = EBUSY;
 	if (istate->initialized)
 		return istate->cache_nr;
 
-	errno = ENOENT;
 	istate->timestamp.sec = 0;
 	istate->timestamp.nsec = 0;
 	fd = open(path, O_RDONLY);
@@ -1431,15 +1429,14 @@ int read_index_from(struct index_state *istate, const char *path)
 	if (fstat(fd, &st))
 		die_errno("cannot stat the open index");
 
-	errno = EINVAL;
 	mmap_size = xsize_t(st.st_size);
 	if (mmap_size < sizeof(struct cache_header) + 20)
 		die("index file smaller than expected");
 
 	mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
-	close(fd);
 	if (mmap == MAP_FAILED)
 		die_errno("unable to map index file");
+	close(fd);
 
 	hdr = mmap;
 	if (verify_hdr(hdr, mmap_size) < 0)
@@ -1495,7 +1492,6 @@ int read_index_from(struct index_state *istate, const char *path)
 
 unmap:
 	munmap(mmap, mmap_size);
-	errno = EINVAL;
 	die("index file corrupt");
 }
 
-- 
1.7.8

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] read_index_from: remove bogus errno assignments
  2012-08-06 11:27 [PATCH] read_index_from: remove bogus errno assignments Nguyễn Thái Ngọc Duy
@ 2012-08-06 17:03 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2012-08-06 17:03 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Thomas Gummerer

Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:

> While at it, move die_errno() next to xmmap() call because it's the
> mmap's error code that we care about. Otherwise if close(fd); fails,
> it could overwrite mmap's errno.

Makes sense and is a sensible fix.

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-08-06 17:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-06 11:27 [PATCH] read_index_from: remove bogus errno assignments Nguyễn Thái Ngọc Duy
2012-08-06 17:03 ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.