The following commit has been merged in the master branch:
commit 4da6f227798069945000aadf01c5eecc42f7f52e
Author: Guillem Jover <[email protected]>
Date:   Sat Feb 20 07:29:06 2010 +0100

    dpkg: Set interesting environment variables on conffile shell spawn
    
    Set DPKG_SHELL_REASON, DPKG_CONFFILE_OLD and DPKG_CONFFILE_NEW
    environment variables when spawning a shell for conffile
    examination, so that the user can easily use them for scripting, or
    as easy mnemonics.
    
    Suggested-by: Daniel Martin <[email protected]>
    
    Closes: #60329

diff --git a/debian/changelog b/debian/changelog
index a79b962..933edea 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -98,6 +98,9 @@ dpkg (1.15.6) UNRELEASED; urgency=low
   * Always spawn a new shell on conffile prompt, instead of supporting
     self backgrounding, remove DPKG_NO_TSTP environment variable support.
     Closes: #38334
+  * Set DPKG_SHELL_REASON, DPKG_CONFFILE_OLD and DPKG_CONFFILE_NEW environment
+    variables when spawning a shell for conffile examination. Closes: #60329
+    Thanks to Daniel Martin <[email protected]> for the idea.
 
   [ Modestas Vainius ]
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to
diff --git a/man/dpkg.1 b/man/dpkg.1
index 74a8c4b..e88d007 100644
--- a/man/dpkg.1
+++ b/man/dpkg.1
@@ -620,6 +620,18 @@ The program \fBdpkg\fP will execute when starting a new 
shell.
 Sets the number of columns \fBdpkg\fP should use when displaying formatted
 text. Currently only used by \-l.
 .TP
+.B DPKG_SHELL_REASON
+Defined by \fBdpkg\fP on the shell spawned on the conffile prompt to
+examine the situation. Current valid value: \fBconffile\-prompt\fP.
+.TP
+.B DPKG_CONFFILE_OLD
+Defined by \fBdpkg\fP on the shell spawned on the conffile prompt to
+examine the situation. Contains the path to the old conffile.
+.TP
+.B DPKG_CONFFILE_NEW
+Defined by \fBdpkg\fP on the shell spawned on the conffile prompt to
+examine the situation. Contains the path to the new conffile.
+.TP
 .B DPKG_RUNNING_VERSION
 Defined by \fBdpkg\fP on the maintainer script environment to the
 version of the currently running \fBdpkg\fP instance.
diff --git a/src/configure.c b/src/configure.c
index 42245f0..96080a5 100644
--- a/src/configure.c
+++ b/src/configure.c
@@ -519,9 +519,12 @@ showdiff(const char *old, const char *new)
  *
  * Create a subprocess and execute a shell to allow the user to manually
  * solve the conffile conflict.
+ *
+ * @param confold The path to the old conffile.
+ * @param confnew The path to the new conffile.
  */
 static void
-spawn_shell(void)
+spawn_shell(const char *confold, const char *confnew)
 {
        pid_t pid;
 
@@ -536,6 +539,11 @@ spawn_shell(void)
                if (!shell || !*shell)
                        shell = DEFAULTSHELL;
 
+               /* Set useful variables for the user. */
+               setenv("DPKG_SHELL_REASON", "conffile-prompt", 1);
+               setenv("DPKG_CONFFILE_OLD", confold, 1);
+               setenv("DPKG_CONFFILE_NEW", confnew, 1);
+
                execlp(shell, shell, "-i", NULL);
                ohshite(_("failed to exec shell (%.250s)"), shell);
        }
@@ -686,7 +694,7 @@ promptconfaction(struct pkginfo *pkg, const char *cfgfile,
                        showdiff(realold, realnew);
 
                if (cc == 'z')
-                       spawn_shell();
+                       spawn_shell(realold, realnew);
        } while (!strchr("yino", cc));
 
        log_message("conffile %s %s", cfgfile,

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to