aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2019-04-19 01:51:03 +0100
committerPeter Wu <peter@lekensteyn.nl>2019-04-19 17:29:03 +0000
commit3f9579e3f5f84262d0f8c849a0f98220fee8d722 (patch)
treea931a947d235ed912671aac3fad71aed7e92d75f
parent727aaad3ae99132470ea0a9eba912aea8ef83ef3 (diff)
wsutil: use environment variable WIRESHARK_EXTCAP_DIR when possible
The WIRESHARK_EXTCAP_DIR environment variable is currently only used on Windows, and on UN*X when not running from the build directory. In order to avoid copying the sampleif.py test utility to the program directory, let's prioritize the environment variable over the build directory. Update the outdated comments while at it, the version directory has been removed long time ago. (The comments are based on the one for plugins.) This also fixes the test suite on macOS where the extcap subdirectory is located in the appbundle directory and not the build directory. Change-Id: I329bb233b1dd0b9c1422c2ebd60a6455347e1d62 Reviewed-on: https://code.wireshark.org/review/32890 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Dario Lombardo <lomato@gmail.com> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
-rw-r--r--test/suite_clopts.py18
-rw-r--r--wsutil/filesystem.c71
2 files changed, 39 insertions, 50 deletions
diff --git a/test/suite_clopts.py b/test/suite_clopts.py
index d33143b04e..ed8b5f54e9 100644
--- a/test/suite_clopts.py
+++ b/test/suite_clopts.py
@@ -287,22 +287,20 @@ class case_tshark_z_expert(subprocesstest.SubprocessTestCase):
@fixtures.uses_fixtures
class case_tshark_extcap(subprocesstest.SubprocessTestCase):
# dumpcap dependency has been added to run this test only with capture support
- def test_tshark_extcap_interfaces(self, cmd_tshark, cmd_dumpcap, program_path):
+ def test_tshark_extcap_interfaces(self, cmd_tshark, cmd_dumpcap, test_env, home_path):
# Script extcaps don't work with the current code on windows.
# https://www.wireshark.org/docs/wsdg_html_chunked/ChCaptureExtcap.html
# TODO: skip this test until it will get fixed.
if sys.platform == 'win32':
self.skipTest('FIXME extcap .py scripts needs special treatment on Windows')
- extcap_tool = 'sampleif.py'
- target_dir = os.path.join(program_path, 'extcap')
- target_file = os.path.join(target_dir, extcap_tool)
- source_file = os.path.join(os.path.dirname(__file__), extcap_tool)
- os.makedirs(target_dir, exist_ok=True)
- shutil.copy2(source_file, target_file)
+ extcap_dir_path = os.path.join(home_path, 'extcap')
+ os.makedirs(extcap_dir_path)
+ test_env['WIRESHARK_EXTCAP_DIR'] = extcap_dir_path
+ source_file = os.path.join(os.path.dirname(__file__), 'sampleif.py')
+ shutil.copy2(source_file, extcap_dir_path)
# Ensure the test extcap_tool is properly loaded
- self.assertRun((cmd_tshark, '-D'))
+ self.assertRun((cmd_tshark, '-D'), env=test_env)
self.assertEqual(1, self.countOutput('sampleif'))
# Ensure tshark lists 2 interfaces in the preferences
- self.assertRun((cmd_tshark, '-G', 'currentprefs'))
+ self.assertRun((cmd_tshark, '-G', 'currentprefs'), env=test_env)
self.assertEqual(2, self.countOutput('extcap.sampleif.test'))
- os.remove(target_file)
diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c
index a107d5ca26..0203ddf284 100644
--- a/wsutil/filesystem.c
+++ b/wsutil/filesystem.c
@@ -1028,46 +1028,45 @@ get_plugins_pers_dir_with_version(void)
/*
* Find the directory where the extcap hooks are stored.
*
+ * If the WIRESHARK_EXTCAP_DIR environment variable is set and we are not
+ * running with special privileges, use that. Otherwise:
+ *
* On Windows, we use the "extcap" subdirectory of the datafile directory.
*
- * On UN*X, we use the EXTCAP_DIR value supplied by the configure
- * script, unless we think we're being run from the build directory,
- * in which case we use the "extcap" subdirectory of the datafile directory.
+ * On UN*X:
+ *
+ * if we appear to be run from the build directory, we use the
+ * "extcap" subdirectory of the build directory.
*
- * In both cases, we then use the subdirectory of that directory whose
- * name is the version number.
+ * otherwise, if we're running from an app bundle in macOS, we
+ * use the Contents/MacOS/extcap subdirectory of the app bundle;
*
- * XXX - if we think we're being run from the build directory, perhaps we
- * should have the extcap code not look in the version subdirectory
- * of the extcap directory, but look in all of the subdirectories
- * of the extcap directory, so it can just fetch the extcap hooks built
- * as part of the build process.
+ * otherwise, we use the EXTCAP_DIR value supplied by CMake.
*/
static char *extcap_dir = NULL;
static void init_extcap_dir(void) {
+ if (g_getenv("WIRESHARK_EXTCAP_DIR") && !started_with_special_privs()) {
+ /*
+ * The user specified a different directory for extcap hooks
+ * and we aren't running with special privileges.
+ */
+ extcap_dir = g_strdup(g_getenv("WIRESHARK_EXTCAP_DIR"));
+ }
#ifdef _WIN32
- const char *alt_extcap_path;
-
- /*
- * On Windows, the data file directory is the installation
- * directory; the extcap hooks are stored under it.
- *
- * Assume we're running the installed version of Wireshark;
- * on Windows, the data file directory is the directory
- * in which the Wireshark binary resides.
- */
- alt_extcap_path = g_getenv("WIRESHARK_EXTCAP_DIR");
- if (alt_extcap_path) {
+ else {
/*
- * The user specified a different directory for extcap hooks.
+ * On Windows, the data file directory is the installation
+ * directory; the extcap hooks are stored under it.
+ *
+ * Assume we're running the installed version of Wireshark;
+ * on Windows, the data file directory is the directory
+ * in which the Wireshark binary resides.
*/
- extcap_dir = g_strdup(alt_extcap_path);
- } else {
extcap_dir = g_build_filename(get_datafile_dir(), "extcap", (gchar *)NULL);
}
#else
- if (running_in_build_directory_flag) {
+ else if (running_in_build_directory_flag) {
/*
* We're (probably) being run from the build directory and
* weren't started with special privileges, so we'll use
@@ -1075,15 +1074,9 @@ static void init_extcap_dir(void) {
* we're running is (that's the build directory).
*/
extcap_dir = g_build_filename(get_progfile_dir(), "extcap", (gchar *)NULL);
- } else {
- if (g_getenv("WIRESHARK_EXTCAP_DIR") && !started_with_special_privs()) {
- /*
- * The user specified a different directory for extcap hooks
- * and we aren't running with special privileges.
- */
- extcap_dir = g_strdup(g_getenv("WIRESHARK_EXTCAP_DIR"));
- }
+ }
#ifdef __APPLE__
+ else if (appbundle_dir != NULL) {
/*
* If we're running from an app bundle and weren't started
* with special privileges, use the Contents/MacOS/extcap
@@ -1093,13 +1086,11 @@ static void init_extcap_dir(void) {
* started with special privileges, so we need only check
* it; we don't need to call started_with_special_privs().)
*/
- else if (appbundle_dir != NULL) {
- extcap_dir = g_build_filename(appbundle_dir, "Contents/MacOS/extcap", (gchar *)NULL);
- }
+ extcap_dir = g_build_filename(appbundle_dir, "Contents/MacOS/extcap", (gchar *)NULL);
+ }
#endif
- else {
- extcap_dir = g_strdup(EXTCAP_DIR);
- }
+ else {
+ extcap_dir = g_strdup(EXTCAP_DIR);
}
#endif
}