Просмотр исходного кода

dpkg: export DPKG_MAINTSCRIPT_NAME to tell what kind of script we're running

The idea is that specialized hooks can benefit from this information to
do the right thing. The same call would be put in the various maintainer
scripts but the actions taken would be different depending on the script
nevertheless.
Raphaël Hertzog лет назад: 16
Родитель
Сommit
246cf59f8c
4 измененных файлов с 10 добавлено и 2 удалено
  1. 3 0
      debian/changelog
  2. 1 0
      lib/dpkg/dpkg.h
  3. 4 0
      man/dpkg.1
  4. 2 2
      src/help.c

+ 3 - 0
debian/changelog

@@ -31,6 +31,9 @@ dpkg (1.15.6.2) UNRELEASED; urgency=low
     This is a temporary work-around so that dselect doesn't try to reinstall
     This is a temporary work-around so that dselect doesn't try to reinstall
     packages of priority > standard that were removed or not installed. Thanks
     packages of priority > standard that were removed or not installed. Thanks
     to Robert Luderda for the patch. Closes: #559519, #556889
     to Robert Luderda for the patch. Closes: #559519, #556889
+  * dpkg now exports DPKG_MAINTSCRIPT_NAME to maintainer scripts with the
+    type of maintainer script currently running (preinst, postinst, prerm,
+    postrm). Closes: #546577
 
 
   [ Colin Watson ]
   [ Colin Watson ]
   * Modern tar files typically use NormalFile1 rather than NormalFile0 for
   * Modern tar files typically use NormalFile1 rather than NormalFile0 for

+ 1 - 0
lib/dpkg/dpkg.h

@@ -80,6 +80,7 @@ DPKG_BEGIN_DECLS
 
 
 #define MAINTSCRIPTPKGENVVAR "DPKG_MAINTSCRIPT_PACKAGE"
 #define MAINTSCRIPTPKGENVVAR "DPKG_MAINTSCRIPT_PACKAGE"
 #define MAINTSCRIPTARCHENVVAR "DPKG_MAINTSCRIPT_ARCH"
 #define MAINTSCRIPTARCHENVVAR "DPKG_MAINTSCRIPT_ARCH"
+#define MAINTSCRIPTNAMEENVVAR "DPKG_MAINTSCRIPT_NAME"
 #define MAINTSCRIPTDPKGENVVAR "DPKG_RUNNING_VERSION"
 #define MAINTSCRIPTDPKGENVVAR "DPKG_RUNNING_VERSION"
 
 
 #define SHELLENV            "SHELL"
 #define SHELLENV            "SHELL"

+ 4 - 0
man/dpkg.1

@@ -651,6 +651,10 @@ package name being handled.
 .B DPKG_MAINTSCRIPT_ARCH
 .B DPKG_MAINTSCRIPT_ARCH
 Defined by \fBdpkg\fP on the maintainer script environment to the
 Defined by \fBdpkg\fP on the maintainer script environment to the
 architecture the package got built for.
 architecture the package got built for.
+.TP
+.B DPKG_MAINTSCRIPT_NAME
+Defined by \fBdpkg\fP on the maintainer script environment to the
+name of the script running (preinst, postinst, prerm, postrm).
 .
 .
 .SH EXAMPLES
 .SH EXAMPLES
 To list packages related to the editor \fBvi\fP(1):
 To list packages related to the editor \fBvi\fP(1):

+ 2 - 2
src/help.c

@@ -258,13 +258,13 @@ do_script(struct pkginfo *pkg, struct pkginfoperfile *pif,
 
 
   c1 = subproc_fork();
   c1 = subproc_fork();
   if (!c1) {
   if (!c1) {
-    cmd->argv[0] = preexecscript(cmd);
-
     if (setenv(MAINTSCRIPTPKGENVVAR, pkg->name, 1) ||
     if (setenv(MAINTSCRIPTPKGENVVAR, pkg->name, 1) ||
         setenv(MAINTSCRIPTARCHENVVAR, pif->architecture, 1) ||
         setenv(MAINTSCRIPTARCHENVVAR, pif->architecture, 1) ||
+        setenv(MAINTSCRIPTNAMEENVVAR, cmd->argv[0], 1) ||
         setenv(MAINTSCRIPTDPKGENVVAR, PACKAGE_VERSION, 1))
         setenv(MAINTSCRIPTDPKGENVVAR, PACKAGE_VERSION, 1))
       ohshite(_("unable to setenv for maintainer script"));
       ohshite(_("unable to setenv for maintainer script"));
 
 
+    cmd->argv[0] = preexecscript(cmd);
     command_exec(cmd);
     command_exec(cmd);
   }
   }
   subproc_signals_setup(cmd->name); /* This does a push_cleanup() */
   subproc_signals_setup(cmd->name); /* This does a push_cleanup() */