el/dot-emacs.el: Don't leak `LD_PRELOAD' into some subprocesses.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 6 Aug 2017 02:23:20 +0000 (03:23 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 6 Aug 2017 02:23:20 +0000 (03:23 +0100)
Currently, compile, term, shell, eshell, but there may be more.
Basically, places where Emacs runs user commands rather than its own
made-up stuff.

el/dot-emacs.el

index 8195411..8aff2b9 100644 (file)
@@ -535,6 +535,12 @@ Pretend they don't exist.  They might be on other display devices."
   '(progn
      (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
 
+(defadvice compile (around hack-environment compile activate)
+  "Hack the environment inherited by inferiors in the compilation."
+  (let ((process-environment process-environment))
+    (setenv "LD_PRELOAD" nil)
+    ad-do-it))
+
 (defun mdw-compile (command &optional directory comint)
   "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
 The DIRECTORY may be nil to not change.  If COMINT is t, then
@@ -3507,6 +3513,11 @@ that character only to be normal punctuation.")
 (mdw-define-face eshell-ls-readonly (t nil))
 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
 
+(defun mdw-eshell-hack ()
+  (when mdw-preload-hacks
+    (setenv "LD_PRELOAD" nil)))
+(add-hook 'eshell-mode-hook 'mdw-eshell-hack)
+
 ;;;--------------------------------------------------------------------------
 ;;; Messages-file mode.
 
@@ -3861,6 +3872,18 @@ This allows you to pass a list of arguments through `ansi-term'."
          (ad-set-arg 2 (car program))
          (ad-set-arg 4 (cdr program))))))
 
+(defadvice term-exec-1 (around hack-environment compile activate)
+  "Hack the environment inherited by inferiors in the terminal."
+  (let ((process-environment process-environment))
+    (setenv "LD_PRELOAD" nil)
+    ad-do-it))
+
+(defadvice shell (around hack-environment compile activate)
+  "Hack the environment inherited by inferiors in the shell."
+  (let ((process-environment process-environment))
+    (setenv "LD_PRELOAD" nil)
+    ad-do-it))
+
 (defun ssh (host)
   "Open a terminal containing an ssh session to the HOST."
   (interactive "sHost: ")