Set the extcap working directory on Windows.
authorGerald Combs <gerald@wireshark.org>
Tue, 14 Apr 2015 00:11:15 +0000 (17:11 -0700)
committerGerald Combs <gerald@wireshark.org>
Wed, 15 Apr 2015 20:26:13 +0000 (20:26 +0000)
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>
CMakeLists.txt
Makefile.nmake
extcap.c
packaging/nsis/uninstall.nsi
packaging/nsis/wireshark.nsi
packaging/portableapps/Makefile.nmake
ui/qt/Wireshark.pro

index 7ac850c1369d47df062ee546258e7536283b8ce6..cd3a360079a3bc8d43e90b1664d964963038fcd3 100644 (file)
@@ -1765,6 +1765,25 @@ macro(set_extra_executable_properties _executable _folder)
        endif()
 endmacro()
 
+macro(set_extcap_executable_properties _executable)
+       set_target_properties(androiddump PROPERTIES FOLDER "Executables/Extcaps")
+
+       set(PROGLIST ${PROGLIST} ${_executable})
+
+       if(WIN32)
+               set_target_properties(${_executable} PROPERTIES
+                       LINK_FLAGS "${WS_LINK_FLAGS} /SUBSYSTEM:WINDOWS"
+                       RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
+                       RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/run/Debug/extcap
+                       RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/run/Release/extcap
+                       RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_BINARY_DIR}/run/MinSizeRel/extcap
+                       RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_BINARY_DIR}/run/RelWithDebInfo/extcap
+               )
+       else()
+               set_target_properties(${_executable} PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
+       endif()
+endmacro()
+
 if(BUILD_wireshark_gtk AND GTK_FOUND)
        set(wireshark_gtk_LIBS
                gtkui
@@ -2172,19 +2191,11 @@ if(BUILD_androiddump)
                extcap/androiddump.c
        )
 
-       set(COPY_CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
-       set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap)
        add_executable(androiddump ${androiddump_FILES})
        add_dependencies(androiddump gitversion)
-       if(WIN32)
-               set_target_properties(androiddump PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS} /SUBSYSTEM:WINDOWS")
-       else()
-               set_target_properties(androiddump PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
-       endif()
-       set_target_properties(androiddump PROPERTIES FOLDER "Executables/Extcaps")
+       set_extcap_executable_properties(androiddump)
        target_link_libraries(androiddump ${androiddump_LIBS})
        install(TARGETS androiddump RUNTIME DESTINATION ${EXTCAP_DIR})
-    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${COPY_CMAKE_RUNTIME_OUTPUT_DIRECTORY})
 endif()
 
 ADD_CUSTOM_COMMAND(
index 92581610f7713d3c4c2142d17dba2887768f591c..61783949d7c98be1447872f625a26cda3d033611 100644 (file)
@@ -1227,17 +1227,9 @@ install-generated-files: doc
        if not exist $(INSTALL_DIR)\extcap mkdir $(INSTALL_DIR)\extcap
        if exist androiddump.exe xcopy androiddump.exe $(INSTALL_DIR)\extcap /d
        if exist androiddump.pdb xcopy androiddump.pdb $(INSTALL_DIR)\extcap /d
-       xcopy ".\wiretap\wiretap-$(WTAP_VERSION).dll" $(INSTALL_DIR)\extcap /d
-       xcopy ".\wsutil\libwsutil.dll" $(INSTALL_DIR)\extcap /d
-       xcopy $(GTK_DIR)\bin\libglib-2.0-0.dll $(INSTALL_DIR)\extcap /d
-       xcopy $(GTK_DIR)\bin\libgmodule-2.0-0.dll $(INSTALL_DIR)\extcap /d
-       xcopy $(ZLIB_DIR)\zlib1.dll $(INSTALL_DIR)\extcap /d
-       xcopy $(GTK_DIR)\bin\$(INTL_DLL) $(INSTALL_DIR)\extcap /d
-!IFDEF GNUTLS_DIR
-       xcopy $(GNUTLS_DIR)\bin\$(GCC_DLL) $(INSTALL_DIR)\extcap /d
-       xcopy $(GNUTLS_DIR)\bin\libgcrypt-20.dll $(INSTALL_DIR)\extcap /d
-       xcopy $(GNUTLS_DIR)\bin\$(GPGERROR_DLL) $(INSTALL_DIR)\extcap /d
-!ENDIF
+       if not exist $(INSTALL_DIR_QT)\extcap mkdir $(INSTALL_DIR_QT)\extcap
+       if exist androiddump.exe xcopy androiddump.exe $(INSTALL_DIR_QT)\extcap /d
+       if exist androiddump.pdb xcopy androiddump.pdb $(INSTALL_DIR_QT)\extcap /d
        if exist capinfos.exe xcopy capinfos.exe $(INSTALL_DIR) /d
        if exist capinfos.pdb xcopy capinfos.pdb $(INSTALL_DIR) /d
        if exist captype.exe xcopy captype.exe $(INSTALL_DIR) /d
index 6d9a5e5aedd75b06146a95aa3d5b799fc46f03c7..6353e2153bc20e27eb89e879ca803bb49f3ca352 100644 (file)
--- a/extcap.c
+++ b/extcap.c
@@ -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);
 }
 
