Przeglądaj źródła

update-alternatives: add logging to /var/log/dpkg.log

Add logging statements in update-alternatives for all calls that can
modify the status of the link group. Also log explicitely alternative
removal, auto-reparation and update. Closes: #445270
Raphael Hertzog 17 lat temu
rodzic
commit
9fac3bb498
3 zmienionych plików z 31 dodań i 1 usunięć
  1. 5 0
      ChangeLog
  2. 1 0
      debian/changelog
  3. 25 1
      scripts/update-alternatives.pl

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+2009-02-22  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/update-alternatives.pl: Add logging to
+	/var/log/dpkg.log.
+
 2009-02-22  Raphael Hertzog  <hertzog@debian.org>
 
 	* man/update-alternatives.8: The vocabulary used was misleading

+ 1 - 0
debian/changelog

@@ -156,6 +156,7 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Rewrite update-alternatives (so that we can understand it again) and
     implement new features on top of it:
     - the --config output is now sorted. Closes: #437060
+    - it now logs information to /var/log/dpkg.log. Closes: #445270
 
   [ Pierre Habouzit ]
   * Add a --query option to update-alternatives. Closes: #336091, #441904

+ 25 - 1
scripts/update-alternatives.pl

@@ -32,6 +32,7 @@ $| = 1;
 # Main program
 #
 
+my @COPY_ARGV = @ARGV;
 while (@ARGV) {
     $_ = shift(@ARGV);
     last if m/^--$/;
@@ -136,6 +137,7 @@ if ($action eq 'display') {
 }
 
 # Actions below might modify the system
+log_msg("run with @COPY_ARGV");
 
 my $current_choice = '';
 if ($alternative->has_current_link()) {
@@ -245,13 +247,15 @@ if ($action eq 'set') {
 
 # No choice left, remove everything
 if (not scalar($alternative->choices())) {
+    log_msg("link group " . $alternative->name() . " fully removed");
     $alternative->remove();
     exit 0;
 }
 
 # New choice wanted
-#print "NEW: $new_choice, was $current_choice\n";
 if (defined($new_choice) and ($current_choice ne $new_choice)) {
+    log_msg("link group " . $alternative->name() .
+            " updated to point to " . $new_choice);
     printf _g("Using '%s' to provide '%s' in %s.") . "\n", $new_choice,
            $alternative->name(),
            ($alternative->status() eq "auto" ? _g("auto mode") : _g("manual mode"))
@@ -259,6 +263,7 @@ if (defined($new_choice) and ($current_choice ne $new_choice)) {
     $alternative->prepare_install($new_choice);
 } elsif ($alternative->is_broken()) {
     # TODO: warn & log
+    log_msg("auto-repair link group " . $alternative->name());
     $alternative->prepare_install($current_choice) if $current_choice;
 }
 
@@ -350,6 +355,24 @@ sub set_action {
     $action = $value;
 }
 
+{
+    my $fh_log;
+    sub log_msg {
+        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)) {
+            $msg = POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime()) .
+                   " $progname: $msg\n";
+            print $fh_log $msg;
+        }
+    }
+}
+
 sub config_all {
     opendir(ADMINDIR, $admdir)
         or quit(_g("can't readdir %s: %s"), $admdir, $!);
@@ -525,6 +548,7 @@ sub set_status {
     if (!defined($self->status()) or $status ne $self->status()) {
         $self->{modified} = 1;
     }
+    main::log_msg("status of link group " . $self->name() . " set to $status");
     $self->{status} = $status;
 }
 sub set_link {