summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorAndrew Fresh <afresh1@cvs.openbsd.org>2022-02-11 00:46:59 +0000
committerAndrew Fresh <afresh1@cvs.openbsd.org>2022-02-11 00:46:59 +0000
commit4c2d1ce55e734264877363eb16eea8b18350e1b9 (patch)
tree27242fc9a8045efd63b447ef35280ae98e836922 /usr.sbin
parent1b0b1afe0e697438f326d700d8bc19cc0af4eb1e (diff)
Lock the pkg db while running
At least when not running in the installer. Suggestions from espie@ Works for me sthen@ fine deraadt@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/fw_update/fw_update.sh36
1 files changed, 35 insertions, 1 deletions
diff --git a/usr.sbin/fw_update/fw_update.sh b/usr.sbin/fw_update/fw_update.sh
index 45fdf337997..d8779488b9a 100644
--- a/usr.sbin/fw_update/fw_update.sh
+++ b/usr.sbin/fw_update/fw_update.sh
@@ -1,5 +1,5 @@
#!/bin/ksh
-# $OpenBSD: fw_update.sh,v 1.36 2022/02/10 00:29:32 afresh1 Exp $
+# $OpenBSD: fw_update.sh,v 1.37 2022/02/11 00:46:58 afresh1 Exp $
#
# Copyright (c) 2021 Andrew Hewus Fresh <afresh1@openbsd.org>
#
@@ -42,11 +42,13 @@ INSTALL=true
LOCALSRC=
unset FTPPID
+unset LOCKPID
unset FWPKGTMP
REMOVE_LOCALSRC=false
cleanup() {
set +o errexit # ignore errors from killing ftp
[ "${FTPPID:-}" ] && kill -TERM -"$FTPPID" 2>/dev/null
+ [ "${LOCKPID:-}" ] && kill -TERM -"$LOCKPID" 2>/dev/null
[ "${FWPKGTMP:-}" ] && rm -rf "$FWPKGTMP"
"$REMOVE_LOCALSRC" && rm -rf "$LOCALSRC"
[ -e "${CFILE}" ] && [ ! -s "$CFILE" ] && rm -f "$CFILE"
@@ -194,6 +196,35 @@ firmware_devicename() {
echo "$_d"
}
+lock_db() {
+ [ "${LOCKPID:-}" ] && return 0
+
+ # The installer doesn't have perl, so we can't lock there
+ [ -e /usr/bin/perl ] || return 0
+
+ set -o monitor
+ perl <<'EOL' |&
+ use v5.16;
+ use warnings;
+ use OpenBSD::PackageInfo qw< lock_db unlock_db >;
+ use OpenBSD::BaseState;
+
+ $|=1;
+
+ lock_db(0, 'OpenBSD::BaseState');
+ END { unlock_db }
+ $SIG{TERM} = sub { exit };
+
+ say $$;
+ sleep;
+EOL
+ set +o monitor
+
+ read -rp LOCKPID
+
+ return 0
+}
+
installed_firmware() {
local _pre="$1" _match="$2" _post="$3" _firmware _fw
set -sA _firmware -- $(
@@ -401,6 +432,7 @@ set -sA devices -- "$@"
if "$DELETE"; then
[ "$OPT_F" ] && echo "Cannot use -F and -d" >&2 && usage
+ lock_db
# Show the "Uninstall" message when just deleting not upgrading
((VERBOSE)) && VERBOSE=3
@@ -464,6 +496,8 @@ fi
[ "${devices[*]:-}" ] || exit
+lock_db
+
added=''
updated=''
kept=''