# HG changeset patch
# Parent e43e8e91417064d0dcfb3b9ec0c2833d7ce00792
Use getexecname() on Solaris
@@ -260,6 +260,19 @@ fi
AC_CHECK_DECLS(strnlen)
+# Check for getexecname function.
+if test -n "${with_target_subdir}"; then
+ case "${host}" in
+ *-*-solaris2*) have_getexecname=yes ;;
+ *) have_getexecname=no ;;
+ esac
+else
+ AC_CHECK_FUNC(getexecname, [have_getexecname=yes], [have_getexecname=no])
+fi
+if test "$have_getexecname" = "yes"; then
+ AC_DEFINE(HAVE_GETEXECNAME, 1, [Define if getexecname is available.])
+fi
+
AC_CACHE_CHECK([whether tests can run],
[libbacktrace_cv_sys_native],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
@@ -82,7 +82,8 @@ fileline_initialize (struct backtrace_st
if (state->filename != NULL)
descriptor = backtrace_open (state->filename, error_callback, data);
else
- descriptor = backtrace_open ("/proc/self/exe", error_callback, data);
+ descriptor = backtrace_open (DEFAULT_PROCESS_FILENAME, error_callback,
+ data);
if (descriptor < 0)
failed = 1;
@@ -56,6 +56,14 @@ POSSIBILITY OF SUCH DAMAGE. */
# endif
#endif
+#ifdef __FreeBSD__
+# define DEFAULT_PROCESS_FILENAME "/proc/curproc/file"
+#elif defined(HAVE_GETEXECNAME)
+# define DEFAULT_PROCESS_FILENAME getexecname ()
+#else
+# define DEFAULT_PROCESS_FILENAME "/proc/self/exe"
+#endif
+
#ifndef HAVE_SYNC_FUNCTIONS
/* Define out the sync functions. These should never be called if
@@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. */
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
+#include <stdlib.h>
#include "backtrace.h"
#include "internal.h"
@@ -73,7 +74,7 @@ error_callback (void *data, const char *
name = pdata->state->filename;
if (name == NULL)
- name = "/proc/self/exe";
+ name = DEFAULT_PROCESS_FILENAME;
fprintf (stderr, "%s: libbacktrace: %s", name, msg);
if (errnum > 0)
fprintf (stderr, ": %s", strerror (errnum));