#ifdef HAVE_PLUGINS
/* Register wiretap plugins */
- if ((init_progfile_dir_error = init_progfile_dir(argv[0]))) {
+ if ((init_progfile_dir_error = init_progfile_dir(argv[0],
+ (const void *)main))) {
g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
have_plugins=no
fi
+#
+# Check whether we can use dladdr to find the pathname of an executable.
+#
+AC_MSG_CHECKING(whether dladdr can be used to find the pathname of an executable)
+ac_save_CFLAGS="$CFLAGS"
+ac_save_LIBS="$LIBS"
+CFLAGS="$CFLAGS $GLIB_CFLAGS"
+LIBS="$GLIB_LIBS $LIBS"
+AC_TRY_RUN([
+#include <stdio.h>
+#include <dlfcn.h>
+
+int
+main(void)
+{
+ Dl_info info;
+
+ if (!dladdr((const void *)main, &info))
+ return 1; /* failure */
+ if (info.dli_fname[0] != '/')
+ return 1; /* not an absolute path - failure */
+ return 0; /* assume success */
+}
+], ac_cv_dladdr_finds_executable_path=yes, ac_cv_dladdr_finds_executable_path=no,
+ [echo $ac_n "cross compiling; assumed OK... $ac_c"
+ ac_cv_dladdr_finds_executable_path=yes])
+CFLAGS="$ac_save_CFLAGS"
+LIBS="$ac_save_LIBS"
+if test x$ac_cv_dladdr_finds_executable_path = xyes
+then
+ AC_DEFINE(DLADDR_FINDS_EXECUTABLE_PATH, 1, [Define if dladdr can be used to find the path of the executable])
+fi
+AC_MSG_RESULT($ac_cv_dladdr_finds_executable_path)
+
+
dnl IGE Mac integration check
AC_MSG_CHECKING(whether to use IGE Mac integration functions)
/*
* Attempt to get the pathname of the executable file.
*/
- init_progfile_dir_error = init_progfile_dir(argv[0]);
+ init_progfile_dir_error = init_progfile_dir(argv[0],
+ (const void *)main);
if (init_progfile_dir_error != NULL) {
fprintf(stderr, "dftest: Can't get pathname of dftest program: %s.\n",
init_progfile_dir_error);
#ifdef HAVE_PLUGINS
/* Register wiretap plugins */
- if ((init_progfile_dir_error = init_progfile_dir(argv[0]))) {
+ if ((init_progfile_dir_error = init_progfile_dir(argv[0],
+ (const void *)main))) {
g_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
g_free(init_progfile_dir_error);
} else {
#include <tchar.h>
#include <shlobj.h>
#include <wsutil/unicode-utils.h>
-#else
+#else /* _WIN32 */
+#ifdef DLADDR_FINDS_EXECUTABLE_PATH
+#include <dlfcn.h>
+#endif /* DLADDR_FINDS_EXECUTABLE_PATH */
#include <pwd.h>
-#endif
+#endif /* _WIN32 */
#include "filesystem.h"
#include "report_err.h"
#ifdef _WIN32
_U_
#endif
+, const void *main_addr
+#if defined(_WIN32) || !defined(DLADDR_FINDS_EXECUTABLE_PATH)
+ _U_
+#endif
)
{
char *dir_end;
msg, error);
}
#else
+#ifdef DLADDR_FINDS_EXECUTABLE_PATH
+ Dl_info info;
+#endif
char *prog_pathname;
char *curdir;
long path_max;
&& !started_with_special_privs())
running_in_build_directory_flag = TRUE;
+#ifdef DLADDR_FINDS_EXECUTABLE_PATH
+ /*
+ * Try to use dladdr() to find the pathname of the executable.
+ */
+ if (dladdr(main_addr, &info) && info.dli_fname[0] == '/') {
+ /*
+ * dladdr() succeeded, and we got an absolute path
+ * for the module containing main() (I don't know
+ * whether it's guaranteed to return an absolute path
+ * on all platforms), so we'll use that as the
+ * executable image's path.
+ */
+ prog_pathname = g_strdup(info.dli_fname);
+ } else
+#endif
+ {
/*
* Try to figure out the directory in which the currently running
* program resides, given the argv[0] it was started with. That
return g_strdup("PATH isn't set");
}
}
+ }
/*
* OK, we have what we think is the pathname
* and save it for future use. Returns NULL on success, and a
* g_mallocated string containing an error on failure.
*/
-extern char *init_progfile_dir(const char *arg0);
+extern char *init_progfile_dir(const char *arg0, const void *main_addr);
/*
* Get the directory in which the program resides.
/*
* Attempt to get the pathname of the executable file.
*/
- init_progfile_dir_error = init_progfile_dir(argv[0]);
+ init_progfile_dir_error = init_progfile_dir(argv[0],
+ (const void *)main);
/* initialize the funnel mini-api */
initialize_funnel_ops();
* - Opens a specified file or named pipe
* - Applies a specfied DLT or "decode as" encapsulation
* - Reads frames prepended with a libpcap packet header.
- * - Prints a status line, followed by fields from a specified list.
+ * - Prints a status line, followed by fields from a specified list.
*/
#ifdef HAVE_CONFIG_H
/*
* Attempt to get the pathname of the executable file.
*/
- init_progfile_dir_error = init_progfile_dir(argv[0]);
+ init_progfile_dir_error = init_progfile_dir(argv[0],
+ (const void *)main);
if (init_progfile_dir_error != NULL) {
fprintf(stderr, "rawshark: Can't get pathname of rawshark program: %s.\n",
init_progfile_dir_error);
/*
* Attempt to get the pathname of the executable file.
*/
- init_progfile_dir_error = init_progfile_dir(argv[0]);
+ init_progfile_dir_error = init_progfile_dir(argv[0],
+ (const void *)main);
if (init_progfile_dir_error != NULL) {
fprintf(stderr, "tshark: Can't get pathname of tshark program: %s.\n",
init_progfile_dir_error);