summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2005-01-14 02:25:13 +0000
committerMarc Espie <espie@cvs.openbsd.org>2005-01-14 02:25:13 +0000
commit40e9a6cdf34436562481587eb43511900cf73931 (patch)
treecd112ed1823e8268abb2ee8515de820c890188e6
parent1ddaf5f286b2ad047bc37bb05b9b860c1850f714 (diff)
`big lock' model: lock the whole db for reading/writing.
design checked with millert@, relying on process termination for unlock at his suggestion. Perf optimization: don't try to reinstall installed packages in kitchensink mode if !-r.
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageInfo.pm28
-rw-r--r--usr.sbin/pkg_add/pkg_add6
-rw-r--r--usr.sbin/pkg_add/pkg_delete3
-rw-r--r--usr.sbin/pkg_add/pkg_info3
4 files changed, 36 insertions, 4 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm b/usr.sbin/pkg_add/OpenBSD/PackageInfo.pm
index e5db40c7500..49e7072dedd 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.15 2004/12/27 22:16:13 espie Exp $
+# $OpenBSD: PackageInfo.pm,v 1.16 2005/01/14 02:25:12 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -20,6 +20,7 @@ use warnings;
package OpenBSD::PackageInfo;
our @ISA=qw(Exporter);
our @EXPORT=qw(installed_packages installed_info installed_name info_names is_info_name
+ lock_db unlock_db
add_installed delete_installed is_installed borked_package CONTENTS COMMENT DESC INSTALL DEINSTALL REQUIRE
REQUIRED_BY REQUIRING DISPLAY UNDISPLAY MTREE_DIRS);
@@ -37,6 +38,7 @@ use constant {
UNDISPLAY => '+UNDISPLAY',
MTREE_DIRS => '+MTREE_DIRS' };
+use Fcntl qw/:flock/;
my $pkg_db = $ENV{"PKG_DBDIR"} || '/var/db/pkg';
our $list;
@@ -166,4 +168,28 @@ sub is_info_name($)
return $info{$name};
}
+my $dlock;
+
+sub lock_db($)
+{
+ my $shared = shift;
+ my $mode = $shared ? LOCK_SH : LOCK_EX;
+ open($dlock, '<', $pkg_db) or return;
+ if (flock($dlock, $mode | LOCK_NB)) {
+ return;
+ }
+ print "Package database already locked... awaiting release\n";
+ while (!flock($dlock, $mode)) {
+ }
+ return;
+}
+
+sub unlock_db()
+{
+ if (defined $dlock) {
+ flock($dlock, LOCK_UN);
+ close($dlock);
+ }
+}
+
1;
diff --git a/usr.sbin/pkg_add/pkg_add b/usr.sbin/pkg_add/pkg_add
index b710792a580..462e3ef59d8 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.166 2005/01/13 00:29:37 espie Exp $
+# $OpenBSD: pkg_add,v 1.167 2005/01/14 02:25:12 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -773,6 +773,7 @@ $state->{very_verbose} = $opt_v >= 2;
$state->{verbose} = $opt_v;
$state->{beverbose} = $opt_n || ($opt_v >= 2);
+lock_db($opt_n);
if (!$opt_x && !$state->{beverbose}) {
OpenBSD::ProgressMeter::enable();
}
@@ -788,6 +789,9 @@ if ($< && !$forced{nonroot}) {
my @todo = (@ARGV);
if (defined $state->{forced}->{kitchensink}) {
reorder(\@todo);
+ if (!$opt_r) {
+ @todo = grep {s/\.tgz$//; !is_installed($_);} @todo;
+ }
print "Adding in order:\n", (map { "\t$_\n" } @todo), "\n";
}
diff --git a/usr.sbin/pkg_add/pkg_delete b/usr.sbin/pkg_add/pkg_delete
index 6483b0d0d76..977b16b1378 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.85 2005/01/03 01:02:45 espie Exp $
+# $OpenBSD: pkg_delete,v 1.86 2005/01/14 02:25:12 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -95,6 +95,7 @@ if ($opt_B eq '') {
$ENV{'PKG_DELETE_EXTRA'} = $state->{extra} ? "Yes" : "No";
+lock_db($opt_n);
if (!$opt_x && !$state->{beverbose}) {
OpenBSD::ProgressMeter::enable();
}
diff --git a/usr.sbin/pkg_add/pkg_info b/usr.sbin/pkg_add/pkg_info
index 84defa9ced7..3ca83cb2f60 100644
--- a/usr.sbin/pkg_add/pkg_info
+++ b/usr.sbin/pkg_add/pkg_info
@@ -1,6 +1,6 @@
#! /usr/bin/perl
# ex:ts=8 sw=4:
-# $OpenBSD: pkg_info,v 1.26 2004/12/22 12:56:25 espie Exp $
+# $OpenBSD: pkg_info,v 1.27 2005/01/14 02:25:12 espie Exp $
#
# Copyright (c) 2003-2004 Marc Espie <espie@openbsd.org>
#
@@ -247,6 +247,7 @@ sub print_info
set_usage('pkg_info [-cDdfIiKkLMpqRrsUv] [-E fname] [-e pkgname] [-l str] pkgname...', 'pkg_info [-Aa flags]');
+lock_db(1);
try {
getopts('cDdfhIikKLmpqRrsvhe:E:MU:l:aA',
{'e' =>