Subject: Re: bug#32478: pcscd service activation causes boot failure

From: [email-masked] (Ludovic Courtès)
Date: Mon, 20 Aug 2018 18:13:25 +0200

Hello,

Chris Marusich <[email-masked]> skribis:

> The attached patch fixes the issue by using an idempotent procedure to
> create the symlink.  If there are no objections, I'll push the patch to
> master about 24 hours from now.  There is a fairly long comment in my
> patch because although I wanted to re-use the switch-symlinks procedure
> from (guix utils), I couldn't figure out how to do it.  Ideas regarding
> this are welcome!  To be specific, I tried to use (guix utils), but then
> I got the following error message at boot time (see my comment for more
> information):
>
> loading '/gnu/store/f4ng1dlpm7q74vssbb049vpf2gvw3n3r-system/boot'...
> [    2.175072] random: fast init done
> making '/gnu/store/f4ng1dlpm7q74vssbb049vpf2gvw3n3r-system' the current system..
> .
> setting up setuid programs in '/run/setuid-programs'...
> populating /etc from /gnu/store/n6cwz1hlmjylva2xrv61njl68g6c8k5l-etc...
> usermod: no changes
> usermod: no changes
> usermod: no changes
> ERROR: In procedure dynamic-func:
> In procedure dynamic-pointer: Symbol not found: strverscmp

This is because (guix utils) pulls in lots of things that are not really
meant to be used on the “build side” (a misnomer in this case, but you
see what I mean ;-)).  Here, it assumes that dlopen support is available
but it’s not because the activation snippet runs on the
statically-linked Guile.

> From 3fa1e930b827aebca2dbbfe84c36cf203f15afda Mon Sep 17 00:00:00 2001
> From: Chris Marusich <[email-masked]>
> Date: Mon, 20 Aug 2018 00:16:06 -0700
> Subject: [PATCH] gnu: services: Fix pcscd activation bug.
>
> * gnu/services/security-token.scm (pcscd-activation): Idempotently create the
> /var/lib/pcsc symlink so that it does not fail when it already exists.

LGTM!

> +     (with-imported-modules (source-module-closure
> +                             '((guix build utils)))
> +       #~(begin
> +           (use-modules (guix build utils))
> +           ;; This switch-symlinks procedure was copied from (guix utils).  It
> +           ;; would be nice to re-use the procedure from that module, but if
> +           ;; we add that module to this gexp's imported modules and try to
> +           ;; use it, then this activation gexp can fail when it runs.  To be
> +           ;; specific, if you try to use (guix utils) and then build a VM
> +           ;; with a pcscd-service-type using "guix system vm-image", then
> +           ;; when you boot the VM, it will fail.  It fails because (guix
> +           ;; utils) dynamically links glibc's strverscmp function when
> +           ;; defining the version-compare procedure, and for some reason
> +           ;; strverscmp can't be found.  Perhaps there's a way to fix or
> +           ;; avoid this, but since we don't need the version-compare
> +           ;; procedure here, anyway, it's simpler to just define our own
> +           ;; switch-symlinks procedure instead.
> +           (define (switch-symlinks link target)
> +             (let ((pivot (string-append link ".new")))
> +               (symlink target pivot)
> +               (rename-file pivot link)))

I think “TODO: Deduplicate” would be enough as a comment, or at least
something more concise like “XXX: We cannot use (guix utils) because it
requires a dynamically-linked Guile, hence the duplicate
‘switch-symlinks’.”  I leave it up to you!

Thanks,
Ludo’.