index 1af6aaa495c293b784ccd36a8ff66a469fe70bc9..739c7571d8a47ff6d8dedec336e4aed547cbf425 100755 (executable)
@@ -147,7 +147,6 @@ Delete "$INSTDIR\etc\gtk-2.0\*.*"
 Delete "$INSTDIR\etc\gtk-3.0\*.*"
 Delete "$INSTDIR\etc\pango\*.*"
 Delete "$INSTDIR\extcap\androiddump.*"
-Delete "$INSTDIR\extcap\*.dll"
 Delete "$INSTDIR\help\*.*"
 Delete "$INSTDIR\iconengines\*.*"
 Delete "$INSTDIR\imageformats\*.*"
index 4af80f7b58fda34164c38fd81e2c4ff3912d3aeb..09e20b5ff8b1d3532d2ae2c17747ed0848ff190d 100644 (file)
@@ -987,10 +987,10 @@ SectionEnd
 
 Section /o "Androiddump" SecAndroiddumpinfos
 ;-------------------------------------------
-SetOutPath $INSTDIR\extcap
+SetOutPath $INSTDIR
 File "${STAGING_DIR}\androiddump.html"
+SetOutPath $INSTDIR\extcap
 File "${STAGING_DIR}\extcap\androiddump.exe"
-File "${STAGING_DIR}\extcap\*.dll"
 SectionEnd
 
 SectionGroupEnd ; "Tools"
index 6a25f928d097aea9954eb68f1e58bc8283235f5a..5ffaeb954ee51311d51e95d3a9fa16ee9d0217b9 100644 (file)
@@ -62,7 +62,6 @@ dirs:
 #!IFDEF UPX
 #      -$(UPX) $(UPX_FLAGS) $(FILES)\$(APP)\$(WIRESHARK)\[a-z]*.exe
 #      -$(UPX) $(UPX_FLAGS) $(FILES)\$(APP)\$(WIRESHARK)\*.dll
-#      -$(UPX) $(UPX_FLAGS) $(FILES)\$(APP)\$(WIRESHARK)\extcap\*.dll
 #      -$(UPX) $(UPX_FLAGS) $(FILES)\$(APP)\$(WIRESHARK)\plugins\$(VERSION)\*.dll
 #      -$(UPX) $(UPX_FLAGS) $(FILES)\$(APP)\$(WIRESHARK)\lib\gtk-2.0\$(GTK_LIB_DIR)\loaders\*.dll
 #      -$(UPX) $(UPX_FLAGS) $(FILES)\$(APP)\$(WIRESHARK)\lib\gtk-2.0\$(GTK_LIB_DIR)\immodules\*.dll
index 5972a9a11e5cab4920c16addf40859390b72d068..5ac94cdf1c1f33b6b4773def9c5fe499b9cb7333 100644 (file)
@@ -493,19 +493,6 @@ win32 {
     QMAKE_POST_LINK +=$$quote($(CHK_DIR_EXISTS) $${PLUGINS_DIR} $(MKDIR) $${PLUGINS_DIR}$$escape_expand(\\n\\t))
     QMAKE_POST_LINK +=$$quote($(COPY_FILE) ..\\..\\$${INSTALL_DIR}\\plugins\\*.dll $(DESTDIR)plugins$$escape_expand(\\n\\t))
 
-    EXTCAP_DIR = $(DESTDIR)extcap
-    QMAKE_POST_LINK +=$$quote($(CHK_DIR_EXISTS) $${EXTCAP_DIR} $(MKDIR) $${EXTCAP_DIR}$$escape_expand(\\n\\t))
-    EXTRA_EXTCAP_BINFILES = \
-        ../../androiddump.exe ../../wiretap/wiretap-$${WTAP_VERSION}.dll ../../wsutil/libwsutil.dll \
-        $${GLIB_DIR}/bin/libglib-2.0-0.dll $${GLIB_DIR}/bin/libgmodule-2.0-0.dll \
-        $${GLIB_DIR}/bin/$${INTL_DLL} $${ZLIB_DIR}/zlib1.dll \
-        $${GNUTLS_DIR}/bin/$${GCC_DLL} $${GNUTLS_DIR}/bin/libgcrypt-20.dll \
-        $${GNUTLS_DIR}/bin/$${GPGERROR_DLL}
-    EXTRA_EXTCAP_BINFILES ~= s,/,\\,g
-    for(FILE,EXTRA_EXTCAP_BINFILES){
-        QMAKE_POST_LINK +=$$quote($(COPY_FILE) $${FILE} $(DESTDIR)extcap$$escape_expand(\\n\\t))
-    }
-
     # This doesn't depend on wireshark-gtk2. It also doesn't work.
     #PLUGINS_IN_PWD=$${IN_PWD}
     #PLUGINS_OUT_PWD=$${OUT_PWD}