summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2013-12-25 14:20:48 +0000
committerespie <espie@openbsd.org>2013-12-25 14:20:48 +0000
commit875cde4bdb158b02636ae702050b9078d1199076 (patch)
treee06f42fe232d7f572c34d33a173e1515edba81d6
parentSupport .St -xsh4.2, the System Interfaces part of the original Single (diff)
downloadwireguard-openbsd-875cde4bdb158b02636ae702050b9078d1199076.tar.xz
wireguard-openbsd-875cde4bdb158b02636ae702050b9078d1199076.zip
a bit more scaffolding for running quirks. In particular, once quirks
have been loaded, complain loudly if something doesn't work. (and complain when quirks don't load in !verbose mode)
-rw-r--r--usr.sbin/pkg_add/OpenBSD/AddDelete.pm39
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgAdd.pm34
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Update.pm18
3 files changed, 58 insertions, 33 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm
index 23d79aa3773..91dc7b6b752 100644
--- a/usr.sbin/pkg_add/OpenBSD/AddDelete.pm
+++ b/usr.sbin/pkg_add/OpenBSD/AddDelete.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: AddDelete.pm,v 1.56 2013/12/23 16:50:29 espie Exp $
+# $OpenBSD: AddDelete.pm,v 1.57 2013/12/25 14:20:48 espie Exp $
#
# Copyright (c) 2007-2010 Marc Espie <espie@openbsd.org>
#
@@ -267,6 +267,34 @@ sub log
}
}
+sub run_quirks
+{
+ my ($state, $sub) = @_;
+
+ if (!exists $state->{quirks}) {
+ eval {
+ require OpenBSD::Quirks;
+ # interface version number.
+ $state->{quirks} = OpenBSD::Quirks->new(1);
+ };
+ if ($@) {
+ $state->errsay("Can't load quirk: #1", $@)
+ if $state->verbose >= 2;
+ # cache that this didn't work
+ $state->{quirks} = undef;
+ }
+ }
+
+ if (defined $state->{quirks}) {
+ eval {
+ &$sub($state->{quirks});
+ };
+ if ($@) {
+ $state->errsay("Bad quirk: #1", $@);
+ }
+ }
+}
+
sub vsystem
{
my $self = shift;
@@ -304,10 +332,11 @@ sub choose_location
if (@$list == 0) {
if (!$is_quirks) {
$state->errsay("Can't find #1", $name);
- eval {
- my $r = [$name];
- $state->quirks->filter_obsolete($r, $state);
- }
+ $state->run_quirks(
+ sub {
+ my $quirks = shift;
+ $quirks->filter_obsolete([$name], $state);
+ });
}
return undef;
} elsif (@$list == 1) {
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
index 6ff666a1ff2..449d486517b 100644
--- a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
@@ -1,7 +1,7 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: PkgAdd.pm,v 1.38 2013/12/23 15:40:24 espie Exp $
+# $OpenBSD: PkgAdd.pm,v 1.39 2013/12/25 14:20:48 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -202,13 +202,6 @@ OpenBSD::Auto::cache(tracker,
return OpenBSD::Tracker->new;
});
-sub quirks
-{
- my $state = shift;
-
- return $state->{quirks};
-}
-
package OpenBSD::ConflictCache;
our @ISA = (qw(OpenBSD::Cloner));
sub new
@@ -994,9 +987,11 @@ sub inform_user_of_problems
my $state = shift;
my @cantupdate = $state->tracker->cant_list;
if (@cantupdate > 0) {
- eval {
- $state->quirks->filter_obsolete(\@cantupdate, $state);
- };
+ $state->run_quirks(
+ sub {
+ my $quirks = shift;
+ $quirks->filter_obsolete(\@cantupdate, $state);
+ });
$state->say("Couldn't find updates for #1", join(', ', @cantupdate));
}
@@ -1026,13 +1021,8 @@ sub quirk_set
sub do_quirks
{
my ($self, $state) = @_;
-
- $self->process_set(quirk_set($state), $state);
- eval {
- require OpenBSD::Quirks;
- # interface version number.
- $state->{quirks} = OpenBSD::Quirks->new(1);
- };
+ my $set = quirk_set($state);
+ $self->process_set($set, $state);
}
@@ -1118,9 +1108,11 @@ sub tweak_list
{
my ($self, $state) = @_;
- eval {
- $state->quirks->tweak_list($state->{setlist}, $state);
- }
+ $state->run_quirks(
+ sub {
+ my $quirks = shift;
+ $quirks->tweak_list($state->{setlist}, $state);
+ });
}
sub main
diff --git a/usr.sbin/pkg_add/OpenBSD/Update.pm b/usr.sbin/pkg_add/OpenBSD/Update.pm
index 4300aa5f71d..3e69d1fb071 100644
--- a/usr.sbin/pkg_add/OpenBSD/Update.pm
+++ b/usr.sbin/pkg_add/OpenBSD/Update.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Update.pm,v 1.153 2012/10/13 10:28:22 jeremy Exp $
+# $OpenBSD: Update.pm,v 1.154 2013/12/25 14:20:48 espie Exp $
#
# Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org>
#
@@ -89,9 +89,11 @@ sub process_handle
}
my $base = 0;
- eval {
- $base = $state->quirks->is_base_system($h, $state);
- };
+ $state->run_quirks(
+ sub {
+ my $quirks = shift;
+ $base = $quirks->is_base_system($h, $state);
+ });
if ($base) {
$h->{update_found} = OpenBSD::Handle->system;
$set->{updates}++;
@@ -122,9 +124,11 @@ sub process_handle
}
push(@search, OpenBSD::Search::Stem->split($sname));
- eval {
- $state->quirks->tweak_search(\@search, $h, $state);
- };
+ $state->run_quirks(
+ sub {
+ my $quirks = shift;
+ $quirks->tweak_search(\@search, $h, $state);
+ });
my $oldfound = 0;
my @skipped_locs = ();