~ chicken-core (chicken-5) a606eb8186538ace2e72dd8aa68db4c7f280b774
commit a606eb8186538ace2e72dd8aa68db4c7f280b774
Author: Jim Ursetto <zbigniewsz@gmail.com>
AuthorDate: Fri Apr 15 22:44:48 2016 -0500
Commit: Peter Bex <peter@more-magic.net>
CommitDate: Sat Apr 16 17:02:47 2016 +0200
On OS X, ensure DYLD_LIBRARY_PATH is passed to children (#1277)
On OS X 10.11, according to Apple's System Integrity Protection Guide, "Any
dynamic linker (dyld) environment variables, such as DYLD_LIBRARY_PATH, are
purged when launching protected processes," including /bin/sh. This causes a
failure running `make check` (bug #1277) because launching children via
system(3) wipes out the library path override used to test uninstalled
binaries. Turning off SIP will resolve the issue but disables other useful
protections.
This patch simulates the pre-SIP behavior by prepending /usr/bin/env
DYLD_LIBRARY_PATH=... to all shell calls made by csc, chicken-install and
setup-api, using the value of the variable in the caller's environment.
To get all tests in `make check` to work, it is only necessary to augment calls
from csc to chicken, from chicken-install to csi, and from setup-api to csc.
Converting these from system(3) to exec(2) works as well, but was deemed too
invasive. This patch affects more calls than necessary in the interest of
simplicity, but calls to protected binaries will have the DYLD_LIBRARY_PATH
stripped out by SIP again anyway.
Signed-off-by: Peter Bex <peter@more-magic.net>
diff --git a/chicken-install.scm b/chicken-install.scm
index 71e1c707..da7a1609 100644
--- a/chicken-install.scm
+++ b/chicken-install.scm
@@ -649,7 +649,6 @@
(let ((cmd (make-install-command
(car e+d+v) (caddr e+d+v) (> i 1)))
(name (car e+d+v)))
- (print " " cmd)
(keep-going
(name "installing")
($system cmd))
@@ -765,12 +764,18 @@
(gather-egg-information dir)))
(define ($system str)
- (let ((r (system
- (if *windows-shell*
- (string-append "\"" str "\"")
- str))))
- (unless (zero? r)
- (error "shell command terminated with nonzero exit code" r str))))
+ (let ((str (cond (*windows-shell*
+ (string-append "\"" str "\""))
+ ((and (eq? (software-version) 'macosx)
+ (get-environment-variable "DYLD_LIBRARY_PATH"))
+ => (lambda (path)
+ (string-append "/usr/bin/env DYLD_LIBRARY_PATH="
+ (qs path) " " str)))
+ (else str))))
+ (print " " str)
+ (let ((r (system str)))
+ (unless (zero? r)
+ (error "shell command terminated with nonzero exit code" r str)))))
(define (installed-extensions)
(delete-duplicates
@@ -805,7 +810,6 @@
(define (command fstr . args)
(let ((cmd (apply sprintf fstr args)))
- (print " " cmd)
($system cmd)))
(define (usage code)
diff --git a/csc.scm b/csc.scm
index bed0073c..94baf6bb 100644
--- a/csc.scm
+++ b/csc.scm
@@ -1062,10 +1062,14 @@ EOF
(define last-exit-code #f)
(define ($system str)
- (when verbose (print str))
- (let ((str (if windows-shell
- (string-append "\"" str "\"")
- str)))
+ (let ((str (cond (windows-shell
+ (string-append "\"" str "\""))
+ ((and osx (get-environment-variable "DYLD_LIBRARY_PATH"))
+ => (lambda (path)
+ (string-append "/usr/bin/env DYLD_LIBRARY_PATH="
+ (qs path) " " str)))
+ (else str))))
+ (when verbose (print str))
(let ((raw-exit-code (if dry-run 0 (system str))))
(unless (zero? raw-exit-code)
(printf "\nError: shell command terminated with non-zero exit status ~S: ~A~%" raw-exit-code str))
diff --git a/setup-api.scm b/setup-api.scm
index d4c965f7..8e1260c1 100644
--- a/setup-api.scm
+++ b/setup-api.scm
@@ -647,13 +647,18 @@
(remove-file* (make-pathname repo egg setup-file-extension)))
(define ($system str)
- (let ((r (system
- (if *windows-shell*
- (string-append "\"" str "\"") ; (sic) thanks to Matthew Flatt
- str))))
- (unless (zero? r)
- (error
- (sprintf "shell command failed with nonzero exit status ~a:~%~% ~a" r str)))))
+ (let ((str (cond (*windows-shell*
+ (string-append "\"" str "\""))
+ ((and (eq? (software-version) 'macosx)
+ (get-environment-variable "DYLD_LIBRARY_PATH"))
+ => (lambda (path)
+ (string-append "/usr/bin/env DYLD_LIBRARY_PATH="
+ (qs path) " " str)))
+ (else str))))
+ (let ((r (system str)))
+ (unless (zero? r)
+ (error
+ (sprintf "shell command failed with nonzero exit status ~a:~%~% ~a" r str))))))
(define (setup-error-handling)
(current-exception-handler
Trap