summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2022-02-15 07:35:36 +0000
committerMarc Espie <espie@cvs.openbsd.org>2022-02-15 07:35:36 +0000
commit6b4ce82af2839ab6806abc7b5379f202bcd87693 (patch)
treeee045d598dd4c06130a95a3d0d17a3d7b9fd2642
parent9ab4308bf2abe93f12c87bbe0e2d7b79dacee490 (diff)
simplify code based on afresh1@'s remark: indeed I always need to
have a state once I'm past the initial locking
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm19
1 files changed, 7 insertions, 12 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index 2c67e648541..865deb4b95e 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.62 2022/02/14 10:34:36 espie Exp $
+# $OpenBSD: PackageInfo.pm,v 1.63 2022/02/15 07:35:35 espie Exp $
#
# Copyright (c) 2003-2014 Marc Espie <espie@openbsd.org>
#
@@ -191,23 +191,18 @@ 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;
}
- &$s->errprint("Package database already locked... awaiting release... ");
+ if (!defined $state) {
+ require OpenBSD::BaseState;
+ $state = 'OpenBSD::BaseState';
+ }
+ $state->errprint("Package database already locked... awaiting release... ");
while (!flock($dlock, $mode)) {
}
- &$s->errsay("done!");
+ $state->errsay("done!");
return;
}