summaryrefslogtreecommitdiff
path: root/guix/build
diff options
context:
space:
mode:
Diffstat (limited to 'guix/build')
-rw-r--r--guix/build/profiles.scm23
-rw-r--r--guix/build/syscalls.scm27
2 files changed, 46 insertions, 4 deletions
diff --git a/guix/build/profiles.scm b/guix/build/profiles.scm
index 0c23cd300e..1dc7976879 100644
--- a/guix/build/profiles.scm
+++ b/guix/build/profiles.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -67,8 +67,14 @@ user-friendly name of the profile is, for instance ~/.guix-profile rather than
(define (build-etc/profile output search-paths)
"Build the 'OUTPUT/etc/profile' shell file containing environment variable
definitions for all the SEARCH-PATHS."
- (mkdir-p (string-append output "/etc"))
- (call-with-output-file (string-append output "/etc/profile")
+ (define file
+ (string-append output "/etc/profile"))
+
+ (mkdir-p (dirname file))
+ (when (file-exists? file)
+ (delete-file file))
+
+ (call-with-output-file file
(lambda (port)
;; The use of $GUIX_PROFILE described below is not great. Another
;; option would have been to use "$1" and have users run:
@@ -144,13 +150,22 @@ instead make DIRECTORY a \"real\" directory containing symlinks."
create symlinks. Write MANIFEST, an sexp, to OUTPUT/manifest. Create
OUTPUT/etc/profile with Bash definitions for -all the variables listed in
SEARCH-PATHS."
+ (define manifest-file
+ (string-append output "/manifest"))
+
;; Make the symlinks.
(union-build output inputs
#:symlink symlink
#:log-port (%make-void-port "w"))
+ ;; If one of the INPUTS provides a '/manifest' file, delete it. That can
+ ;; happen if MANIFEST contains something such as a Guix instance, which is
+ ;; ultimately built as a profile.
+ (when (file-exists? manifest-file)
+ (delete-file manifest-file))
+
;; Store meta-data.
- (call-with-output-file (string-append output "/manifest")
+ (call-with-output-file manifest-file
(lambda (p)
(pretty-print manifest p)))
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index d75c11ada7..66d63a2931 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -73,6 +73,7 @@
file-system-mount-flags
statfs
free-disk-space
+ device-in-use?
processes
mkdtemp!
@@ -684,6 +685,32 @@ mounted at FILE."
(define AT_NO_AUTOMOUNT #x800)
(define AT_EMPTY_PATH #x1000)
+(define-syntax BLKRRPART ;<sys/mount.h>
+ (identifier-syntax #x125F))
+
+(define* (device-in-use? device)
+ "Return #t if the block DEVICE is in use, #f otherwise. This is inspired
+from fdisk_device_is_used function of util-linux. This is particulary useful
+for devices that do not appear in /proc/self/mounts like overlayfs lowerdir
+backend device."
+ (let*-values (((fd) (open-fdes device O_RDONLY))
+ ((ret err) (%ioctl fd BLKRRPART %null-pointer)))
+ (close-fdes fd)
+ (cond
+ ((= ret 0)
+ #f)
+ ((= err EBUSY)
+ #t)
+ ((= err EINVAL)
+ ;; We get EINVAL for devices that have the GENHD_FL_NO_PART_SCAN flag
+ ;; set in the kernel, in particular loopback devices, though we do seem
+ ;; to get it for SCSI storage (/dev/sr0) on QEMU.
+ #f)
+ (else
+ (throw 'system-error "ioctl" "~A"
+ (list (strerror err))
+ (list err))))))
+
;;;
;;; Containers.