Message ID | yddpq3pserl.fsf@manam.CeBiTec.Uni-Bielefeld.DE |
---|---|
State | New |
Headers | show |
On Wed, Nov 7, 2012 at 5:50 AM, Rainer Orth <ro@cebitec.uni-bielefeld.de> wrote: > Gerald Pfeifer <gerald@pfeifer.com> writes: > >> Just a small note, in the following >> >> +#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 >> >> would it make sense to have the feature test (HAVE_GETEXECNAME) before >> the OS test (__FreeBSD__), so that when/if the OS implements the feature >> in newer versions that takes precedence? > > Good point. I've incorporated this into my patch and regularly include > it in my *-*-solaris2.{9, 10, 11} and x86_64-unknown-linux-gnu > bootstraps. Sorry for the delay on this. I wanted to do it in a different way that I think is more flexible and avoids #ifdef __FreeBSD__. This patch tries different approaches to find the executable. It also ha a chance of working if, e.g., the executable was removed. Bootstrapped and ran libbacktrace and Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Please let me know if this doesn't fix the problems on Solaris and FreeBSD. Thanks for the earlier patches. Ian 2012-11-12 Ian Lance Taylor <iant@google.com> Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> Gerald Pfeifer <gerald@pfeifer.com> * configure.ac: Check for getexecname. * fileline.c: #include <errno.h>. Define getexecname if not available. (fileline_initialize): Try to find the executable in a few different ways. * print.c (error_callback): Only print the filename if it came from the backtrace state. * configure, config.h.in: Rebuild.
# HG changeset patch # Parent a6a174227cae12381edf325b21adc905e8fa50e6 Use getexecname() on Solaris diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -289,6 +289,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;])], diff --git a/libbacktrace/fileline.c b/libbacktrace/fileline.c --- a/libbacktrace/fileline.c +++ b/libbacktrace/fileline.c @@ -82,7 +82,8 @@ fileline_initialize (struct backtrace_st if (state->filename != NULL) descriptor = backtrace_open (state->filename, error_callback, data, NULL); else - descriptor = backtrace_open ("/proc/self/exe", error_callback, data, NULL); + descriptor = backtrace_open (DEFAULT_PROCESS_FILENAME, error_callback, + data, NULL); if (descriptor < 0) failed = 1; diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h --- a/libbacktrace/internal.h +++ b/libbacktrace/internal.h @@ -56,6 +56,14 @@ POSSIBILITY OF SUCH DAMAGE. */ # endif #endif +#ifdef HAVE_GETEXECNAME +# define DEFAULT_PROCESS_FILENAME getexecname () +#elif defined(__FreeBSD__) +# define DEFAULT_PROCESS_FILENAME "/proc/curproc/file" +#else +# define DEFAULT_PROCESS_FILENAME "/proc/self/exe" +#endif + #ifndef HAVE_SYNC_FUNCTIONS /* Define out the sync functions. These should never be called if diff --git a/libbacktrace/print.c b/libbacktrace/print.c --- a/libbacktrace/print.c +++ b/libbacktrace/print.c @@ -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));