From 3e4a8149efbf7d6515ec6ac542ee8882320763d0 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Mon, 26 Jul 2021 14:06:58 -0700 Subject: 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 --- src/image.lisp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/image.lisp') diff --git a/src/image.lisp b/src/image.lisp index fc29179..cbd63c5 100644 --- a/src/image.lisp +++ b/src/image.lisp @@ -99,7 +99,7 @@ Thus, PREREQUEST must not start up any threads." ,@forms))) (defun dump-consfigurator (filename form) - (umask #o077) + (nix:umask #o077) (uiop:register-image-restore-hook (lambda () (eval form)) nil) (uiop:dump-image filename :executable t)) @@ -150,7 +150,7 @@ already running from FILENAME." (eql :linux (uiop:operating-system)) (pathname-equal file (resolve-symlinks "/proc/self/exe"))) (unless filename - (mrun "chmod" "0700" (pathname-directory-pathname file))) + (nix:chmod #o700 (unix-namestring (pathname-directory-pathname file)))) (if form (dump-consfigurator-in-grandchild file form) (dump-consfigurator-in-grandchild file)))) @@ -183,7 +183,7 @@ already running from FILENAME." #'force-output *standard-output* *error-output* *debug-io* *terminal-io*) when (zerop (fork)) - do (setsid) + do (nix:setsid) (close ,fork-control) (handle-fork-request input output) (uiop:quit)) @@ -197,8 +197,9 @@ already running from FILENAME." (delete-file ,fork-control) (unwind-protect (progn ,@forms) (close *fork-control*) - (let ((status (nth-value 1 (waitpid child 0)))) - (unless (and (wifexited status) (zerop (wexitstatus status))) + (let ((status (nth-value 1 (nix:waitpid child)))) + (unless + (and (nix:WIFEXITED status) (zerop (nix:WEXITSTATUS status))) (error "Fork control child did not exit zero.")))))))) ;; IPC security considerations @@ -258,8 +259,8 @@ already running from FILENAME." (unwind-protect (with-open-file (out out :element-type 'character) (with-open-file (err err :element-type 'character) - (let ((status (nth-value 1 (waitpid child 0)))) - (unless (wifexited status) + (let ((status (nth-value 1 (nix:waitpid child)))) + (unless (nix:WIFEXITED status) (failed-change "~&Grandchild process did not exit normally, status #x~(~4,'0X~)." status)) @@ -268,7 +269,7 @@ already running from FILENAME." :element-type 'character) (write-to-mkfifo (list (slurp-stream-string out) (slurp-stream-string err) - (wexitstatus status)) + (nix:WEXITSTATUS status)) output))))) (delete-file out) (delete-file err)))) -- cgit v1.2.3