[libbacktrace] Use getexecname() on Solaris

Gerald Pfeifer gerald@pfeifer.com
Fri Oct 5 11:05:00 GMT 2012


On Fri, 5 Oct 2012, Rainer Orth wrote:
> This is due to the hardcoded use of /proc/self/exe in libbacktrace,
> which doesn't exist on Solaris, and probably is also missing on other
> non-Linux OSes.  Solaris (since 2.6, it seems) provides getexecname()
> instead, which this patch uses.
:
> I haven't touched the other hardcoded use in print.c since it isn't
> obvious to me how best to handle it.
>
> 2012-10-05  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>
>        * configure.ac: Check for getexecname.
>        * configure: Regenerate.
>        * config.h.in: Regenerate.
>        * fileline.c (fileline_initialize) [HAVE_GETEXECNAME]: Use
>        getexecname if available.

Oops, I also had prepared a patch for this which I was just going
to submit when seeing yours.

Your patch is better in that it checks for getexecname (which does
not exist in FreeBSD).  Mine seems better in that it removes the 
duplication between fileline.c and print.c and also addresses the
latter case.

Could you just merge mine into yours or am I missing something?

Gerald


2012-10-05  Gerald Pfeifer  <gerald@pfeifer.com>

	* internal.h (DEFAULT_PROCESS_FILENAME): Define.
	* fileline.c (fileline_initialize): Use it.
 	* print.c (error_callback): Ditto.

Index: internal.h
===================================================================
--- internal.h	(revision 192106)
+++ internal.h	(working copy)
@@ -56,6 +56,12 @@
 # endif
 #endif
 
+#ifdef __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
Index: fileline.c
===================================================================
--- fileline.c	(revision 192106)
+++ fileline.c	(working copy)
@@ -82,7 +82,8 @@
   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;
 
Index: print.c
===================================================================
--- print.c	(revision 192106)
+++ print.c	(working copy)
@@ -73,7 +73,7 @@
 
   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));



More information about the Gcc-patches mailing list