diff options
-rw-r--r-- | share/txr/stdlib/compiler.tl | 21 | ||||
-rw-r--r-- | txr.1 | 22 |
2 files changed, 39 insertions, 4 deletions
diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index e7cc10b9..953a4129 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -1711,11 +1711,29 @@ [mapdo (op prinl @1 out-stream) out-forms] (delete-package *package*))) +(defun propagate-perms (in-stream out-stream) + (let ((sti (stat in-stream))) + (when (plusp (logand sti.mode s-ixusr)) + (let ((mode "+x") + (suid (if (plusp (logand sti.mode s-isuid)) ",u+s")) + (sgid (if (and (plusp (logand sti.mode s-isgid)) + (plusp (logand sti.mode s-ixgrp))) ",g+s"))) + (when (or suid sgid) + (let ((sto (stat out-stream))) + (set mode (append mode + (if (eql sti.uid sto.uid) suid) + (if (eql sti.gid sto.gid) sgid))))) + (chmod out-stream mode))))) + (defun compile-file-conditionally (in-path out-path test-fn) (whenlet ((success nil) + (perms nil) (streams (open-compile-streams in-path out-path test-fn))) (with-resources ((in-stream (car streams) (close-stream in-stream)) (out-stream (cadr streams) (progn + (when perms + (propagate-perms in-stream + out-stream)) (close-stream out-stream) (unless success (remove-path (caddr streams)))))) @@ -1732,7 +1750,8 @@ (progn (set line `@line `) (upd line (regsub #/--lisp[^\-]/ (ret `--compiled@[@1 -1]`))) - (put-line (butlast line) out-stream)) + (put-line (butlast line) out-stream) + (set perms t)) (seek-stream in-stream 0 :from-start)) (labels ((compile-form (unex-form) (let* ((form (macroexpand unex-form)) @@ -70042,6 +70042,10 @@ circular structures are reproduced. .SS* Treatment of The Hash Bang Line +\*(TX supports the hash bang mechanism in compiled +.code .tlo +files, thereby allowing compiled scripts to be executable. + When a source file begins with the .code #! ("hash-bang") character sequence, the file compiler propagates that @@ -70051,9 +70055,21 @@ compiled file, subject to the following transformation: occurrences of which are not followed by a dash are replaced with .strn --compiled . -\*(TX supports the hash bang mechanism in compiled -.code .tlo -files, thereby allowing compiled scripts to be executable. +Furthermore, certain permissions are propagated from a hash bang source +file to the target file. If the source file is executable to its owner, +then the target file is made executable as if by using +.code chmod +with the +.code +x +mode: all the executable permissions that are allowed by the current +.code umask +are are enabled on the target file. If the target file is thus being marked +executable, then additional permissions are also treated as follows. If the +target file has the same owner as the source file, and the source file's setuid +permission bit is set, then this is propagated to the target file. Similarly, +if the target file has the same group owner as the source file, and the source +file's group execute bit and setgid permission bit are set, then the setgid +bit is set on the target file. .SS* Compiled File Compatibility |