summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_add/OpenBSD
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2019-07-24 18:05:26 +0000
committerespie <espie@openbsd.org>2019-07-24 18:05:26 +0000
commit912731942ee4c6e6d3e26e936b9951c1d0a4d741 (patch)
tree0d4b89cac2949f29462d67f5c9b9eace0c35b3b0 /usr.sbin/pkg_add/OpenBSD
parentReturn fd of -1 if take_charge() detects 'quit' being set to (diff)
downloadwireguard-openbsd-912731942ee4c6e6d3e26e936b9951c1d0a4d741.tar.xz
wireguard-openbsd-912731942ee4c6e6d3e26e936b9951c1d0a4d741.zip
GC old catchall
add a better framework for signal handling (not used yet)
Diffstat (limited to 'usr.sbin/pkg_add/OpenBSD')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Delete.pm4
-rw-r--r--usr.sbin/pkg_add/OpenBSD/Error.pm62
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PkgAdd.pm8
-rw-r--r--usr.sbin/pkg_add/OpenBSD/State.pm4
4 files changed, 56 insertions, 22 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/Delete.pm b/usr.sbin/pkg_add/OpenBSD/Delete.pm
index df82de71ad0..b7748d3e506 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.159 2019/07/10 11:56:01 espie Exp $
+# $OpenBSD: Delete.pm,v 1.160 2019/07/24 18:05:26 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -121,7 +121,7 @@ sub unregister_dependencies
local $@;
try {
OpenBSD::RequiredBy->new($name)->delete($pkgname);
- } catchall {
+ } catch {
$state->errsay($_);
};
}
diff --git a/usr.sbin/pkg_add/OpenBSD/Error.pm b/usr.sbin/pkg_add/OpenBSD/Error.pm
index a44a9ceb982..7905d763cf7 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.39 2019/07/24 09:03:12 espie Exp $
+# $OpenBSD: Error.pm,v 1.40 2019/07/24 18:05:26 espie Exp $
#
# Copyright (c) 2004-2010 Marc Espie <espie@openbsd.org>
#
@@ -32,14 +32,50 @@ sub cache(*&)
*{$callpkg."::$sym"} = $actual;
}
-# a bunch of other modules create persistent state that must be cleaned up
-# on exit (temporary files, network connections to abort properly...)
-# END blocks would do that (but see below...) but sig handling bypasses that,
-# so we MUST install SIG handlers.
+package OpenBSD::SigHandler;
+
+# instead of "local" sighandlers, let's do objects that revert
+# to their former state afterwards
+sub new
+{
+ my $class = shift;
+ # keep previous state
+ bless {}, $class;
+}
+
+
+sub DESTROY
+{
+ my $self = shift;
+ while (my ($s, $v) = each %$self) {
+ $SIG{$s} = $v;
+ }
+}
+
+sub set
+{
+ my $self = shift;
+ my $v = pop;
+ for my $s (@_) {
+ $self->{$s} = $SIG{$s};
+ $SIG{$s} = $v;
+ }
+ return $self;
+}
+
+sub intercept
+{
+ my $self = shift;
+ my $v = pop;
+ return $self->set(@_,
+ sub {
+ my $sig = shift;
+ &$v($sig);
+ $SIG{$sig} = $self->{$sig};
+ kill -$sig, $$;
+ });
+}
-# note that END will be run for *each* process, so beware!
-# (temp files are registered per pid, for instance, so they only
-# get cleaned when the proper pid is used)
package OpenBSD::Handler;
# a bunch of other modules create persistent state that must be cleaned up
@@ -109,10 +145,13 @@ __PACKAGE__->reset;
package OpenBSD::Error;
require Exporter;
our @ISA=qw(Exporter);
-our @EXPORT=qw(try throw catch catchall rethrow);
+our @EXPORT=qw(try throw catch rethrow INTetc);
+
our ($FileName, $Line, $FullMessage);
+our @INTetc = (qw(INT QUIT HUP TERM));
+
use Carp;
sub dienow
{
@@ -155,11 +194,6 @@ sub catch(&)
bless $_[0], "OpenBSD::Error::catch";
}
-sub catchall(&)
-{
- bless $_[0], "OpenBSD::Error::catch";
-}
-
sub rmtree
{
my $class = shift;
diff --git a/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm b/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm
index e9057a24b1f..759c8f1e923 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.113 2019/06/09 18:58:06 espie Exp $
+# $OpenBSD: PkgAdd.pm,v 1.114 2019/07/24 18:05:26 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -704,7 +704,7 @@ sub delete_old_packages
require OpenBSD::Delete;
try {
OpenBSD::Delete::delete_handle($o, $state);
- } catchall {
+ } catch {
$state->errsay($_);
$state->fatal(partial_install(
"Deinstallation of $oldname failed",
@@ -787,7 +787,7 @@ sub really_add
try {
OpenBSD::Add::perform_extraction($handle, $state);
- } catchall {
+ } catch {
unless ($state->{interrupted}) {
$state->errsay($_);
$errors++;
@@ -816,7 +816,7 @@ sub really_add
try {
OpenBSD::Add::perform_installation($handle, $state);
- } catchall {
+ } catch {
unless ($state->{interrupted}) {
$state->errsay($_);
$errors++;
diff --git a/usr.sbin/pkg_add/OpenBSD/State.pm b/usr.sbin/pkg_add/OpenBSD/State.pm
index 73987dc4ec5..b89c2f4adf2 100644
--- a/usr.sbin/pkg_add/OpenBSD/State.pm
+++ b/usr.sbin/pkg_add/OpenBSD/State.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: State.pm,v 1.61 2019/07/21 14:05:30 espie Exp $
+# $OpenBSD: State.pm,v 1.62 2019/07/24 18:05:26 espie Exp $
#
# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
#
@@ -291,7 +291,7 @@ sub do_options
try {
&$sub;
- } catchall {
+ } catch {
$state->usage("#1", $_);
};
}