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

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.
Raphael Hertzog лет назад: 17
Родитель
Сommit
73c189a330
4 измененных файлов с 23 добавлено и 5 удалено
  1. 10 0
      ChangeLog
  2. 3 0
      man/update-alternatives.8
  3. 2 2
      scripts/t/900_update_alternatives.t
  4. 8 3
      scripts/update-alternatives.pl

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2009-02-22  Raphael Hertzog  <hertzog@debian.org>
+
+	* 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  <hertzog@debian.org>
 
 	* scripts/update-alternatives.pl: update-alternatives should not

+ 3 - 0
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

+ 2 - 2
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";

+ 8 - 3
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()) .