This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [libbacktrace] Use getexecname() on Solaris


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.

Ok for mainline?

	Rainer


2012-10-05  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
	    Gerald Pfeifer  <gerald@pfeifer.com>

	libbacktrace:
	* configure.ac: Check for getexecname.
	* configure: Regenerate.
	* config.h.in: Regenerate.
	* internal.h (DEFAULT_PROCESS_FILENAME): Define.
	* fileline.c (fileline_initialize): Use it.
	* print.c (error_callback): Likewise.
	Include <stdlib.h>.

# 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));
-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]