Browse Source

dpkg: Add support for DPKG_MAINTSCRIPT_DEBUG environment variable

This variable will be set on the maintainer scripts environment to
either 0 or 1, depending on whether dpkg was called with --debug
requesting maintainer scripts debugging output.
Guillem Jover 8 years ago
parent
commit
522a3ba285
3 changed files with 12 additions and 0 deletions
  1. 1 0
      debian/changelog
  2. 6 0
      man/dpkg.1
  3. 5 0
      src/script.c

+ 1 - 0
debian/changelog

@@ -16,6 +16,7 @@ dpkg (1.18.4) UNRELEASED; urgency=low
   * Make dpkg-architecture warning on non-matching GNU system type compiler
     agnostic.
   * Add ‘.gitreview’ to the default dpkg-source ignore lists.
+  * Add support for DPKG_MAINTSCRIPT_DEBUG environment variable to dpkg.
   * Test suite:
     - Improve perl code test coverage.
   * Build system:

+ 6 - 0
man/dpkg.1

@@ -858,6 +858,12 @@ architecture the package got built for (since dpkg 1.15.4).
 Defined by \fBdpkg\fP on the maintainer script environment to the
 name of the script running, one of \fBpreinst\fP, \fBpostinst\fP,
 \fBprerm\fP or \fBpostrm\fP (since dpkg 1.15.7).
+.TP
+.B DPKG_MAINTSCRIPT_DEBUG
+Defined by \fBdpkg\fP on the maintainer script environment to a value
+(\(oq\fB0\fP\(cq or \(oq\fB1\fP\(cq) noting whether debugging has been
+requested (with the \fB\-\-debug\fP option) for the maintainer scripts
+(since dpkg 1.18.4).
 .
 .SH FILES
 .TP

+ 5 - 0
src/script.c

@@ -36,6 +36,7 @@
 #endif
 
 #include <dpkg/i18n.h>
+#include <dpkg/debug.h>
 #include <dpkg/dpkg.h>
 #include <dpkg/dpkg-db.h>
 #include <dpkg/pkg.h>
@@ -165,13 +166,17 @@ maintscript_exec(struct pkginfo *pkg, struct pkgbin *pkgbin,
 	pid = subproc_fork();
 	if (pid == 0) {
 		char *pkg_count;
+		const char *maintscript_debug;
 
 		pkg_count = str_fmt("%d", pkgset_installed_instances(pkg->set));
 
+		maintscript_debug = debug_has_flag(dbg_scripts) ? "1" : "0";
+
 		if (setenv("DPKG_MAINTSCRIPT_PACKAGE", pkg->set->name, 1) ||
 		    setenv("DPKG_MAINTSCRIPT_PACKAGE_REFCOUNT", pkg_count, 1) ||
 		    setenv("DPKG_MAINTSCRIPT_ARCH", pkgbin->arch->name, 1) ||
 		    setenv("DPKG_MAINTSCRIPT_NAME", cmd->argv[0], 1) ||
+		    setenv("DPKG_MAINTSCRIPT_DEBUG", maintscript_debug, 1) ||
 		    setenv("DPKG_RUNNING_VERSION", PACKAGE_VERSION, 1))
 			ohshite(_("unable to setenv for maintainer script"));