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

[PATCH 1/3] create_symref: check error return from open().

From
Junio C Hamano <junkio@cox.net>
Date
Jan 27, 2007, 01:46 UTC
Message-ID
<7v64ats0m3.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vbqkluzcm.fsf@assigned-by-dhcp.cox.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * There seem to be similarly "casual" users of open in the rest
   of the code, but I noticed this while looking at your series.
   I've already done the necessary shuffling in my tree, so
   there is no need to resend your "move create_symref()".
 refs.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/refs.c b/refs.c
index 0840b3b..12e46b8 100644
--- a/refs.c
+++ b/refs.c
@@ -331,7 +331,11 @@ int create_symref(const char *ref_target, const char *refs_heads_master)
 		return -1;
 	}
 	lockpath = mkpath("%s.lock", git_HEAD);
-	fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);	
+	fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
+	if (fd < 0) {
+		error("Unable to open %s for writing", lockpath);
+		return -5;
+	}
 	written = write_in_full(fd, ref, len);
 	close(fd);
 	if (written != len) {
-- 
1.5.0.rc2.g8ac6-dirty
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 4 in “reflog for HEAD (detached or between branches)”
  1. Nicolas PitreJan 26, 2007
  2. Junio C HamanoJan 26, 2007
  3. 1/3 create_symref: check error return from open().Junio C Hamano, Jan 27, 2007
  4. 3/3 write_in_full: size_t is unsigned.Junio C Hamano, Jan 27, 2007

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.