diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2022-02-14 10:34:37 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2022-02-14 10:34:37 +0000 |
commit | 55737b855cd9bf4179e9ed6e633cce2069bdb94b (patch) | |
tree | 9b7c1dc3bda382ec813ae939e956d73a0536dcee /usr.sbin | |
parent | f45445147c856b4dbadec29836b3f7e1d91b55bd (diff) |
make db locking self-contained
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/PackageInfo.pm | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm index cac8edd5a5d..2c67e648541 100644 --- a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm +++ b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: PackageInfo.pm,v 1.61 2020/01/28 11:25:44 espie Exp $ +# $OpenBSD: PackageInfo.pm,v 1.62 2022/02/14 10:34:36 espie Exp $ # # Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org> # @@ -191,15 +191,23 @@ sub lock_db($;$) { my ($shared, $state) = @_; my $mode = $shared ? LOCK_SH : LOCK_EX; + my $s = + sub { + if (!defined $state) { + require OpenBSD::BaseState; + return 'OpenBSD::BaseState'; + } else { + return $state; + } + }; open($dlock, '<', $pkg_db) or return; if (flock($dlock, $mode | LOCK_NB)) { return; } - $state->errprint("Package database already locked... awaiting release... ") - if defined $state; + &$s->errprint("Package database already locked... awaiting release... "); while (!flock($dlock, $mode)) { } - $state->errsay("done!") if defined $state; + &$s->errsay("done!"); return; } |