[fedora-java] patch to resurrect LD_PRELOAD hack

Tom Tromey tromey at redhat.com
Tue Jan 24 02:07:48 UTC 2006


This patch to libgcj would let us resurrect the LD_PRELOAD hack.  The
idea is to remove the "pr13212.so" entry from LD_PRELOAD during libgcj
startup, to avoid passing this to sub-processes which may not be
prepared for it.

This is quite ugly and, I think, won't be going into upstream libgcj.

Please comment.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey at redhat.com>

	* prims.cc (scrub_ld_preload): New function.
	(_Jv_RunMain): Call it.

Index: prims.cc
===================================================================
--- prims.cc	(revision 109835)
+++ prims.cc	(working copy)
@@ -1339,10 +1339,51 @@
   return 0;
 }
 
+// If the PR 13212 workaround is mentioned in LD_PRELOAD, remove it.
+// If we don't remove it, it will be inherited by processes we exec(),
+// and this causes problems on some platforms.  Note that this is
+// purely a hack and will go away once we have a new enough version of
+// the GC.
+static void
+scrub_ld_preload ()
+{
+  char *val = getenv ("LD_PRELOAD");
+  if (! val)
+    return;
+
+  char preload[strlen (val) + 1];
+  strcpy (preload, val);
+
+  char result[strlen (preload) + 2];
+  result[0] = '\0';
+
+  char *state = NULL;
+  for (char *word = strtok_r (preload, " ", &state);
+       word;
+       word = strtok_r (NULL, " ", &state))
+    {
+      int len = strlen (word);
+      if (len >= 11 && ! strcmp (word + len - 11, "/pr13212.so"))
+	{
+	  // Don't include this one.
+	}
+      else
+	{
+	  strcat (result, word);
+	  strcat (result, " ");
+	}
+    }
+
+  setenv ("LD_PRELOAD", result, 1);
+}
+
 void
 _Jv_RunMain (JvVMInitArgs *vm_args, jclass klass, const char *name, int argc,
              const char **argv, bool is_jar)
 {
+  // Make sure LD_PRELOAD is clean before we might exec a process.
+  scrub_ld_preload ();
+
 #ifndef DISABLE_MAIN_ARGS
   _Jv_SetArgs (argc, argv);
 #endif




More information about the java-devel mailing list