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

pkg: Change directory to / before executing maintainer scripts

This should give maintainer scripts a more stable and sane environment.

This change does not work too well with relative admindir paths, as they
need to be normalized on input. But then several dpkg tools do not play
nice with relative amindirs anyway, and this needs a general cleanup
which will be done on subsequent commits.

Closes: #686782
Guillem Jover лет назад: 14
Родитель
Сommit
7fb7f6e154
2 измененных файлов с 5 добавлено и 2 удалено
  1. 1 0
      debian/changelog
  2. 4 2
      src/script.c

+ 1 - 0
debian/changelog

@@ -68,6 +68,7 @@ dpkg (1.17.0) UNRELEASED; urgency=low
     when we are definitely removing the main path.
   * Activate file triggers on removal more accurately, only when we know
     we are inevitably removing things.
+  * Change dir to / before executing maintainer scripts. Closes: #686782
 
  -- Guillem Jover <guillem@debian.org>  Fri, 03 Aug 2012 13:21:00 +0200
 

+ 4 - 2
src/script.c

@@ -118,9 +118,11 @@ preexecscript(struct command *cmd)
 
 		if (chroot(instdir))
 			ohshite(_("failed to chroot to `%.250s'"), instdir);
-		if (chdir("/"))
-			ohshite(_("failed to chdir to `%.255s'"), "/");
 	}
+	/* Switch to a known good directory to give the maintainer script
+	 * a saner environment, also needed after the chroot(). */
+	if (chdir("/"))
+		ohshite(_("failed to chdir to `%.255s'"), "/");
 	if (debug_has_flag(dbg_scripts)) {
 		struct varbuf args = VARBUF_INIT;
 		const char **argv = cmd->argv;