Browse Source

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 <Daniel.Martin@jhu.edu>

Closes: #60329
Guillem Jover 16 years ago
parent
commit
4da6f22779
3 changed files with 25 additions and 2 deletions
  1. 3 0
      debian/changelog
  2. 12 0
      man/dpkg.1
  3. 10 2
      src/configure.c

+ 3 - 0
debian/changelog

@@ -98,6 +98,9 @@ dpkg (1.15.6) UNRELEASED; urgency=low
   * Always spawn a new shell on conffile prompt, instead of supporting
   * Always spawn a new shell on conffile prompt, instead of supporting
     self backgrounding, remove DPKG_NO_TSTP environment variable support.
     self backgrounding, remove DPKG_NO_TSTP environment variable support.
     Closes: #38334
     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 <Daniel.Martin@jhu.edu> for the idea.
 
 
   [ Modestas Vainius ]
   [ Modestas Vainius ]
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to

+ 12 - 0
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
 Sets the number of columns \fBdpkg\fP should use when displaying formatted
 text. Currently only used by \-l.
 text. Currently only used by \-l.
 .TP
 .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
 .B DPKG_RUNNING_VERSION
 Defined by \fBdpkg\fP on the maintainer script environment to the
 Defined by \fBdpkg\fP on the maintainer script environment to the
 version of the currently running \fBdpkg\fP instance.
 version of the currently running \fBdpkg\fP instance.

+ 10 - 2
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
  * Create a subprocess and execute a shell to allow the user to manually
  * solve the conffile conflict.
  * solve the conffile conflict.
+ *
+ * @param confold The path to the old conffile.
+ * @param confnew The path to the new conffile.
  */
  */
 static void
 static void
-spawn_shell(void)
+spawn_shell(const char *confold, const char *confnew)
 {
 {
 	pid_t pid;
 	pid_t pid;
 
 
@@ -536,6 +539,11 @@ spawn_shell(void)
 		if (!shell || !*shell)
 		if (!shell || !*shell)
 			shell = DEFAULTSHELL;
 			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);
 		execlp(shell, shell, "-i", NULL);
 		ohshite(_("failed to exec shell (%.250s)"), shell);
 		ohshite(_("failed to exec shell (%.250s)"), shell);
 	}
 	}
@@ -686,7 +694,7 @@ promptconfaction(struct pkginfo *pkg, const char *cfgfile,
 			showdiff(realold, realnew);
 			showdiff(realold, realnew);
 
 
 		if (cc == 'z')
 		if (cc == 'z')
-			spawn_shell();
+			spawn_shell(realold, realnew);
 	} while (!strchr("yino", cc));
 	} while (!strchr("yino", cc));
 
 
 	log_message("conffile %s %s", cfgfile,
 	log_message("conffile %s %s", cfgfile,