Attempt to use dladdr() to get the pathname of the executable image if
it's available and works. svn path=/trunk/; revision=27812
This commit is contained in:
parent
724cae360e
commit
7c6e2155cc
|
@ -302,7 +302,8 @@ main(int argc, char *argv[])
|
||||||
#ifdef HAVE_PLUGINS
|
#ifdef HAVE_PLUGINS
|
||||||
/* Register wiretap 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_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
|
||||||
g_free(init_progfile_dir_error);
|
g_free(init_progfile_dir_error);
|
||||||
} else {
|
} else {
|
||||||
|
|
35
configure.in
35
configure.in
|
@ -676,6 +676,41 @@ else
|
||||||
have_plugins=no
|
have_plugins=no
|
||||||
fi
|
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
|
dnl IGE Mac integration check
|
||||||
AC_MSG_CHECKING(whether to use IGE Mac integration functions)
|
AC_MSG_CHECKING(whether to use IGE Mac integration functions)
|
||||||
|
|
||||||
|
|
3
dftest.c
3
dftest.c
|
@ -75,7 +75,8 @@ main(int argc, char **argv)
|
||||||
/*
|
/*
|
||||||
* Attempt to get the pathname of the executable file.
|
* 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) {
|
if (init_progfile_dir_error != NULL) {
|
||||||
fprintf(stderr, "dftest: Can't get pathname of dftest program: %s.\n",
|
fprintf(stderr, "dftest: Can't get pathname of dftest program: %s.\n",
|
||||||
init_progfile_dir_error);
|
init_progfile_dir_error);
|
||||||
|
|
|
@ -424,7 +424,8 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
#ifdef HAVE_PLUGINS
|
#ifdef HAVE_PLUGINS
|
||||||
/* Register wiretap 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_warning("capinfos: init_progfile_dir(): %s", init_progfile_dir_error);
|
||||||
g_free(init_progfile_dir_error);
|
g_free(init_progfile_dir_error);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -55,9 +55,12 @@
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#include <wsutil/unicode-utils.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>
|
#include <pwd.h>
|
||||||
#endif
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
#include "report_err.h"
|
#include "report_err.h"
|
||||||
|
@ -246,6 +249,10 @@ init_progfile_dir(const char *arg0
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
_U_
|
_U_
|
||||||
#endif
|
#endif
|
||||||
|
, const void *main_addr
|
||||||
|
#if defined(_WIN32) || !defined(DLADDR_FINDS_EXECUTABLE_PATH)
|
||||||
|
_U_
|
||||||
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char *dir_end;
|
char *dir_end;
|
||||||
|
@ -334,6 +341,9 @@ init_progfile_dir(const char *arg0
|
||||||
msg, error);
|
msg, error);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
#ifdef DLADDR_FINDS_EXECUTABLE_PATH
|
||||||
|
Dl_info info;
|
||||||
|
#endif
|
||||||
char *prog_pathname;
|
char *prog_pathname;
|
||||||
char *curdir;
|
char *curdir;
|
||||||
long path_max;
|
long path_max;
|
||||||
|
@ -355,6 +365,22 @@ init_progfile_dir(const char *arg0
|
||||||
&& !started_with_special_privs())
|
&& !started_with_special_privs())
|
||||||
running_in_build_directory_flag = TRUE;
|
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
|
* Try to figure out the directory in which the currently running
|
||||||
* program resides, given the argv[0] it was started with. That
|
* program resides, given the argv[0] it was started with. That
|
||||||
|
@ -456,6 +482,7 @@ init_progfile_dir(const char *arg0
|
||||||
return g_strdup("PATH isn't set");
|
return g_strdup("PATH isn't set");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* OK, we have what we think is the pathname
|
* OK, we have what we think is the pathname
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
* and save it for future use. Returns NULL on success, and a
|
* and save it for future use. Returns NULL on success, and a
|
||||||
* g_mallocated string containing an error on failure.
|
* 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.
|
* Get the directory in which the program resides.
|
||||||
|
|
|
@ -1808,7 +1808,8 @@ main(int argc, char *argv[])
|
||||||
/*
|
/*
|
||||||
* Attempt to get the pathname of the executable file.
|
* 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 the funnel mini-api */
|
||||||
initialize_funnel_ops();
|
initialize_funnel_ops();
|
||||||
|
|
|
@ -460,7 +460,8 @@ main(int argc, char *argv[])
|
||||||
/*
|
/*
|
||||||
* Attempt to get the pathname of the executable file.
|
* 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) {
|
if (init_progfile_dir_error != NULL) {
|
||||||
fprintf(stderr, "rawshark: Can't get pathname of rawshark program: %s.\n",
|
fprintf(stderr, "rawshark: Can't get pathname of rawshark program: %s.\n",
|
||||||
init_progfile_dir_error);
|
init_progfile_dir_error);
|
||||||
|
|
3
tshark.c
3
tshark.c
|
@ -773,7 +773,8 @@ main(int argc, char *argv[])
|
||||||
/*
|
/*
|
||||||
* Attempt to get the pathname of the executable file.
|
* 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) {
|
if (init_progfile_dir_error != NULL) {
|
||||||
fprintf(stderr, "tshark: Can't get pathname of tshark program: %s.\n",
|
fprintf(stderr, "tshark: Can't get pathname of tshark program: %s.\n",
|
||||||
init_progfile_dir_error);
|
init_progfile_dir_error);
|
||||||
|
|
Loading…
Reference in New Issue