From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6OZ2KKRSkF9DPAAA0tVLHw (envelope-from ) for ; Wed, 21 Oct 2020 15:24:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id cAQ6JKRSkF+LXwAAbx9fmQ (envelope-from ) for ; Wed, 21 Oct 2020 15:24:20 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 49ED9940414 for ; Wed, 21 Oct 2020 15:24:20 +0000 (UTC) Received: from localhost ([::1]:57768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVFyN-0003Cg-5X for larch@yhetil.org; Wed, 21 Oct 2020 11:24:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVFnS-00057R-8f for guix-patches@gnu.org; Wed, 21 Oct 2020 11:13:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVFnR-0001Ri-W2 for guix-patches@gnu.org; Wed, 21 Oct 2020 11:13:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kVFnR-0004MN-S7 for guix-patches@gnu.org; Wed, 21 Oct 2020 11:13:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#39807] [PATCH] guix: pack: Only wrap executable files. Resent-From: Eric Bavier Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 21 Oct 2020 15:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39807 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 39807@debbugs.gnu.org Received: via spool by 39807-submit@debbugs.gnu.org id=B39807.160329314816708 (code B ref 39807); Wed, 21 Oct 2020 15:13:01 +0000 Received: (at 39807) by debbugs.gnu.org; 21 Oct 2020 15:12:28 +0000 Received: from localhost ([127.0.0.1]:50232 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVFmt-0004LN-Pm for submit@debbugs.gnu.org; Wed, 21 Oct 2020 11:12:28 -0400 Received: from mout01.posteo.de ([185.67.36.65]:33083) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kVFmr-0004L8-K5 for 39807@debbugs.gnu.org; Wed, 21 Oct 2020 11:12:26 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 75A94160064 for <39807@debbugs.gnu.org>; Wed, 21 Oct 2020 17:12:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1603293139; bh=yUfArOs3huv4h5jGZm+vjr5p6rbmt85VBVcNKE72uT0=; h=Subject:From:To:Cc:Date:From; b=ZA7lgQRQR2xzOeTjyHzVVlLDKbFDpOOFmSaaOju1+DyKtBxoL+PVCLEUsyPP7j9jf RxGERGxHs2DCjpX5a968Y/b8yQdmUYNE5TK81LyMFvhZSxRsWfELVUAONEZmZnLZrH HgRdgvBL65bFZDyh1SFXAATsTMW1pwqPmp9LYf4Z7irMuNv49lGsPSdKlWPfUvjImD DSas0jX+uzEGkaQnRoG4aoFGLrPk5mjOQKpFlBjgLNBm2pRGJeB+SH/u4qGqE7As9P xVnnx3lN8yCk9LDM3HIdeMp1cCTUK7Fn+gVyfkkfME3no/OIY+B6vDK4+KlFVXN7HR 4TanzP4z6InyA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4CGYrL1lRfz6tp2; Wed, 21 Oct 2020 17:12:17 +0200 (CEST) Message-ID: <69f5446e2accd24cd1de9e3964373ab525b0875d.camel@posteo.net> From: Eric Bavier Date: Wed, 21 Oct 2020 10:12:14 -0500 In-Reply-To: <87wnzk7xs0.fsf@gnu.org> References: <3ace941f920d87da65de6e4fdc16add5b9725434.camel@posteo.net> <83416910901e77b537b64de392ee02598ccd72ff.camel@posteo.net> <87wnzk7xs0.fsf@gnu.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=posteo.net header.s=2017 header.b=ZA7lgQRQ; dmarc=fail reason="SPF not aligned (strict)" header.from=posteo.net (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: +wz6pg4300SO Hi Ludo, On Wed, 2020-10-21 at 11:07 +0200, Ludovic Courtès wrote: > Hi Eric, > > Instead of searching for an occurrence of ORIGINAL_STORE, can’t we use > the file name of the wrapper (as opposed to WRAPPED_PROGRAM) in the > index calculation? Along these lines: Good idea, I hadn't considered that we know the destination of the wrapper in advance. This works as long as we make sure "result" is in canonical form, e.g. no repeated separators, because /proc/self/exe is in canonical form: diff --git a/gnu/packages/aux-files/run-in-namespace.c b/gnu/packages/aux-files/run-in-namespace.c index 52a16a5362..947ff02dda 100644 --- a/gnu/packages/aux-files/run-in-namespace.c +++ b/gnu/packages/aux-files/run-in-namespace.c @@ -620,7 +620,7 @@ main (int argc, char *argv[]) /* SELF is something like "/home/ludo/.local/gnu/store/…-foo/bin/ls" and we want to extract "/home/ludo/.local/gnu/store". */ size_t index = strlen (self) - - strlen ("@WRAPPED_PROGRAM@") + strlen (original_store); + - strlen (WRAPPER_PROGRAM) + strlen (original_store); char *store = strdup (self); store[index] = '\0'; diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm index ac578aa965..8106031d6d 100644 --- a/guix/scripts/pack.scm +++ b/guix/scripts/pack.scm @@ -776,6 +776,10 @@ last resort for relocation." (#f base) (index (string-drop base index))))) + (define (find-input-files dir) + ;; Note: Use 'stat' so that symlinks are followed. + (find-files (string-append input "/" dir) #:stat stat)) + (define (elf-interpreter elf) ;; Return the interpreter of ELF as a string, or #f if ELF has no ;; interpreter segment. @@ -849,7 +853,7 @@ last resort for relocation." (("@STORE_DIRECTORY@") (%store-directory))) (let* ((base (strip-store-prefix program)) - (result (string-append target "/" base)) + (result (string-append target base)) (proot #$(and proot? #~(string-drop #$(file-append (proot) "/bin/proot") @@ -858,6 +862,7 @@ last resort for relocation." (mkdir-p (dirname result)) (apply invoke #$compiler "-std=gnu99" "-static" "-Os" "-g0" "-Wall" "run.c" "-o" result + (string-append "-DWRAPPER_PROGRAM=\"" result "\"") (append (if proot (list (string-append "-DPROOT_PROGRAM=\"" proot "\"")) @@ -878,10 +883,9 @@ last resort for relocation." (receive (executables others) (partition executable-file? - ;; Note: Trailing slash in case these are symlinks. - (append (find-files (string-append input "/bin/")) - (find-files (string-append input "/sbin/")) - (find-files (string-append input "/libexec/")))) + (append (find-input-files "bin") + (find-input-files "sbin") + (find-input-files "libexec"))) ;; Wrap only executables, since the wrapper will eventually need ;; to execve them. E.g. git's "libexec" directory contains many ;; shell scripts that are source'd from elsewhere, which fails if