diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Add.pm | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Delete.pm | 30 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Error.pm | 11 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackingElement.pm | 13 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/SharedItems.pm | 20 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/UpdateSet.pm | 55 | ||||
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/x509.pm | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_add | 8 | ||||
-rw-r--r-- | usr.sbin/pkg_add/pkg_delete | 6 |
9 files changed, 72 insertions, 81 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Add.pm b/usr.sbin/pkg_add/OpenBSD/Add.pm index 690fdc13186..76124a59aef 100644 --- a/usr.sbin/pkg_add/OpenBSD/Add.pm +++ b/usr.sbin/pkg_add/OpenBSD/Add.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Add.pm,v 1.91 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: Add.pm,v 1.92 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -547,7 +547,7 @@ sub install { my ($self, $state) = @_; $self->SUPER::install($state); - $state->print("You may wish to add ", $self->fullname, " to /etc/man.conf\n"); + $state->log("You may wish to add ", $self->fullname, " to /etc/man.conf\n"); } package OpenBSD::PackingElement::Manpage; diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm index 47d689768b9..0413453e158 100644 --- a/usr.sbin/pkg_add/OpenBSD/Delete.pm +++ b/usr.sbin/pkg_add/OpenBSD/Delete.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Delete.pm,v 1.83 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: Delete.pm,v 1.84 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -158,7 +158,7 @@ sub delete_plist return if $state->{not}; if ($state->{baddelete}) { my $borked = keep_old_files($state, $plist); - $state->print("Files kept as $borked package\n"); + $state->log("Files kept as $borked package\n"); delete $state->{baddelete}; } @@ -407,7 +407,7 @@ sub delete print "Problem: ", $self->fullname, " does not have a checksum\n"; print "NOT deleting: $realname\n"; - $state->print("Couldn't delete $realname (no checksum)\n"); + $state->log("Couldn't delete $realname (no checksum)\n"); return; } my $d = $self->compute_digest($realname, @@ -416,7 +416,7 @@ sub delete print "Problem: checksum doesn't match for ", $self->fullname, "\n"; print "NOT deleting: $realname\n"; - $state->print("Couldn't delete $realname (bad checksum)\n"); + $state->log("Couldn't delete $realname (bad checksum)\n"); $self->do_not_delete($state); return; } @@ -429,7 +429,7 @@ sub delete return if $state->{not}; if (!unlink $realname) { print "Problem deleting $realname\n"; - $state->print("deleting $realname failed: $!\n"); + $state->log("deleting $realname failed: $!\n"); } } @@ -510,23 +510,23 @@ sub delete my $action = $state->{replacing} ? "check" : "remove"; my $origname = $orig->realname($state); if (! -e $realname) { - $state->print("File $realname does not exist\n"); + $state->log("File $realname does not exist\n"); return; } if (! -f $realname) { - $state->print("File $realname is not a file\n"); + $state->log("File $realname is not a file\n"); return; } if (!defined $orig->{d}) { - $state->print("Couldn't delete $realname (no checksum)\n"); + $state->log("Couldn't delete $realname (no checksum)\n"); return; } if ($state->{quick} && $state->{quick} >= 2) { unless ($state->{extra}) { $self->mark_dir($state); - $state->print("You should also $action $realname\n"); + $state->log("You should also $action $realname\n"); return; } } else { @@ -536,7 +536,7 @@ sub delete } else { unless ($state->{extra}) { $self->mark_dir($state); - $state->print("You should also $action $realname (which was modified)\n"); + $state->log("You should also $action $realname (which was modified)\n"); return; } } @@ -545,7 +545,7 @@ sub delete print "deleting $realname\n" if $state->{verbose}; if (!unlink $realname) { print "Problem deleting $realname\n"; - $state->print("deleting $realname failed: $!\n"); + $state->log("deleting $realname failed: $!\n"); } } @@ -606,13 +606,13 @@ sub delete return if $state->{not}; return unless -e $realname or -l $realname; if ($state->{replacing}) { - $state->print("Remember to update $realname\n"); + $state->log("Remember to update $realname\n"); $self->mark_dir($state); } elsif ($state->{extra}) { unlink($realname) or print "problem deleting extra file $realname\n"; } else { - $state->print("You should also remove $realname\n"); + $state->log("You should also remove $realname\n"); $self->mark_dir($state); } } @@ -628,7 +628,7 @@ sub delete if ($state->{extra}) { $self->SUPER::delete($state); } else { - $state->print("You should also remove the directory $realname\n"); + $state->log("You should also remove the directory $realname\n"); $self->mark_dir($state); } } @@ -641,7 +641,7 @@ sub delete if ($state->{extra}) { $self->run($state); } else { - $state->print("You should also run ", $self->{expanded}, "\n"); + $state->log("You should also run ", $self->{expanded}, "\n"); } } diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm index ea1947f5f8b..3f9947da105 100644 --- a/usr.sbin/pkg_add/OpenBSD/Error.pm +++ b/usr.sbin/pkg_add/OpenBSD/Error.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Error.pm,v 1.17 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: Error.pm,v 1.18 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2004 Marc Espie <espie@openbsd.org> # @@ -192,23 +192,24 @@ sub delayed_output print @$msgs; } } + $self->{messages} = {}; } sub system { - my $state = shift; + my $self = shift; if (open(my $grab, "-|", @_)) { my $_; while (<$grab>) { - $state->print($_); + $self->print($_); } if (!close $grab) { - $state->print("system(", join(", ", @_), ") failed: $! ", + $self->print("system(", join(", ", @_), ") failed: $! ", child_error(), "\n"); } return $?; } else { - $state->print("system(", join(", ", @_), + $self->print("system(", join(", ", @_), ") was not run: $!", child_error(), "\n"); } } diff --git a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm index 1ab90c8978c..1ba458ee1d0 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackingElement.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackingElement.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackingElement.pm,v 1.158 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: PackingElement.pm,v 1.159 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -401,11 +401,12 @@ sub check_digest my ($self, $file, $state) = @_; return if $self->{link} or $self->{symlink}; if (!defined $self->{d}) { - $state->fatal($self->fullname, " does not have a signature"); + $state->log->fatal($self->fullname, + " does not have a signature"); } my $d = $self->compute_digest($file->{destdir}.$file->name); if (!$d->equals($self->{d})) { - $state->fatal("checksum for ", $self->fullname, + $state->log->fatal("checksum for ", $self->fullname, " does not match"); } if ($state->{very_verbose}) { @@ -1512,9 +1513,9 @@ sub run chmod 0755, $name; return if $state->system($name, $pkgname, @args) == 0; if ($state->{defines}->{scripts}) { - $state->warn($self->beautify, " script failed\n"); + $state->log->warn($self->beautify, " script failed\n"); } else { - $state->fatal($self->beautify." script failed"); + $state->log->fatal($self->beautify." script failed"); } } @@ -1555,7 +1556,7 @@ sub prepare while (<$src>) { next if m/^\+\-+\s*$/o; s/^[+-] //o; - $state->print($_); + $state->log($_); } } else { Warn "Can't open $fname: $!\n"; diff --git a/usr.sbin/pkg_add/OpenBSD/SharedItems.pm b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm index 6ece9d43e43..51e9234b0a3 100644 --- a/usr.sbin/pkg_add/OpenBSD/SharedItems.pm +++ b/usr.sbin/pkg_add/OpenBSD/SharedItems.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: SharedItems.pm,v 1.14 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: SharedItems.pm,v 1.15 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2004-2006 Marc Espie <espie@openbsd.org> # @@ -67,16 +67,16 @@ sub cleanup my $realname = $state->{destdir}.$d; if ($remaining->{dirs}->{$realname}) { for my $i (@{$h->{$d}}) { - $state->set_pkgname($i->{pkgname}); + $state->log->set_context($i->{pkgname}); $i->reload($state); } } else { for my $i (@{$h->{$d}}) { - $state->set_pkgname($i->{pkgname}); + $state->log->set_context($i->{pkgname}); $i->cleanup($state); } if (!rmdir $realname) { - $state->print("Error deleting directory $realname: $!\n") + $state->log("Error deleting directory $realname: $!\n") unless $state->{dirs_okay}->{$d}; } } @@ -90,8 +90,8 @@ sub cleanup if ($state->{extra}) { System(OpenBSD::Paths->userdel, $user); } else { - $state->set_pkgname($pkgname); - $state->print("You should also run /usr/sbin/userdel $user\n"); + $state->log->set_context($pkgname); + $state->log("You should also run /usr/sbin/userdel $user\n"); } $done++; } @@ -103,8 +103,8 @@ sub cleanup if ($state->{extra}) { System(OpenBSD::Paths->groupdel, $group); } else { - $state->set_pkgname($pkgname); - $state->print("You should also run /usr/sbin/groupdel $group\n"); + $state->log->set_context($pkgname); + $state->log("You should also run /usr/sbin/groupdel $group\n"); } $done++; } @@ -126,7 +126,7 @@ sub cleanup { my ($self, $state) = @_; my $fullname = $state->{destdir}.$self->fullname; - $state->print("You may wish to remove ", $fullname, " from man.conf\n"); + $state->log("You may wish to remove ", $fullname, " from man.conf\n"); for my $f (OpenBSD::Paths->man_cruft) { unlink("$fullname/$f"); } @@ -137,7 +137,7 @@ sub cleanup { my ($self, $state) = @_; my $fullname = $state->{destdir}.$self->fullname; - $state->print("You may wish to remove ", $fullname, " from your font path\n"); + $state->log("You may wish to remove ", $fullname, " from your font path\n"); for my $f (OpenBSD::Paths->font_cruft) { unlink("$fullname/$f"); } diff --git a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm index e204a0f7cfb..9b701a782ce 100644 --- a/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm +++ b/usr.sbin/pkg_add/OpenBSD/UpdateSet.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: UpdateSet.pm,v 1.16 2009/11/11 11:01:55 espie Exp $ +# $OpenBSD: UpdateSet.pm,v 1.17 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2007 Marc Espie <espie@openbsd.org> # @@ -45,57 +45,46 @@ sub cleanup OpenBSD::SharedItems::cleanup($self, $state); } -package OpenBSD::pkg_foo::State; +package OpenBSD::Log; use OpenBSD::Error; +our @ISA = qw(OpenBSD::Error); -sub new -{ - my $class = shift; - my $o = bless {}, $class; - $o->init(@_); - return $o; -} - -sub init +sub set_context { - my $self = shift; - $self->{l} = OpenBSD::Error->new; + &OpenBSD::Error::set_pkgname; } -sub log +sub dump { - my $self = shift; - return $self->{l}; + &OpenBSD::Error::delayed_output; } -sub set_pkgname -{ - my $self = shift; - $self->log->set_pkgname(@_); -} -sub print -{ - my $self = shift; - $self->log->print(@_); -} +package OpenBSD::pkg_foo::State; +use OpenBSD::Error; -sub warn +sub new { - my $self = shift; - $self->log->warn(@_); + my $class = shift; + my $o = bless {}, $class; + $o->init(@_); + return $o; } -sub fatal +sub init { my $self = shift; - $self->log->fatal(@_); + $self->{l} = OpenBSD::Log->new; } -sub delayed_output +sub log { my $self = shift; - $self->log->delayed_output(@_); + if (@_ == 0) { + return $self->{l}; + } else { + $self->{l}->print(@_); + } } sub system diff --git a/usr.sbin/pkg_add/OpenBSD/x509.pm b/usr.sbin/pkg_add/OpenBSD/x509.pm index 944f16aeb02..0a6ff1712e9 100644 --- a/usr.sbin/pkg_add/OpenBSD/x509.pm +++ b/usr.sbin/pkg_add/OpenBSD/x509.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: x509.pm,v 1.2 2009/10/14 11:06:41 espie Exp $ +# $OpenBSD: x509.pm,v 1.3 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -96,7 +96,7 @@ sub check_signature my ($plist, $state) = @_; my $sig = $plist->get('digital-signature'); if ($sig->{key} ne 'x509') { - $state->warn("Error: unknown signature style"); + $state->log->warn("Error: unknown signature style"); return 0; } my ($fh, $fname) = mkstemp("/tmp/pkgcontent.XXXXXXXXX"); @@ -108,7 +108,7 @@ sub check_signature if (system_quiet (OpenBSD::Paths->openssl, "smime", "-verify", "-binary", "-inform", "DEM", "-in", $fname2, "-content", $fname, "-CAfile", OpenBSD::Paths->pkgca, "-out", "/dev/null") != 0) { - $state->warn("Bad signature"); + $state->log->warn("Bad signature"); return 0; } if ($state->{verbose}) { diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add index 99beac08ba9..56021dc8896 100644 --- a/usr.sbin/pkg_add/pkg_add +++ b/usr.sbin/pkg_add/pkg_add @@ -1,7 +1,7 @@ #! /usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_add,v 1.375 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: pkg_add,v 1.376 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2003-2009 Marc Espie <espie@openbsd.org> # @@ -95,7 +95,7 @@ sub deptree_header sub set_name_from_handle { my ($state, $h) = @_; - $state->set_pkgname($h->pkgname); + $state->log->set_context($h->pkgname); } sub updater @@ -477,7 +477,7 @@ sub install_set } if ($handle->has_error) { $state->set_name_from_handle($handle); - $state->print("Can't install ", $handle->pkgname, ":", + $state->log("Can't install ", $handle->pkgname, ":", $handle->error_message, "\n"); $bad++; return (); @@ -810,7 +810,7 @@ if ($state->{packages_with_sig}) { if ($state->{beverbose}) { OpenBSD::Vstat::tally(); } -$state->delayed_output; +$state->log->dump; if (defined $state->{updatedepends} && %{$state->{updatedepends}}) { print "Forced updates, bogus dependencies for ", join(' ', sort(keys %{$state->{updatedepends}})), diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete index 91128464b22..04d44e0477d 100644 --- a/usr.sbin/pkg_add/pkg_delete +++ b/usr.sbin/pkg_add/pkg_delete @@ -1,6 +1,6 @@ #!/usr/bin/perl # ex:ts=8 sw=4: -# $OpenBSD: pkg_delete,v 1.116 2009/11/10 11:36:56 espie Exp $ +# $OpenBSD: pkg_delete,v 1.117 2009/11/11 11:13:16 espie Exp $ # # Copyright (c) 2003-2007 Marc Espie <espie@openbsd.org> # @@ -197,7 +197,7 @@ eval { print $opt_n ? "Pretending to delete " : "Deleting ", "$pkgname\n"; } - $state->set_pkgname($pkgname); + $state->log->set_context($pkgname); OpenBSD::Delete::delete_package($pkgname, $state); $done{$pkgname} = 1; $removed++; @@ -213,7 +213,7 @@ OpenBSD::PackingElement::Fontdir::finish_fontdirs($state); if ($state->{beverbose}) { OpenBSD::Vstat::tally(); } -$state->delayed_output; +$state->log->dump; rethrow $dielater; } catch { print STDERR "$0: $_\n"; |