On Mon, Feb 14, 2022 at 11:37:55AM +0100, Marc Espie wrote:
> - you don't need to call unlock_db. When the process dies, the fd dies with
> it, and the lock.
>
> - I've committed glue to PackageInfo.pm to make lock_db self-contained
> (it will pull BaseState in on an "as needed" basis, which also comes in
> handy for other locks prior to having a state)
>
> Index: fw_update.sh
> ===================================================================
> RCS file: /cvs/src/usr.sbin/fw_update/fw_update.sh,v
> retrieving revision 1.37
> diff -u -p -r1.37 fw_update.sh
> --- fw_update.sh 11 Feb 2022 00:46:58 -0000 1.37
> +++ fw_update.sh 14 Feb 2022 10:35:57 -0000
> @@ -206,13 +206,11 @@ lock_db() {
> perl <<'EOL' |&
> use v5.16;
> use warnings;
> - use OpenBSD::PackageInfo qw< lock_db unlock_db >;
> - use OpenBSD::BaseState;
> + use OpenBSD::PackageInfo qw< lock_db >;
>
> $|=1;
>
> - lock_db(0, 'OpenBSD::BaseState');
> - END { unlock_db }
> + lock_db(0);
> $SIG{TERM} = sub { exit };
>
> say $$;
>
>
Extra note: I generally steer away from END {} blocks in my code in most
cases. Those blocks obviously survive fork... so whenever you need perl
code on both sides, you are asking for trouble.
(that's the reason why the OpenBSD::Temp registers files to clean with
the associated pid. I got bitten by this).
None of the default pkg_* bother to call unlock_db at the end... that hook
is there specifically if you want to peek at the db, and release the lock
before the end, nothing more.