aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2007-05-21 20:31:45 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2007-05-21 20:31:45 +0000
commit0f41677984f6a3a2c05c4e92da4bf7a3afde957b (patch)
treeca1efe51008ffcf0243cc83d30bca9d639a7084a
parent654d976d6cd4e811957dbb6a7e16559d3ac9e2fe (diff)
Have init_progfile_dir() also check whether
WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set and, if so and we weren't run with special privileges, set the running_in_build_directory_flag. Have it do the same if it finds ".libs" in the pathname of the program and we weren't run with special privileges, as that means it was probably run from the libtool wrapper script and presumably thus isn't an installed binary. This means that get_credential_info() has to be called before init_progfile_dir(). Clean up some indentation. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@21866 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r--dftest.c8
-rw-r--r--epan/filesystem.c82
-rw-r--r--gtk/main.c14
-rw-r--r--tshark.c10
4 files changed, 67 insertions, 47 deletions
diff --git a/dftest.c b/dftest.c
index e42ff526b1..c1631db8a4 100644
--- a/dftest.c
+++ b/dftest.c
@@ -67,14 +67,14 @@ main(int argc, char **argv)
dfilter_t *df;
/*
- * Attempt to get the pathname of the executable file.
+ * Get credential information for later use.
*/
- init_progfile_dir(argv[0]);
+ get_credential_info();
/*
- * Get credential information for later use.
+ * Attempt to get the pathname of the executable file.
*/
- get_credential_info();
+ init_progfile_dir(argv[0]);
/*
* Now attempt to get the pathname of the plugins.
diff --git a/epan/filesystem.c b/epan/filesystem.c
index e63b4dc333..f0ce082653 100644
--- a/epan/filesystem.c
+++ b/epan/filesystem.c
@@ -212,9 +212,17 @@ test_for_fifo(const char *path)
return 0;
}
+/*
+ * Directory from which the executable came.
+ */
static char *progfile_dir;
/*
+ * TRUE if we're running from the build directory.
+ */
+static gboolean running_in_build_directory_flag = FALSE;
+
+/*
* Get the pathname of the directory from which the executable came,
* and save it for future use. Returns NULL on success, and a
* g_mallocated string containing an error on failure.
@@ -321,6 +329,19 @@ init_progfile_dir(const char *arg0
char *retstr;
/*
+ * Check whether WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set in the
+ * environment; if so, set running_in_build_directory_flag if we
+ * weren't started with special privileges. (If we were started
+ * with special privileges, it's not safe to allow the user to point
+ * us to some other directory; running_in_build_directory_flag, when
+ * set, causes us to look for plugins and the like in the build
+ * directory.)
+ */
+ if (getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL
+ && !started_with_special_privs())
+ running_in_build_directory_flag = TRUE;
+
+ /*
* Try to figure out the directory in which the currently running
* program resides, given the argv[0] it was started with. That
* might be the absolute path of the program, or a path relative
@@ -452,6 +473,20 @@ init_progfile_dir(const char *arg0
* artifact of libtool.
*/
*dir_end = '\0';
+
+ /*
+ * This presumably means we're run from
+ * the libtool wrapper, which probably
+ * means we're being run from the build
+ * directory. If we weren't started
+ * with special privileges, set
+ * running_in_build_directory_flag.
+ *
+ * XXX - should we check whether what
+ * follows ".libs/" begins with "lt-"?
+ */
+ if (!started_with_special_privs())
+ running_in_build_directory_flag = TRUE;
}
}
@@ -490,9 +525,9 @@ get_progfile_dir(void)
* process resides.
*
* On UN*X, we use the DATAFILE_DIR value supplied by the configure
- * script, unless the WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment
- * variable is set, in which case we use the directory in which the
- * executable for this process resides.
+ * script, unless we think we're being run from the build directory,
+ * in which case we use the directory in which the executable for this
+ * process resides.
*
* XXX - if we ever make libwireshark a real library, used by multiple
* applications (more than just TShark and versions of Wireshark with
@@ -563,13 +598,12 @@ get_datafile_dir(void)
}
}
#else
- if (getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL
- && !started_with_special_privs() && progfile_dir != NULL) {
+ if (running_in_build_directory_flag && progfile_dir != NULL) {
/*
- * WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, and
- * we weren't started with special privileges, and
- * we were able to determine the directory in which
- * the program was found, so use that.
+ * We're (probably) being run from the build directory and
+ * weren't started with special privileges, and we were
+ * able to determine the directory in which the program
+ * was found, so use that.
*/
datafile_dir = progfile_dir;
} else {
@@ -590,14 +624,13 @@ get_datafile_dir(void)
* On Windows, we use the "plugin" subdirectory of the datafile directory.
*
* On UN*X, we use the PLUGIN_DIR value supplied by the configure
- * script, unless the WIRESHARK_RUN_FROM_BUILD_DIRECTORY environment
- * variable is set, in which case we use the "plugin" subdirectory of
- * the datafile directory.
+ * script, unless we think we're being run from the build directory,
+ * in which case we use the "plugin" subdirectory of the datafile directory.
*
* In both cases, we then use the subdirectory of that directory whose
* name is the version number.
*
- * XXX - if WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, perhaps we
+ * XXX - if we think we're being run from the build directory, perhaps we
* should have the plugin code not look in the version subdirectory
* of the plugin directory, but look in all of the subdirectories
* of the plugin directory, so it can just fetch the plugins built
@@ -605,11 +638,6 @@ get_datafile_dir(void)
*/
static const char *plugin_dir;
-/*
- * TRUE if we're running from the build directory.
- */
-static gboolean running_in_build_directory_flag = FALSE;
-
void
init_plugin_dir(void)
{
@@ -647,22 +675,14 @@ init_plugin_dir(void)
running_in_build_directory_flag = TRUE;
}
#else
- if (getenv("WIRESHARK_RUN_FROM_BUILD_DIRECTORY") != NULL
- && !started_with_special_privs()) {
+ if (running_in_build_directory_flag) {
/*
- * WIRESHARK_RUN_FROM_BUILD_DIRECTORY is set, and
- * we weren't started with special privileges, so
- * we'll use the "plugins" subdirectory of the
- * datafile directory (the datafile directory is
- * the build directory), and set the "we're running
- * in a build directory" flag, so the plugin scanner
- * will check all subdirectories of that directory
- * for plugins. (If we were started with special
- * privileges, it's not safe to allow the user to
- * point us to some other directory.)
+ * We're (probably) being run from the build directory and
+ * weren't started with special privileges, so we'll use
+ * the "plugins" subdirectory of the datafile directory
+ * (the datafile directory is the build directory).
*/
plugin_dir = g_strdup_printf("%s/plugins", get_datafile_dir());
- running_in_build_directory_flag = TRUE;
} else
plugin_dir = PLUGIN_DIR;
#endif
diff --git a/gtk/main.c b/gtk/main.c
index ff1bfdec17..3c93ec3e5c 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -2144,20 +2144,20 @@ main(int argc, char *argv[])
OPTSTRING_INIT OPTSTRING_WIN32;
#ifdef HAVE_AIRPDCAP
- /* Davide Schiera (2006-11-18): init AirPDcap context */
- AirPDcapInitContext(&airpdcap_ctx);
- /* Davide Schiera (2006-11-18) ------------------------------------------- */
+ /* Davide Schiera (2006-11-18): init AirPDcap context */
+ AirPDcapInitContext(&airpdcap_ctx);
+ /* Davide Schiera (2006-11-18) ------------------------------------------- */
#endif
/*
- * Attempt to get the pathname of the executable file.
+ * Get credential information for later use.
*/
- init_progfile_dir_error = init_progfile_dir(argv[0]);
+ get_credential_info();
/*
- * Get credential information for later use.
+ * Attempt to get the pathname of the executable file.
*/
- get_credential_info();
+ init_progfile_dir_error = init_progfile_dir(argv[0]);
/*
* Now attempt to get the pathname of the plugins.
diff --git a/tshark.c b/tshark.c
index 42ecf77042..8559216608 100644
--- a/tshark.c
+++ b/tshark.c
@@ -721,6 +721,11 @@ main(int argc, char *argv[])
static const char optstring[] = OPTSTRING_INIT OPTSTRING_WIN32;
/*
+ * Get credential information for later use.
+ */
+ get_credential_info();
+
+ /*
* Attempt to get the pathname of the executable file.
*/
init_progfile_dir_error = init_progfile_dir(argv[0]);
@@ -730,11 +735,6 @@ main(int argc, char *argv[])
}
/*
- * Get credential information for later use.
- */
- get_credential_info();
-
- /*
* Now attempt to get the pathname of the plugins.
*/
init_plugin_dir();