do not set environment variables in bash processes
authorAndreas Beckmann <anbe@debian.org>
Thu, 5 Jan 2023 01:52:44 +0000 (01:52 +0000)
committerAndreas Beckmann <anbe@debian.org>
Thu, 5 Jan 2023 01:52:44 +0000 (01:52 +0000)
Gbp-Pq: Name workaround-bash-setenv.patch

libglfork.cpp

index 213779aabff5b22e8e749a053a678683eb9dcdaa..7827c41e5224fab5ee64f9de23fca4d6db8cb25a 100644 (file)
@@ -165,9 +165,17 @@ struct ContextsInfo: public std::map<GLXContext, ContextInfo> {
 struct EarlyInitializer {
   EarlyInitializer(const char **adpy_strp, const char **libgla_strp)
   {
+    // Setting environment variables in a bash process from an LD_PRELOAD
+    // library during initialization may be harmful. It can temporarily wipe
+    // the environment making subsequent getenv() return NULL (see #962566).
+    // Not setting this variable will allow primus to continue its
+    // initialization while possibly breaking OpenGL usage in bash processes
+    // (but not in subsequent processes started from bash scripts).
+    if (!dlsym(RTLD_DEFAULT, "bash_copyright")) {
     // Allow multiple glvnd libGL.so.1 instances to be loaded into a process
     // and OpenGL calls dispatched to them depending on context.
     setenv("__GLVND_DISALLOW_PATCHING", "1", 0);
+    }
 #ifdef BUMBLEBEE_SOCKET
     // Signal the Bumblebee daemon to bring up secondary X
     int sock = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);