Subject: Re: bug#26341: [PATCH] build: vm: Add missing module.

From: [email-masked] (Ludovic Courtès)
Date: Tue, 04 Apr 2017 14:41:23 +0200

Hello Mathieu,

Mathieu Othacehe <[email-masked]> skribis:

> * gnu/build/vm.scm (define-module): Use module (guix build syscalls).
>
> It fixes the following warnings during guix build :
>
> gnu/build/vm.scm:233:3: warning: possibly unbound variable `mount'
> gnu/build/vm.scm:238:3: warning: possibly unbound variable `umount'
> gnu/build/vm.scm:268:8: warning: possibly unbound variable `mount'
> gnu/build/vm.scm:276:8: warning: possibly unbound variable `umount'
> gnu/build/vm.scm:315:4: warning: possibly unbound variable `mount'
> gnu/build/vm.scm:323:4: warning: possibly unbound variable `umount'

This is weird but on purpose: this module is used in a context, in (gnu
system vm), where ‘guile-static-stripped’ is running, in the initrd.
And ‘guile-static-stripped’ has ‘guile-linux-syscalls.patch’, which adds
bindings for ‘mount’, ‘umount’, etc.

Conversely, (guix build syscalls) relies on the ability to do
dlopen(NULL) and to resolve “mount” et al. from libc.so.  This cannot
work with the statically-linked Guile, which is why we have
‘guile-linux-syscalls.patch’.

So this patch cannot be applied as is, and I think it would break things
that use (gnu build vm).

That said, we should improve this.  Perhaps something along the lines of
the attached patch would work.

Could you try and send an updated patch?

Thanks,
Ludo’.

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 5aae1530f..e108d6169 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -462,7 +462,9 @@ the returned procedure is called."
 (define UMOUNT_NOFOLLOW 8)
 
 (define mount
-  (let ((proc (syscall->procedure int "mount" `(* * * ,unsigned-long *))))
+  (let ((proc (if (module-defined? the-scm-module 'mount)
+                  (module-ref the-scm-module 'mount)
+                  (syscall->procedure int "mount" `(* * * ,unsigned-long *)))))
     (lambda* (source target type #:optional (flags 0) options
                      #:key (update-mtab? #f))
       "Mount device SOURCE on TARGET as a file system TYPE.  Optionally, FLAGS