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

Re: [Bug] wrapper.c uses unportable unsetenv

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 29, 2021, 20:35 UTC
Message-ID
<xmqqsfwjk1s3.fsf@gitster.g>
In-Reply-To
<012301d7cd01$90428960$b0c79c20$@nexbridge.com>
<rsbecker@nexbridge.com> writes:
Show 7 quoted lines
> The unsetenv()/setenv(overwrite) calls are not 100% portable - as in not on
> all POSIX implementations. It breaks the build on some of the NonStop
> platforms. This will change in a year or two but I really don't want to fall
> behind on git releases.
>
> This was introduced at 3540c71 but I was on vacation when it happened so did
> not catch it during reviews - my apologies for that.

I do not quite understand. xsetenv() does use the three-arg setenv(), but that is not anything new. It merely replaced a call to the same three-arg setenv() in environment.c that have already been there, introduced by d7ac12b2 (Add set_git_dir() function, 2007-08-01).

You may argue that 3540c71 has done a shoddy job by introducing xunsetenv() without adding any caller, and to this day, we do not have a single caller to the wrapper, but we already have a few calls to unsetenv() that is compiled unconditionally.

So if you built any version of Git, you must have had these somehow "available" in your build (e.g. your system headers may have made them a no-op), and I'd expect you'd keep doing the same to locally work it around on the platform side, without ...

> Is it critical that this be called or can we #ifdef it away if it isn't
> supported for a build? The #if is exactly this:

... doing something like this in the generic part of the code. Please don't do this.

Show 13 quoted lines
> wrapper.c@150
> + #if (_TANDEM_ARCH_ > 3 || (_TANDEM_ARCH_ == 3 && __L_Series_RVU >= 2010))
> 	if (setenv(name, value, overwrite))
> 		die_errno(_("could not setenv '%s'"), name ? name :
> "(null)");
> + #endif
>
> wrapper.c@154
> + #if (_TANDEM_ARCH_ > 3 || (_TANDEM_ARCH_ == 3 && __L_Series_RVU >= 2010))
> 	if (!unsetenv(name))
> 		die_errno(_("could not unsetenv '%s'"), name ? name :
> "(null)");
> + #endif

There are compat/setenv.c and compat/unsetenv.c to be used when NO_SETENV and NO_UNSETENV are defined. Is that how you built your Git earlier since 2007, perhaps?

Previous: rsbecker@nexbridge.comNext: rsbecker@nexbridge.com
Message 2 of 7 in “[Bug] wrapper.c uses unportable unsetenv”
  1. rsbecker@nexbridge.comOct 29, 2021
  2. Junio C HamanoOct 29, 2021
  3. rsbecker@nexbridge.comOct 29, 2021
  4. rsbecker@nexbridge.comOct 29, 2021
  5. Junio C HamanoOct 29, 2021
  6. Johannes SchindelinOct 29, 2021
  7. Junio C HamanoOct 29, 2021

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.