diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-04-13 17:11:15 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2015-04-15 20:26:13 +0000 |
commit | 40ce324f4d0beda62a957f5f6c47dcc9ac5c5c18 (patch) | |
tree | c20e9a349a21b8e77e7d95420b0954550e17a51c /extcap.c | |
parent | 05c0152370cbe084193ad2946e6fc96a1017c08e (diff) |
Set the extcap working directory on Windows.
On Windows, prepend the main program directory to %Path% when spawning
extcap processes. This lets us place androiddump in extcap while allowing
it to locate its DLLs.
Change-Id: I406c47ce71323266d5f14fb596931398464e452d
Reviewed-on: https://code.wireshark.org/review/8057
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'extcap.c')
-rw-r--r-- | extcap.c | 24 |
1 files changed, 23 insertions, 1 deletions
@@ -139,11 +139,28 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb, const gchar *file; gboolean keep_going; gchar **argv; +#ifdef WIN32 + gchar **dll_search_envp; + gchar *progfile_dir; +#endif keep_going = TRUE; argv = (gchar **) g_malloc0(sizeof(gchar *) * (argc + 2)); +#ifdef WIN32 + /* + * Make sure executables can find dependent DLLs and that they're *our* + * DLLs: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586.aspx + * Alternatively we could create a simple wrapper exe similar to Create + * Hidden Process (http://www.commandline.co.uk/chp/). + */ + dll_search_envp = g_get_environ(); + progfile_dir = g_strdup_printf("%s;%s", get_progfile_dir(), g_environ_getenv(dll_search_envp, "Path")); + dll_search_envp = g_environ_setenv(dll_search_envp, "Path", progfile_dir, TRUE); + g_free(progfile_dir); +#endif + if ((dir = g_dir_open(dirname, 0, NULL)) != NULL) { #ifdef WIN32 dirname = g_strescape(dirname,NULL); @@ -156,12 +173,14 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb, gint i; gint exit_status = 0; GError *error = NULL; + gchar **envp = NULL; /* full path to extcap binary */ extcap_string = g_string_new(""); #ifdef WIN32 g_string_printf(extcap_string, "%s\\\\%s",dirname,file); extcap = g_string_free(extcap_string, FALSE); + envp = dll_search_envp; #else g_string_printf(extcap_string, "%s/%s", dirname, file); extcap = g_string_free(extcap_string, FALSE); @@ -174,7 +193,7 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb, argv[i+1] = args[i]; argv[argc+1] = NULL; - status = g_spawn_sync(dirname, argv, NULL, + status = g_spawn_sync(dirname, argv, envp, (GSpawnFlags) 0, NULL, NULL, &command_output, NULL, &exit_status, &error); @@ -188,6 +207,9 @@ static void extcap_foreach(gint argc, gchar **args, extcap_cb_t cb, g_dir_close(dir); } +#ifdef WIN32 + g_strfreev(dll_search_envp); +#endif g_free(argv); } |