unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 41189@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#41189] [PATCH v2 2/4] pack: Factorize store references in wrapper.
Date: Wed, 13 May 2020 14:52:13 +0200	[thread overview]
Message-ID: <20200513125215.27740-3-ludo@gnu.org> (raw)
In-Reply-To: <20200513125215.27740-1-ludo@gnu.org>

* gnu/packages/aux-files/run-in-namespace.c (original_store): New variable.
(exec_in_user_namespace, exec_with_proot, main): Use it instead of the
literal "@STORE_DIRECTORY@".
---
 gnu/packages/aux-files/run-in-namespace.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/gnu/packages/aux-files/run-in-namespace.c b/gnu/packages/aux-files/run-in-namespace.c
index 6beac7fd53..6e97359078 100644
--- a/gnu/packages/aux-files/run-in-namespace.c
+++ b/gnu/packages/aux-files/run-in-namespace.c
@@ -42,6 +42,10 @@
 #include <dirent.h>
 #include <sys/syscall.h>
 
+/* The original store, "/gnu/store" by default.  */
+static const char original_store[] = "@STORE_DIRECTORY@";
+
+
 /* Like 'malloc', but abort if 'malloc' returns NULL.  */
 static void *
 xmalloc (size_t size)
@@ -228,7 +232,7 @@ exec_in_user_namespace (const char *store, int argc, char *argv[])
      bind-mounted in the right place.  */
   int err;
   char *new_root = mkdtemp (strdup ("/tmp/guix-exec-XXXXXX"));
-  char *new_store = concat (new_root, "@STORE_DIRECTORY@");
+  char *new_store = concat (new_root, original_store);
   char *cwd = get_current_dir_name ();
 
   /* Create a child with separate namespaces and set up bind-mounts from
@@ -307,11 +311,11 @@ exec_with_proot (const char *store, int argc, char *argv[])
   int proot_specific_argc = 4;
   int proot_argc = argc + proot_specific_argc;
   char *proot_argv[proot_argc + 1], *proot;
-  char bind_spec[strlen (store) + 1 + sizeof "@STORE_DIRECTORY@"];
+  char bind_spec[strlen (store) + 1 + sizeof original_store];
 
   strcpy (bind_spec, store);
   strcat (bind_spec, ":");
-  strcat (bind_spec, "@STORE_DIRECTORY@");
+  strcat (bind_spec, original_store);
 
   proot = concat (store, PROOT_PROGRAM);
 
@@ -413,8 +417,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 ("@STORE_DIRECTORY@");
+    - strlen ("@WRAPPED_PROGRAM@") + strlen (original_store);
   char *store = strdup (self);
   store[index] = '\0';
 
@@ -424,7 +427,7 @@ main (int argc, char *argv[])
      @WRAPPED_PROGRAM@ right away.  This is not just an optimization: it's
      needed when running one of these wrappers from within an unshare'd
      namespace, because 'unshare' fails with EPERM in that context.  */
-  if (strcmp (store, "@STORE_DIRECTORY@") != 0
+  if (strcmp (store, original_store) != 0
       && lstat ("@WRAPPED_PROGRAM@", &statbuf) != 0)
     {
       const struct engine *engine = execution_engine ();
-- 
2.26.2





  parent reply	other threads:[~2020-05-13 12:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-11 17:05 [bug#41189] [PATCH 0/3] Add Fakechroot engine for 'guix pack -RR' Ludovic Courtès
2020-05-11 17:11 ` [bug#41189] [PATCH 1/3] pack: Wrapper honors 'GUIX_EXECUTION_ENGINE' environment variable Ludovic Courtès
2020-05-11 17:11   ` [bug#41189] [PATCH 2/3] gnu: Add fakechroot Ludovic Courtès
2020-05-11 17:11   ` [bug#41189] [PATCH 3/3] pack: Add relocation via ld.so and fakechroot Ludovic Courtès
2020-05-11 21:18 ` [bug#41189] [PATCH 0/3] Add Fakechroot engine for 'guix pack -RR' Carlos O'Donell
2020-05-12 10:03   ` Ludovic Courtès
2020-05-12 12:09     ` Carlos O'Donell
2020-05-12 15:32       ` Ludovic Courtès
2020-05-13 12:52         ` [bug#41189] [PATCH v2 0/4] " Ludovic Courtès
2020-05-13 12:52           ` [bug#41189] [PATCH v2 1/4] pack: Wrapper honors 'GUIX_EXECUTION_ENGINE' environment variable Ludovic Courtès
2020-05-13 12:52           ` Ludovic Courtès [this message]
2020-05-13 12:52           ` [bug#41189] [PATCH v2 3/4] gnu: Add fakechroot Ludovic Courtès
2020-05-13 12:52           ` [bug#41189] [PATCH v2 4/4] pack: Add relocation via ld.so and fakechroot Ludovic Courtès
2020-05-14 15:24           ` bug#41189: [PATCH v2 0/4] Add Fakechroot engine for 'guix pack -RR' Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200513125215.27740-3-ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=41189@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).