[type/__debconf_set_selections] Synchronise objects

Works around locking error:

	debconf: DbDriver "config": /var/cache/debconf/config.dat is locked by another process: Resource temporarily unavailable
This commit is contained in:
Dennis Camera 2021-04-27 19:41:10 +02:00
parent 9cf19388ab
commit a42ebc7a78
2 changed files with 19 additions and 1 deletions

View file

@ -41,10 +41,15 @@ test -s "${linesfile}" || {
exit 0 exit 0
} }
# assert __type_explorer is set (because it is used by the Perl script)
: "${__type_explorer:?}"
/usr/bin/perl -- - "${linesfile}" <<'EOF' /usr/bin/perl -- - "${linesfile}" <<'EOF'
use strict; use strict;
use warnings "all"; use warnings "all";
use Fcntl qw(:DEFAULT :flock);
use Debconf::Db; use Debconf::Db;
use Debconf::Question; use Debconf::Question;
@ -78,7 +83,20 @@ sub state {
} }
} }
Debconf::Db->load(readonly => 'true');
# Load Debconf DB but manually lock on the state explorer script,
# because Debconf aborts immediately if executed concurrently.
# This is not really an ideal solution because the Debconf DB could be locked by
# another process (e.g. apt-get), but no way to achieve this could be found.
# If you know how to, please provide a patch.
my $lockfile = "%ENV{'__type_explorer'}/state";
if (open my $lock_fh, '+<', $lockfile) {
flock $lock_fh, LOCK_EX or die "Cannot lock $lockfile";
}
{
Debconf::Db->load(readonly => 'true');
}
while (<>) { while (<>) {
# Read and process lines (taken from debconf-set-selections) # Read and process lines (taken from debconf-set-selections)