Преглед изворни кода

dpkg: Export variable DPKG_ROOT in maintainer scripts

This variable holds the value of instdir. It is supposed to be used
in maintainer scripts. It should be prepended to all paths that are
operated on. Currently, dpkg chroots to the instdir before invoking
maintainer scripts, so when it does that DPKG_ROOT is set to the empty
string. Thus currently, DPKG_ROOT is always empty.

[guillem@debian.org:
 - Reword man page to clarify current status. ]

Closes: #804624
Signed-off-by: Guillem Jover <guillem@debian.org>
Helmut Grohne пре 10 година
родитељ
комит
1a1cb120d1
4 измењених фајлова са 16 додато и 0 уклоњено
  1. 2 0
      debian/changelog
  2. 10 0
      man/dpkg.1
  3. 2 0
      src/main.c
  4. 2 0
      src/script.c

+ 2 - 0
debian/changelog

@@ -80,6 +80,8 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
   * Add new -I option to dpkg-shlibdeps to ignore package build directories.
   * Add new -I option to dpkg-shlibdeps to ignore package build directories.
     Closes: #821025
     Closes: #821025
   * Add new -O option to dpkg-genchanges.
   * Add new -O option to dpkg-genchanges.
+  * Make dpkg export variable DPKG_ROOT in maintainer scripts. Closes: #804624
+    Thanks to Helmut Grohne <helmut@subdivi.de>.
   * Portability:
   * Portability:
     - Move DPKG_ADMINDIR environment variable name out from update-alternatives
     - Move DPKG_ADMINDIR environment variable name out from update-alternatives
       code, to make life easier for non-dpkg-based systems.
       code, to make life easier for non-dpkg-based systems.

+ 10 - 0
man/dpkg.1

@@ -857,6 +857,16 @@ The currently accepted values are: \fBauto\fP, \fBalways\fP and
 \fBnever\fP (default).
 \fBnever\fP (default).
 .SS Internal environment
 .SS Internal environment
 .TP
 .TP
+.B DPKG_ROOT
+Defined by \fBdpkg\fP on the maintainer script environment to indicate
+which installation to act on (since dpkg 1.18.5).
+The value is intended to be prepended to any path maintainer scripts
+operate on.
+During normal operation, this variable is empy.
+When installing packages into a different \fBinstdir\fP, \fBdpkg\fP
+normally invokes maintainer scripts using \fBchroot\fP(2) and leaves
+this variable empty.
+.TP
 .B DPKG_SHELL_REASON
 .B DPKG_SHELL_REASON
 Defined by \fBdpkg\fP on the shell spawned on the conffile prompt to
 Defined by \fBdpkg\fP on the shell spawned on the conffile prompt to
 examine the situation (since dpkg 1.15.6).
 examine the situation (since dpkg 1.15.6).

+ 2 - 0
src/main.c

@@ -876,6 +876,8 @@ int main(int argc, const char *const *argv) {
   /* Always set environment, to avoid possible security risks. */
   /* Always set environment, to avoid possible security risks. */
   if (setenv("DPKG_ADMINDIR", admindir, 1) < 0)
   if (setenv("DPKG_ADMINDIR", admindir, 1) < 0)
     ohshite(_("unable to setenv for subprocesses"));
     ohshite(_("unable to setenv for subprocesses"));
+  if (setenv("DPKG_ROOT", instdir, 1) < 0)
+    ohshite(_("unable to setenv for subprocesses"));
 
 
   if (!f_triggers)
   if (!f_triggers)
     f_triggers = (cipaction->arg_int == act_triggers && *argv) ? -1 : 1;
     f_triggers = (cipaction->arg_int == act_triggers && *argv) ? -1 : 1;

+ 2 - 0
src/script.c

@@ -105,6 +105,8 @@ maintscript_pre_exec(struct command *cmd)
 			ohshit(_("admindir must be inside instdir for dpkg to work properly"));
 			ohshit(_("admindir must be inside instdir for dpkg to work properly"));
 		if (setenv("DPKG_ADMINDIR", admindir + instdirl, 1) < 0)
 		if (setenv("DPKG_ADMINDIR", admindir + instdirl, 1) < 0)
 			ohshite(_("unable to setenv for subprocesses"));
 			ohshite(_("unable to setenv for subprocesses"));
+		if (setenv("DPKG_ROOT", "", 1) < 0)
+			ohshite(_("unable to setenv for subprocesses"));
 
 
 		if (chroot(instdir))
 		if (chroot(instdir))
 			ohshite(_("failed to chroot to '%.250s'"), instdir);
 			ohshite(_("failed to chroot to '%.250s'"), instdir);