diff options
author | Gerald Combs <gerald@wireshark.org> | 2019-05-10 11:22:11 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2019-05-24 15:49:34 +0000 |
commit | f12ec0c9a36579e5d970207d601f98bc1d9e8c0e (patch) | |
tree | 35763f62b5c8cad0e6e39407fe43efff9a86c995 /wsutil/filesystem.c | |
parent | d5cdd9515fde13eab736eb155ead30ac371cd89a (diff) |
wsutil+macOS: Use realpath() to resolve our program path.
Use realpath() to resolve our program file directory on macOS. This lets
us create symlinks to the program files in our application bundle
without affecting our plugin and other paths.
Change-Id: If77cbd7da56e01f2cd602334d361c8aa52afeae0
Reviewed-on: https://code.wireshark.org/review/33151
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'wsutil/filesystem.c')
-rw-r--r-- | wsutil/filesystem.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index 0203ddf284..f2a05e3b98 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -315,13 +315,18 @@ static gboolean running_in_build_directory_flag = FALSE; * use realpath() if they want the real thing, but that's also true of * something obtained by looking at argv[0]. */ +#define xx_free free /* hack so checkAPIs doesn't complain */ static const char * get_executable_path(void) { #if defined(__APPLE__) - char *executable_path; + static char *executable_path; uint32_t path_buf_size; + if (executable_path) { + return executable_path; + } + path_buf_size = PATH_MAX; executable_path = (char *)g_malloc(path_buf_size); if (_NSGetExecutablePath(executable_path, &path_buf_size) == -1) { @@ -329,6 +334,16 @@ get_executable_path(void) if (_NSGetExecutablePath(executable_path, &path_buf_size) == -1) return NULL; } + /* + * Resolve our path so that it's possible to symlink the executables + * in our application bundle. + */ + char *rp_execpath = realpath(executable_path, NULL); + if (rp_execpath) { + g_free(executable_path); + executable_path = g_strdup(rp_execpath); + xx_free(rp_execpath); + } return executable_path; #elif defined(__linux__) /* |