From b1b4001db08c9a0b094523df18d287336651eeef Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 10 Jul 2021 19:02:50 -0700 Subject: factor out MOUNTPOINTP Signed-off-by: Sean Whitton --- src/connection.lisp | 7 +++++++ src/connection/chroot.lisp | 5 ++--- src/package.lisp | 1 + src/property/installer.lisp | 4 ++-- src/property/mount.lisp | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/connection.lisp b/src/connection.lisp index 3105bc6..57b48c6 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -444,6 +444,13 @@ expected." (defun test (&rest args) (zerop (apply #'mrun :for-exit "test" args))) +(defun mountpointp (path) + "Is PATH a mount point? + +Uses mountpoint(1) from util-linux, so add a property requiring OS:LINUX or a +subclass to the :HOSTATTRS subroutine of properties calling this." + (zerop (mrun :for-exit "mountpoint" "-q" path))) + (defun delete-remote-trees (&rest paths) "Recursively delete each of PATHS." (mrun "rm" "-rf" paths)) diff --git a/src/connection/chroot.lisp b/src/connection/chroot.lisp index acf8053..d0d59ac 100644 --- a/src/connection/chroot.lisp +++ b/src/connection/chroot.lisp @@ -48,7 +48,7 @@ should be the mount point, without the chroot's root prefixed.") (slot-value connection 'into)))) ;; We only mount when the target is not already a mount point, so we ;; don't shadow anything that the user has already set up. - (when (plusp (mrun :for-exit "mountpoint" "-q" dest)) + (unless (mountpointp dest) (setq mount-args (copy-list mount-args)) (setf (lastcar mount-args) dest) (apply #'mrun "mount" mount-args) @@ -67,8 +67,7 @@ should be the mount point, without the chroot's root prefixed.") (with-slots (into) connection ;; Ensure the chroot itself is a mountpoint so that findmnt(8) works ;; correctly within the chroot. - (unless (zerop (mrun :for-exit "mountpoint" "-q" into)) - (chroot-mount connection "--bind" into "/")) + (unless (mountpointp into) (chroot-mount connection "--bind" into "/")) ;; Now set up the usual bind mounts. Help here from arch-chroot(8). (mount:assert-devtmpfs-udev-/dev) (dolist (mount mount:*standard-linux-vfs*) diff --git a/src/package.lisp b/src/package.lisp index 07df631..7cc2a71 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -142,6 +142,7 @@ #:remote-file-stats #:remote-last-reboot #:remote-consfigurator-cache-pathname + #:mountpointp #:delete-remote-trees #:readfile #:writefile diff --git a/src/property/installer.lisp b/src/property/installer.lisp index 72119a0..0196438 100644 --- a/src/property/installer.lisp +++ b/src/property/installer.lisp @@ -189,7 +189,7 @@ using a combinator like ON-CHANGE, or applied manually with DEPLOY-THESE." (flet ((preservedp (pathname) (member pathname preserved-directories :test #'pathname-equal))) (mount:assert-devtmpfs-udev-/dev) - (unless (zerop (mrun :for-exit "mountpoint" "-q" "/run")) + (unless (mountpointp "/run") (failed-change "/run is not a mount point; don't know what to do.")) ;; If there's an EFI system partition, we need to store knowledge of @@ -198,7 +198,7 @@ using a combinator like ON-CHANGE, or applied manually with DEPLOY-THESE." ;; is responsible for adding an entry for the EFI system partition to ;; the new system's fstab, but we are responsible for restoring ;; knowledge of the partition to the kernel's mount table. - (when (zerop (mrun :for-exit "mountpoint" "-q" "/boot/efi")) + (when (mountpointp "/boot/efi") (destructuring-bind (type source options) (words (stripln (run "findmnt" "-nro" "FSTYPE,SOURCE,OPTIONS" "/boot/efi"))) diff --git a/src/property/mount.lisp b/src/property/mount.lisp index 21d5530..e0c3430 100644 --- a/src/property/mount.lisp +++ b/src/property/mount.lisp @@ -109,7 +109,7 @@ After mounting /sys, mount this when /sys/firmware/efi/efivars exists.") (defun assert-devtmpfs-udev-/dev () "On a system with the Linux kernel, assert that /dev has fstype devtmpfs." - (unless (and (zerop (mrun :for-exit "mountpoint" "-q" "/dev")) + (unless (and (mountpointp "/dev") (string= "devtmpfs udev" (stripln (run "findmnt" "-nro" "fstype,source" "/dev")))) (failed-change -- cgit v1.2.3