Browse Source

u-a: Generalize admindir environment variable handling

This variable is currently set by dpkg, but other package managers or
callers might set it with a different name on other downstream projects.
Let's move the variable name to the build system so that third parties
do not have to modify the code going on to remove a dpkg-specific name.
Guillem Jover 10 years ago
parent
commit
cb93a53a1d
3 changed files with 13 additions and 4 deletions
  1. 3 0
      debian/changelog
  2. 4 0
      utils/Makefile.am
  3. 6 4
      utils/update-alternatives.c

+ 3 - 0
debian/changelog

@@ -26,6 +26,9 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
   * Add source format backend-specific --help options support to dpkg-source.
   * Add MIPS R6 architectures to arch tables. Closes: #807340
     Thanks to YunQiang Su <wzssyqa@gmail.com>.
+  * Portability:
+    - Move DPKG_ADMINDIR environment variable name out from update-alternatives
+      code, to make life easier for non-dpkg-based systems.
   * Perl modules:
     - Add new CTRL_REPO_RELEASE control block type to Dpkg::Control.
     - Add new CTRL_COPYRIGHT_HEADER, CTRL_COPYRIGHT_FILES and

+ 4 - 0
utils/Makefile.am

@@ -24,6 +24,10 @@ endif
 update_alternatives_SOURCES = \
 	update-alternatives.c
 
+update_alternatives_CPPFLAGS = \
+	-DADMINDIR_ENVVAR=\"DPKG_ADMINDIR\" \
+	$(AM_CPPFLAGS)
+
 update_alternatives_LDADD = \
 	../lib/compat/libcompat.la \
 	$(LIBINTL) \

+ 6 - 4
utils/update-alternatives.c

@@ -352,11 +352,13 @@ set_action(const char *new_action)
 static const char *
 admindir_init(void)
 {
-	const char *basedir, *dpkg_basedir;
+	const char *basedir, *basedir_env;
 
-	dpkg_basedir = getenv("DPKG_ADMINDIR");
-	if (dpkg_basedir)
-		basedir = dpkg_basedir;
+	/* Try to get the admindir from an environment variable, usually set
+	 * by the system package manager. */
+	basedir_env = getenv(ADMINDIR_ENVVAR);
+	if (basedir_env)
+		basedir = basedir_env;
 	else
 		basedir = ADMINDIR;