From 559a999fe21f89d0f297cf6feb9a2b01da773400 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 10 Feb 2020 04:08:22 -0800 Subject: chmod tests: avoid sticky bit when not available. On Solaris, we can't set the sticky bit on a non-directory without special privilege. Let's detect whether we can set the sticky bit on our test object. If we can't, then we avoid executing tests that involve the sticky bit. * tests/018/chmod.tl (test-sticky): New variable. (cht): If test-sticky is false, only run the test if none of the inputs contain a 't'. --- tests/018/chmod.tl | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/018/chmod.tl b/tests/018/chmod.tl index 7963f303..ada3f0be 100644 --- a/tests/018/chmod.tl +++ b/tests/018/chmod.tl @@ -3,28 +3,35 @@ (defvarl tgt [*args* 0]) +(remove-path tgt) +(with-stream (s (open-file tgt "w"))) +(umask #o022) + +(defvarl test-sticky (progn + (chmod tgt s-isvtx) + (let ((st (stat tgt))) + (plusp (logand s-isvtx st.mode))))) + (defmacro mode-bits (st-mode) ^(logand ,st-mode #xFFF)) (defun cht (init mode expected) - (let ((ini (dec-perm init)) - (exp (dec-perm expected))) - (chmod tgt ini) - (let* ((st (stat tgt)) - (m (mode-bits st.mode))) - (unless (eql m ini) - (error "failed to set initial mode: expected: ~s, actual: ~s " - init (enc-perm m)))) - (chmod tgt mode) - (let* ((st (stat tgt)) - (m (mode-bits st.mode))) - (unless (eql m exp) - (error "failed to set mode with ~s: expected ~s, actual ~s" - mode expected (enc-perm m)))))) - -(remove-path tgt) -(with-stream (s (open-file tgt "w"))) -(umask #o022) + (when (or test-sticky + (not (find #\t `@init@mode@expected`))) + (let ((ini (dec-perm init)) + (exp (dec-perm expected))) + (chmod tgt ini) + (let* ((st (stat tgt)) + (m (mode-bits st.mode))) + (unless (eql m ini) + (error "failed to set initial mode: expected: ~s, actual: ~s " + init (enc-perm m)))) + (chmod tgt mode) + (let* ((st (stat tgt)) + (m (mode-bits st.mode))) + (unless (eql m exp) + (error "failed to set mode with ~s: expected ~s, actual ~s" + mode expected (enc-perm m))))))) (cht "------------" "a+strwx" "sgtrwxrwxrwx") (cht "------------" "+strwx" "sgtrwxr-xr-x") -- cgit v1.2.3