chiark / gitweb /
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 8195411ab293a8e0c79e71590d2a076ec157a555..8aff2b958ac9e97c2a7f25f9942a5d07397ebdcf 100644 (file)
@@ -535,6 +535,12 @@ (eval-after-load "compile"
   '(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 @@ (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
 (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 @@ (defadvice term-exec (before program-args-list compile activate)
          (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: ")