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

Re: [PATCH 3/3] Replace setenv(GIT_DIR_ENVIRONMENT, ...) with set_git_dir()

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 22, 2007, 22:09 UTC
Message-ID
<Pine.LNX.4.64.0711222149390.27959@racer.site>
In-Reply-To
<3B6B19E6-255F-4D8F-B6A3-255A9E8E0AB0@zib.de>
Hi,
On Thu, 22 Nov 2007, Steffen Prohaska wrote:
> Yes, and apparently even nobody knows how to trigger the problem on 
> Windows.

A quick and easy way would be to instrument getenv(), unsetenv() and setenv(), which would trigger an error. Something like this (but you will have to put in a few "extern called_getenv; called_getenv = 0;", since already a simple git-init fails because of setup_path()):

-- snipsnap -- [PATCH] Instrument getenv(), setenv(), unsetenv() and putenv()

... for finding places where a pointer obtained by getenv() could be invalidated later.

---
 environment.c     |    1 +
 git-compat-util.h |   31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/environment.c b/environment.c
index ce75e98..027340e 100644
--- a/environment.c
+++ b/environment.c
@@ -9,6 +9,7 @@
  */
 #include "cache.h"
 
+int called_setenv, called_getenv;
 char git_default_email[MAX_GITNAME];
 char git_default_name[MAX_GITNAME];
 int trust_executable_bit = 1;
diff --git a/git-compat-util.h b/git-compat-util.h
index 79eb10e..a41469b 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -427,4 +427,35 @@ static inline int strtol_i(char const *s, int base, int *result)
 	return 0;
 }
 
+extern int called_setenv, called_getenv;
+static inline char *test_getenv(const char *name)
+{
+	if (!called_setenv)
+		warning ("called test_getenv %s", name);
+	called_getenv = 1;
+	return getenv(name);
+}
+static inline int test_setenv(const char *name, const char *value, int overwrite)
+{
+	if (!called_setenv && called_getenv)
+		die ("getenv was called before setenv(%s, %s, %d)",
+				name, value, overwrite);
+	return setenv(name, value, overwrite);
+}
+static inline int test_unsetenv(const char *name)
+{
+	if (!called_setenv && called_getenv)
+		die ("getenv was called before unsetenv(%s)", name);
+	return unsetenv(name);
+}
+static inline int test_putenv(char *string)
+{
+	if (!called_setenv && called_getenv)
+		die ("getenv was called before putenv(%s)", string);
+	return putenv(string);
+}
+#define getenv test_getenv
+#define setenv test_setenv
+#define unsetenv test_unsetenv
+
 #endif
Previous: Steffen ProhaskaNext: Steffen Prohaska
Message 12 of 18 in “msysgit fallout”
  1. 0/3 msysgit falloutSteffen Prohaska, Nov 21, 2007
  2. 1/3 sha1_file.c: Fix size_t related printf format warningsSteffen Prohaska, Nov 21, 2007
  3. 2/3 builtin-init-db: use get_git_dir() instead of getenv()Steffen Prohaska, Nov 21, 2007
  4. 3/3 Replace setenv(GIT_DIR_ENVIRONMENT, ...) with set_git_dir()Steffen Prohaska, Nov 21, 2007
  5. Johannes SchindelinNov 22, 2007
  6. Junio C HamanoNov 22, 2007
  7. Steffen ProhaskaNov 22, 2007
  8. Junio C HamanoNov 22, 2007
  9. Steffen ProhaskaNov 22, 2007
  10. Johannes SixtNov 22, 2007
  11. Steffen ProhaskaNov 22, 2007
  12. Johannes SchindelinNov 22, 2007
  13. Steffen ProhaskaJan 1, 2008
  14. Dmitry KakurinJan 3, 2008
  15. Steffen ProhaskaJan 3, 2008
  16. Dmitry KakurinJan 3, 2008
  17. Steffen ProhaskaJan 3, 2008
  18. Johannes SixtNov 22, 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.