The following commit has been merged in the master branch:
commit 73c189a330b4878ab7be880d4b943fe9fbb3b06d
Author: Raphael Hertzog <[email protected]>
Date:   Sun Feb 22 23:09:51 2009 +0100

    update-alternatives: add --log option
    
    This option overrides the default log file /var/log/dpkg.log.
    It is needed to make the update-alternatives test-suite succeed
    when run with fakeroot because without override the test-suite would
    try to write to /var/log/dpkg.log and fail. Hence adjust
    the test-suite accordingly.

diff --git a/ChangeLog b/ChangeLog
index 4e8749e..256d0c3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2009-02-22  Raphael Hertzog  <[email protected]>
 
+       * scripts/update-alternatives.pl: Add new option --log to
+       log to another file than /var/log/dpkg.log.
+       * man/update-alternatives.8: Document the new option.
+       * scripts/t/900_update_alternatives.t: Call update-alternatives
+       with --log /dev/null since the test suite can be run with fakeroot
+       and it would try to write to /var/log/dpkg.log because fakeroot
+       makes it believe that it is writable.
+
+2009-02-22  Raphael Hertzog  <[email protected]>
+
        * scripts/update-alternatives.pl: update-alternatives should not
        replace real files by symlinks. When --install is called, the
        alternative link should either not exist or already be a link. It
diff --git a/man/update-alternatives.8 b/man/update-alternatives.8
index c21edc0..71320af 100644
--- a/man/update-alternatives.8
+++ b/man/update-alternatives.8
@@ -331,6 +331,9 @@ different from the default.
 Specifies the administrative directory, when this is to be
 different from the default.
 .TP
+.BI \-\-log " file"
+Specifies the log file, when this is to be different from the default
+(/var/log/dpkg.log).
 .TP
 .BI \-\-force
 Let \fBupdate-alternatives\fR replace any real file that is installed
diff --git a/scripts/t/900_update_alternatives.t 
b/scripts/t/900_update_alternatives.t
index 21618c5..58da41a 100644
--- a/scripts/t/900_update_alternatives.t
+++ b/scripts/t/900_update_alternatives.t
@@ -12,8 +12,8 @@ my $admindir = 
File::Spec->rel2abs("$srcdir/t.tmp/ua/admindir"),
 my $altdir = File::Spec->rel2abs("$srcdir/t.tmp/ua/alternatives");
 my $bindir = File::Spec->rel2abs("$srcdir/t.tmp/ua/bin");
 # XXX: switch to version without .pl
-my @ua = ("$srcdir/update-alternatives.pl", "--quiet", "--admindir",
-         "$admindir", "--altdir", "$altdir");
+my @ua = ("$srcdir/update-alternatives.pl", "--log", "/dev/null",
+          "--quiet", "--admindir", "$admindir", "--altdir", "$altdir");
 
 my $main_link = "$bindir/generic-test";
 my $main_name = "generic-test";
diff --git a/scripts/update-alternatives.pl b/scripts/update-alternatives.pl
index 387b790..4e0a865 100755
--- a/scripts/update-alternatives.pl
+++ b/scripts/update-alternatives.pl
@@ -23,6 +23,7 @@ my $alternative;      # Alternative worked on
 my $inst_alt;         # Alternative to install
 my $fileset;          # Set of files to install in the alternative
 my $path;             # Path of alternative we are offering
+my $log_file = "/var/log/dpkg.log";
 my $skip_auto = 0;    # Skip alternatives properly configured in auto mode 
(for --config)
 my $verbosemode = 0;
 my $force = 0;
@@ -96,6 +97,10 @@ while (@ARGV) {
         }
         $inst_alt->add_slave($sname, $slink);
         $fileset->add_slave($sname, $spath);
+    } elsif (m/^--log$/) {
+        @ARGV || badusage(_g("--%s needs a <file> argument"), "log");
+        $log_file = shift @ARGV;
+        push @pass_opts, $_, $log_file;
     } elsif (m/^--altdir$/) {
         @ARGV || badusage(_g("--%s needs a <directory> argument"), "altdir");
         $altdir = shift @ARGV;
@@ -472,9 +477,9 @@ sub set_action {
         my ($msg) = @_;
         # XXX: the C rewrite must use the std function to get the
         # filename from /etc/dpkg/dpkg.cfg or from command line
-        if (!defined($fh_log) and -w "/var/log/dpkg.log") {
-            open($fh_log, ">>", "/var/log/dpkg.log") ||
-                quit(_g("Can't append to %s"), "/var/log/dpkg.log");
+        if (!defined($fh_log) and -w $log_file) {
+            open($fh_log, ">>", $log_file) ||
+                quit(_g("Can't append to %s"), $log_file);
         }
         if (defined($fh_log)) {
             $msg = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime()) .

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to