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

Re: [PATCH updated] Fallback on _NSGetExecutablePath to get the executable path if using argv[0] fails

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 29, 2010, 18:49 UTC
Message-ID
<20101129184929.GA9441@burratino>
In-Reply-To
<DD9829B7-8851-41CF-BCC6-2676B6015028@apple.com>
Jeremy Huddleston wrote:
Show 5 quoted lines
> This adds better support for RUNTIME_PREFIX on Mac OS X.  The previous codepath
> would only work if argv[0] contained the full path to the executable or $PATH
> already contained /path/to/libexec/git-core.  We use _NSGetExecutablePath here
> to find the full path (and thus prepend the correct libexec/git-core to $PATH)
> in the case where argv[0] does not contain the full path to the executable.

Closer. But that is perhaps too much at the level of code rather than the user:

	Subject: MacOSX: Use _NSGetExecutablePath to get full argv[0] path
	When RUNTIME_PREFIX support is enabled (which is common on Mac OS X)
	the exec-path is derived from the program invocation path.
	Unfortunately, usual Unix semantics are for argv[0] to contain
	the path used to invoke a program rather than the path to the
	executable.  So usual invocations of git would not result in
	helpers from exec-path being found correctly:
		$ git fast-import
		... example output here ...
	So in the spirit of v1.6.0-rc1~21 (Windows: make sure argv[0]
	has a path, 2008-07-21), use _NSGetExecutablePath to find the full
	path to the git binary, avoiding such trouble.
> --- a/exec_cmd.c
> +++ b/exec_cmd.c
[...]
Show 17 quoted lines
> @@ -53,6 +57,19 @@ const char *git_extract_argv0_path(const char *argv0)
>  	if (slash >= argv0) {
>  		argv0_path = xstrndup(argv0, slash - argv0);
>  		return slash + 1;
> +#if defined(__APPLE__)
> +	} else {
> +		char new_argv0[PATH_MAX];
> +		uint32_t new_argv0_s = PATH_MAX;
> +		if(_NSGetExecutablePath(new_argv0, &new_argv0_s) == 0) {
> +			slash = new_argv0 + strlen(new_argv0);
> +			while (new_argv0 <= slash && !is_dir_sep(*slash))
> +		                slash--;
> +
> +			if (slash >= new_argv0)
> +				argv0_path = xstrndup(new_argv0, slash - new_argv0);
> +		}
> +#endif

Can't this ifdef be avoided? The ideal is for such code to be abstracted away into helper functions in git-compat-util.h and compat/*.c.

Jonathan
Previous: Jeremy HuddlestonNext: Junio C Hamano
Message 5 of 14 in “Fallback on _NSGetExecutablePath to get the executable path if using argv[0] fails”
  1. Fallback on _NSGetExecutablePath to get the executable path if using argv[0] failsJeremy Huddleston, Nov 29, 2010
  2. Thiago FarinaNov 29, 2010
  3. Jonathan NiederNov 29, 2010
  4. Fallback on _NSGetExecutablePath to get the executable path if using argv[0] failsJeremy Huddleston, Nov 29, 2010
  5. Jonathan NiederNov 29, 2010
  6. Junio C HamanoNov 29, 2010
  7. Jeremy HuddlestonNov 29, 2010
  8. Jeremy HuddlestonNov 29, 2010
  9. Jonathan NiederNov 29, 2010
  10. Jeremy HuddlestonNov 29, 2010
  11. Jonathan NiederNov 29, 2010
  12. Kevin BallardNov 29, 2010
  13. Jonathan NiederDec 3, 2010
  14. Kevin BallardDec 3, 2010

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.