Add a routine to get the path of an executable given the program name.

That reduces the number of get_progfile_dir() calls, leaving only the
calls that are done either to 1) get the pathname in order to display it
or 2) get the pathname in order to reset the library path.

That makes it easier to figure out which get_progfile_dir() calls are
made to find the directory in which (non-extcap) binaries from Wireshark
are installed and which - if any - are made to figure out the directory
in which *the currently-running executable* are stored.  (Currently,
get_progfile_dir() attemps to get the former, not the latter, so
extcaps in an extcap subdirectory, for example, will get the parent
directory of that subdirectory, *not* the directory in which they weere
installed.)
This commit is contained in:
Guy Harris 2022-12-22 22:37:45 -08:00 committed by Gerald Combs
parent 44511c318d
commit 13f3ebc4e5
6 changed files with 48 additions and 16 deletions

View File

@ -220,13 +220,13 @@ sync_pipe_add_arg(char **args, int *argc, const char *arg)
/* Initialize an argument list and add dumpcap to it. */
static char **
init_pipe_args(int *argc) {
char **argv;
const char *progfile_dir;
char *exename;
char **argv;
progfile_dir = get_progfile_dir();
if (progfile_dir == NULL) {
return NULL;
/* Find the absolute path of the dumpcap executable. */
exename = get_executable_path("dumpcap");
if (exename == NULL) {
return NULL;
}
/* Allocate the string pointer array with enough space for the
@ -235,13 +235,6 @@ init_pipe_args(int *argc) {
argv = (char **)g_malloc(sizeof (char *));
*argv = NULL;
/* take Wireshark's absolute program path and replace "Wireshark" with "dumpcap" */
#ifdef _WIN32
exename = ws_strdup_printf("%s\\dumpcap.exe", progfile_dir);
#else
exename = ws_strdup_printf("%s/dumpcap", progfile_dir);
#endif
/* Make that the first argument in the argument list (argv[0]). */
argv = sync_pipe_add_arg(argv, argc, exename);

View File

@ -455,7 +455,7 @@ static void mmdb_resolve_start(void) {
}
GPtrArray *args = g_ptr_array_new();
char *mmdbresolve = ws_strdup_printf("%s%c%s", get_progfile_dir(), G_DIR_SEPARATOR, "mmdbresolve");
char *mmdbresolve = get_executable_path("mmdbresolve");
g_ptr_array_add(args, mmdbresolve);
for (guint i = 0; i < mmdb_file_arr->len; i++) {
g_ptr_array_add(args, g_strdup("-f"));

View File

@ -96,6 +96,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
get_datafile_dir@Base 1.12.0~rc1
get_datafile_path@Base 1.12.0~rc1
get_dirname@Base 1.12.0~rc1
get_executable_path@Base 4.1.0
get_extcap_dir@Base 1.99.0
get_friendly_program_name@Base 3.5.0
get_global_profiles_dir@Base 1.12.0~rc1

View File

@ -423,7 +423,7 @@ sharkd_loop(int argc _U_, char* argv[])
handles[i_handles++] = si.hStdError;
}
exename = ws_strdup_printf("%s\\%s", get_progfile_dir(), "sharkd.exe");
exename = get_executable_path("sharkd");
// we need to pass in all of the command line parameters except the -a parameter
// passing in -a at this point would could a loop, each iteration of which would generate a new session process

View File

@ -371,7 +371,7 @@ bool is_packet_configuration_namespace(void)
*/
#define xx_free free /* hack so checkAPIs doesn't complain */
static const char *
get_executable_path(void)
get_current_executable_path(void)
{
#if defined(__APPLE__)
static char *executable_path;
@ -531,6 +531,32 @@ static void trim_progfile_dir(void)
g_free(extcap_progfile_dir);
}
/*
* Construct the path name of a non-extcap Wireshark executable file,
* given the program name. The executable name doesn't include ".exe";
* append it on Windows, so that callers don't have to worry about that.
*
* This presumes that all non-extcap executables are in the same directory.
*
* The returned file name was g_malloc()'d so it must be g_free()d when the
* caller is done with it.
*/
char *
get_executable_path(const char *program_name)
{
/*
* Fail if we don't know what directory contains the executables.
*/
if (progfile_dir == NULL)
return NULL;
#ifdef _WIN32
return ws_strdup_printf("%s\\%s.exe", progfile_dir, program_name);
#else
return ws_strdup_printf("%s/%s", progfile_dir, program_name);
#endif
}
/*
* Get the pathname of the directory from which the executable came,
* and save it for future use. Returns NULL on success, and a
@ -635,7 +661,7 @@ configuration_init(
running_in_build_directory_flag = TRUE;
}
execname = get_executable_path();
execname = get_current_executable_path();
if (execname == NULL) {
/*
* OK, guess based on argv[0].

View File

@ -61,6 +61,18 @@ WS_DLL_PUBLIC bool is_packet_configuration_namespace(void);
*/
WS_DLL_PUBLIC const char *get_progfile_dir(void);
/*
* Construct the path name of a non-extcap Wireshark executable file,
* given the program name. The executable name doesn't include ".exe";
* append it on Windows, so that callers don't have to worry about that.
*
* This presumes that all non-extcap executables are in the same directory.
*
* The returned file name was g_malloc()'d so it must be g_free()d when the
* caller is done with it.
*/
WS_DLL_PUBLIC char *get_executable_path(const char *filename);
/*
* Get the directory in which plugins are stored; this must not be called
* before configuration_init() is called, as they might be stored in a