--- /usr/sbin/update-alternatives.bk	2007-11-29 06:02:52.000000000 +0100
+++ /usr/sbin/update-alternatives	2007-12-19 00:37:18.000000000 +0100
@@ -229,6 +229,38 @@ sub check_many_actions()
     badusage(sprintf(_g("two commands specified: %s and --%s"), $_, $action));
 }
 
+sub checked_slave ($$$) {
+	my ($sname, $slink, $spath) = @_;
+	$linkname = readlink($slink);
+	if (!defined($linkname) && $! != ENOENT) {
+		pr(sprintf(_g("warning: %s is supposed to be a slave symlink to\n".
+		              " %s, or nonexistent; however, readlink failed: %s"),
+		           $slink, "$altdir/$sname", $!))
+		    if $verbosemode > 0;
+	} elsif (!defined($linkname) ||
+	        (defined($linkname) && $linkname ne "$altdir/$sname")) {
+		unlink("$slink.dpkg-tmp") || $! == ENOENT ||
+		    quit(sprintf(_g("unable to ensure %s nonexistent: %s"),
+		                 "$slink.dpkg-tmp", $!));
+		symlink("$altdir/$sname","$slink.dpkg-tmp") ||
+		    quit(sprintf(_g("unable to make %s a symlink to %s: %s"),
+		                 "$slink.dpkg-tmp", "$altdir/$sname", $!));
+		rename_mv("$slink.dpkg-tmp",$slink) ||
+		    quit(sprintf(_g("unable to install %s as %s: %s"),
+		                 "$slink.dpkg-tmp", $slink, $!));
+	}
+	if (defined($linkname = readlink("$altdir/$sname")) && $linkname eq $spath) {
+		&pr(sprintf(_g("Leaving %s (%s) pointing to %s."), $sname, $slink, $spath))
+		  if $verbosemode > 0;
+	} else {
+		&pr(sprintf(_g("Updating %s (%s) to point to %s."), $sname, $slink, $spath))
+		  if $verbosemode > 0;
+	}
+	symlink("$spath","$altdir/$sname.dpkg-tmp") ||
+	    &quit(sprintf(_g("unable to make %s a symlink to %s: %s"), "$altdir/$sname.dpkg-tmp", $spath, $!));
+	rename_mv("$altdir/$sname.dpkg-tmp","$altdir/$sname") ||
+	    &quit(sprintf(_g("unable to install %s as %s: %s"), "$altdir/$sname.dpkg-tmp", "$altdir/$sname", $!));
+}
 
 #
 # Main program
@@ -595,35 +627,7 @@ if ($mode eq 'auto') {
 	    unlink("$slink") || $! == &ENOENT ||
 	        &quit(sprintf(_g("unable to remove %s: %s"), $slink, $!));
         } else {
-	    $linkname = readlink($slink);
-	    if (!defined($linkname) && $! != ENOENT) {
-		pr(sprintf(_g("warning: %s is supposed to be a slave symlink to\n".
-		              " %s, or nonexistent; however, readlink failed: %s"),
-		           $slink, "$altdir/$sname", $!))
-		    if $verbosemode > 0;
-	    } elsif (!defined($linkname) ||
-	            (defined($linkname) && $linkname ne "$altdir/$sname")) {
-		unlink("$slink.dpkg-tmp") || $! == ENOENT ||
-		    quit(sprintf(_g("unable to ensure %s nonexistent: %s"),
-		                 "$slink.dpkg-tmp", $!));
-		symlink("$altdir/$sname","$slink.dpkg-tmp") ||
-		    quit(sprintf(_g("unable to make %s a symlink to %s: %s"),
-		                 "$slink.dpkg-tmp", "$altdir/$sname", $!));
-		rename_mv("$slink.dpkg-tmp",$slink) ||
-		    quit(sprintf(_g("unable to install %s as %s: %s"),
-		                 "$slink.dpkg-tmp", $slink, $!));
-	    }
-            if (defined($linkname= readlink("$altdir/$sname")) && $linkname eq $spath) {
-                &pr(sprintf(_g("Leaving %s (%s) pointing to %s."), $sname, $slink, $spath))
-                  if $verbosemode > 0;
-            } else {
-                &pr(sprintf(_g("Updating %s (%s) to point to %s."), $sname, $slink, $spath))
-                  if $verbosemode > 0;
-            }
-            symlink("$spath","$altdir/$sname.dpkg-tmp") ||
-                &quit(sprintf(_g("unable to make %s a symlink to %s: %s"), "$altdir/$sname.dpkg-tmp", $spath, $!));
-            rename_mv("$altdir/$sname.dpkg-tmp","$altdir/$sname") ||
-                &quit(sprintf(_g("unable to install %s as %s: %s"), "$altdir/$sname.dpkg-tmp", "$altdir/$sname", $!));
+	    checked_slave ($sname, $slink, $spath);
         }
     }
 }
@@ -677,9 +681,7 @@ sub config_alternatives {
 	for( my $slnum = 0; $slnum < @slavenames; $slnum++ ) {
 	    my $slave = $slavenames[$slnum];
 	    if ($slavepath{$preferred,$slnum} ne '') {
-		checked_symlink($slavepath{$preferred,$slnum},
-			"$altdir/$slave.dpkg-tmp");
-		checked_mv("$altdir/$slave.dpkg-tmp", "$altdir/$slave");
+	    	checked_slave ($slave, $slavelinks[$slnum], $slavepath{$preferred,$slnum});
 	    } else {
 		&pr(sprintf(_g("Removing %s (%s), not appropriate with %s."), $slave, $slavelinks[$slnum], $versions[$preferred]))
 		    if $verbosemode > 0;
