diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-07-26 14:06:58 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-09-09 11:19:40 -0700 |
commit | 3e4a8149efbf7d6515ec6ac542ee8882320763d0 (patch) | |
tree | 47ea0ced2be5ce4f2a5ab246d5e10a686a98694c /src/util.lisp | |
parent | 009634f28b0443cc6a5dc37f733e281819c9947b (diff) | |
download | consfigurator-3e4a8149efbf7d6515ec6ac542ee8882320763d0.tar.gz |
use CFFI, mostly via Osicat, for all syscalls/libc except fork(2)
Also replace some calls to chmod(1) with calls to chmod(2).
Using CFFI rather than implementation-specific wrappers should be better for
portability. Also with this commit we stop hard coding types like uid_t as
:UNSIGNED-INT, which was less portable.
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/util.lisp')
-rw-r--r-- | src/util.lisp | 39 |
1 files changed, 8 insertions, 31 deletions
diff --git a/src/util.lisp b/src/util.lisp index f498352..74e2801 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -370,15 +370,7 @@ expansion as a starting point for your own DEFPACKAGE form for your consfig." (char +alphanum+ (random #.(length +alphanum+)))) finally (return result))) (mkfifo (temp) - (handler-case - (progn - #+sbcl (sb-posix:mkfifo temp #o600) - #-(or sbcl) - (unless (zerop - (foreign-funcall - "mkfifo" :string temp :unsigned-int #o600 :int)) - (error "mkfifo(3) failed!")) - t) + (handler-case (nix:mkfifo temp #o600) (serious-condition (c) (if (or (file-exists-p temp) (directory-exists-p temp)) nil @@ -507,31 +499,16 @@ previous output." ;;;; Forking utilities -;;; Use only implementation-specific fork, waitpid etc. calls to avoid thread -;;; woes. Things like chroot(2) and setuid(2), however, should be okay. +;;; Use implementation-specific fork(2) wrapper, and never fork(2) itself, to +;;; allow the implementation to handle things like finaliser threads. For all +;;; other syscalls/libc & POSIX macros like WIFEXITED, use CFFI, via Osicat +;;; when there's a wrapper available, for portability. (defun fork () ;; Normalise any other implementations such that we signal an error if ;; fork(2) returns -1, so caller doesn't have to check for that. #+sbcl (sb-posix:fork)) -(defun waitpid (pid options) - ;; Normalise any other implementations such that we always return (values - ;; PID EXIT-STATUS), as SB-POSIX:WAITPID does. - #+sbcl (sb-posix:waitpid pid options)) - -(defun wifexited (status) - #+sbcl (sb-posix:wifexited status)) - -(defun wexitstatus (status) - #+sbcl (sb-posix:wexitstatus status)) - -(defun setsid () - #+sbcl (sb-posix:setsid)) - -(defun umask (mode) - #+sbcl (sb-posix:umask mode)) - (defmacro forked-progn (child-pid child-form &body parent-forms) (with-gensyms (retval) `(progn @@ -600,9 +577,9 @@ interactive debugger.")) (defun posix-login-environment (logname home) "Reset the environment after switching UID, or similar, in a :LISP connection. Does not currently establish a PAM session." - (let ((euid (foreign-funcall "geteuid" :unsigned-int)) + (let ((rootp (zerop (nix:geteuid))) (maybe-preserve '("TERM"))) - (when (zerop euid) + (when rootp (push "SSH_AUTH_SOCK" maybe-preserve)) (let ((preserved (loop for var in maybe-preserve for val = (getenv var) @@ -615,7 +592,7 @@ Does not currently establish a PAM session." (getenv "LOGNAME") logname (getenv "SHELL") "/bin/sh" (getenv "PATH") - (if (zerop euid) + (if rootp "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" "/usr/local/bin:/bin:/usr/bin")) (uiop:chdir home))) |