Procházet zdrojové kódy

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 před 16 roky
rodič
revize
4da6f22779
3 změnil soubory, kde provedl 25 přidání a 2 odebrání
  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
     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 <Daniel.Martin@jhu.edu> for the idea.
 
   [ Modestas Vainius ]
   * 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
 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.

+ 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
  * 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,