瀏覽代碼

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 10 年之前
父節點
當前提交
522a3ba285
共有 3 個文件被更改,包括 12 次插入0 次删除
  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
   * Make dpkg-architecture warning on non-matching GNU system type compiler
     agnostic.
     agnostic.
   * Add ‘.gitreview’ to the default dpkg-source ignore lists.
   * Add ‘.gitreview’ to the default dpkg-source ignore lists.
+  * Add support for DPKG_MAINTSCRIPT_DEBUG environment variable to dpkg.
   * Test suite:
   * Test suite:
     - Improve perl code test coverage.
     - Improve perl code test coverage.
   * Build system:
   * 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
 Defined by \fBdpkg\fP on the maintainer script environment to the
 name of the script running, one of \fBpreinst\fP, \fBpostinst\fP,
 name of the script running, one of \fBpreinst\fP, \fBpostinst\fP,
 \fBprerm\fP or \fBpostrm\fP (since dpkg 1.15.7).
 \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
 .SH FILES
 .TP
 .TP

+ 5 - 0
src/script.c

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