git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: fatal: unable to write sha1 file git 1.6.2.1

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 25, 2009, 00:03 UTC
Message-ID
<alpine.LFD.2.00.0903241655210.3032@localhost.localdomain>
In-Reply-To
<49C961D0.4010704@mycircuit.org>
On Tue, 24 Mar 2009, Peter wrote:
Show 7 quoted lines
>
> Thanks a lot , I will check that out tomorrow, in the meantime, this is the
> result of your patch being applied:
> 
> $ git add <big stuff>
> 
> fatal: error when closing sha1 file (Bad file descriptor)
Ok, that's probably cifs_writepages() doing
                        open_file = find_writable_file(CIFS_I(mapping->host));
                        if (!open_file) {
                                cERROR(1, ("No writable handles for inode"));
                                rc = -EBADF;
			} else {
				..
so yeah, looks like it's the fchmod() that triggers it.

I suspect this would be a safer - if slightly slower - way to make sure the file is read-only. It's slower, because it is going to look up the filename once more, but I bet it is going to avoid this particular CIFS bug.

			Linus
---
 http-push.c |    2 +-
 sha1_file.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/http-push.c b/http-push.c
index 48e5f38..ba4fa4d 100644
--- a/http-push.c
+++ b/http-push.c
@@ -748,8 +748,8 @@ static void finish_request(struct transfer_request *request)
 			aborted = 1;
 		}
 	} else if (request->state == RUN_FETCH_LOOSE) {
-		fchmod(request->local_fileno, 0444);
 		close(request->local_fileno); request->local_fileno = -1;
+		chmod(request->tmpfile, 0444);
 
 		if (request->curl_result != CURLE_OK &&
 		    request->http_code != 416) {
diff --git a/sha1_file.c b/sha1_file.c
index 4563173..8268da7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2285,9 +2285,8 @@ static void close_sha1_file(int fd)
 {
 	if (fsync_object_files)
 		fsync_or_die(fd, "sha1 file");
-	fchmod(fd, 0444);
 	if (close(fd) != 0)
-		die("unable to write sha1 file");
+		die("error when closing sha1 file (%s)", strerror(errno));
 }
 
 /* Size of directory component, including the ending '/' */
@@ -2384,6 +2383,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
 	close_sha1_file(fd);
 	free(compressed);
 
+	chmod(tmpfile, 0444);
 	if (mtime) {
 		struct utimbuf utb;
 		utb.actime = mtime;
Previous: PeterNext: Jeff Layton
Message 7 of 13 in “fatal: unable to write sha1 file git 1.6.2.1”
  1. PeterMar 24, 2009
  2. Nicolas PitreMar 24, 2009
  3. Linus TorvaldsMar 24, 2009
  4. PeterMar 24, 2009
  5. Linus TorvaldsMar 24, 2009
  6. PeterMar 24, 2009
  7. Linus TorvaldsMar 25, 2009
  8. Jeff LaytonMar 25, 2009
  9. Jeff LaytonMar 24, 2009
  10. Linus TorvaldsMar 25, 2009
  11. Steven FrenchMar 25, 2009
  12. Jeff LaytonMar 25, 2009
  13. PeterMar 25, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.