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

[PATCH] Handle the errors from chdir in set_work_tree

From
Alex Riesen <raa.lkml@gmail.com>
Date
Aug 2, 2007, 15:27 UTC
Message-ID
<81b0412b0708020827p174515b7tc05fefde77f7d7c4@mail.gmail.com>

These I haven't seen yet. Wouldn't like such a surprise though. Also unstatic rel, it seems to be declared static accidentally.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---

One gets paranoid when exposed to "commercial" systems for too long.

 setup.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
From 602d49acd3e5285974cc1b7c4337301b13bb54b8 Mon Sep 17 00:00:00 2001
From: Alex Riesen <raa.lkml@gmail.com>
Date: Thu, 2 Aug 2007 16:51:57 +0200
Subject: [PATCH] Handle the errors from chdir in set_work_tree

These I haven't seen yet. Wouldn't like such a surprise though. Also unstatic rel, it seems to be declared static accidentally.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 setup.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/setup.c b/setup.c
index 1beba7e..4e6bb76 100644
--- a/setup.c
+++ b/setup.c
@@ -201,8 +201,8 @@ int is_inside_work_tree(void)
  */
 const char *set_work_tree(const char *dir)
 {
-	char dir_buffer[PATH_MAX];
-	static char buffer[PATH_MAX + 1], *rel = NULL;
+	char dir_buffer[PATH_MAX], *rel = NULL;
+	static char buffer[PATH_MAX + 1];
 	int len, postfix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1;
 
 	/* strip the variable 'dir' of the postfix "/.git" if it has it */
@@ -220,8 +220,10 @@ const char *set_work_tree(const char *dir)
 		if (!is_absolute_path(dir))
 			set_git_dir(make_absolute_path(dir));
 		dir = dir_buffer;
-		chdir(dir);
-		strcat(rel, "/");
+		if (chdir(dir))
+			rel = NULL;
+		else
+			strcat(rel, "/");
 		inside_git_dir = 0;
 	} else {
 		rel = NULL;
-- 
1.5.3.rc3.145.g4d9cdb
Next: Johannes Schindelin
Message 1 of 6 in “Handle the errors from chdir in set_work_tree”
  1. Handle the errors from chdir in set_work_treeAlex Riesen, Aug 2, 2007
  2. Johannes SchindelinAug 2, 2007
  3. Junio C HamanoAug 2, 2007
  4. Johannes SchindelinAug 2, 2007
  5. Alex RiesenAug 2, 2007
  6. Junio C HamanoAug 2, 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.