Skip to content

Commit

Permalink
i#58: properly parse the executable path on recent OSX kernels (#2266)
Browse files Browse the repository at this point in the history
The OSX kernel used to place the bare executable path above envp.
On recent XNU versions, the kernel now prefixes the executable path
with the string executable_path= so it can be parsed getenv style.
  • Loading branch information
shawndenbow authored Mar 6, 2017
1 parent d78c218 commit a7ff3fa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/unix/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,13 @@ set_executable_path(const char *exe_path)
NULL_TERMINATE_BUFFER(executable_path);
}

/* The OSX kernel used to place the bare executable path above envp.
* On recent XNU versions, the kernel now prefixes the executable path
* with the string executable_path= so it can be parsed getenv style.
*/
#ifdef MACOS
# define EXECUTABLE_KEY "executable_path="
#endif
/* i#189: we need to re-cache after a fork */
static char *
get_application_name_helper(bool ignore_cache, bool full_path)
Expand All @@ -1024,6 +1031,9 @@ get_application_name_helper(bool ignore_cache, bool full_path)
} while (*env != NULL);
env++; /* Skip the NULL separating the envp array from exec_path */
c = *env;
if (strncmp(EXECUTABLE_KEY, c, strlen(EXECUTABLE_KEY)) == 0) {
c += strlen(EXECUTABLE_KEY);
}
/* If our frontends always absolute-ize paths prior to exec,
* this should usually be absolute -- but we go ahead and
* handle relative just in case (and to handle child processes).
Expand Down

0 comments on commit a7ff3fa

Please sign in to comment.