[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] Correct passing of DPKG_ADMINDIR to maintainer scripts with --root



Fix up the DPKG_ADMINDIR env var being passed to maintainer scripts when
running with --root; we need to prune the root directory name from the front
of the admindir we set for chrooted processes, otherwise the directory won't
be found.
---
 src/help.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/help.c b/src/help.c
index 551592a..ef9fa8d 100644
--- a/src/help.c
+++ b/src/help.c
@@ -186,6 +186,11 @@ preexecscript(struct command *cmd)
   size_t instdirl;
 
   if (*instdir) {
+    if (strstr(admindir, instdir) == admindir)
+      /* Already forked, safe to modify the environment; strip off the chroot
+         path from our admin dir so this works under the chroot */
+      if (setenv("DPKG_ADMINDIR", admindir+strlen(instdir), 1) < 0)
+        ohshite(_("unable to setenv for subprocesses"));
     if (chroot(instdir)) ohshite(_("failed to chroot to `%.250s'"),instdir);
     if (chdir("/"))
       ohshite(_("failed to chdir to `%.255s'"), "/");
-- 
1.7.1


Reply to: