| author | Raphaël Hertzog <hertzog@debian.org> | |
| Fri, 21 Oct 2011 14:21:56 +0000 (16:21 +0200) | ||
| committer | Raphaël Hertzog <hertzog@debian.org> | |
| Fri, 21 Oct 2011 14:37:02 +0000 (16:37 +0200) |
The lock is taken on debian/control as this is a file that we know to
always exist. Without this lock, it's possible that the file is updated
concurrently by two processes when parallel building is enabled (leading
to one of them failing unexpectedly).
Reported-by: James Vega <jamessan@debian.org>
always exist. Without this lock, it's possible that the file is updated
concurrently by two processes when parallel building is enabled (leading
to one of them failing unexpectedly).
Reported-by: James Vega <jamessan@debian.org>
| debian/changelog | patch | blob | history | |
| debian/control | patch | blob | history | |
| scripts/dpkg-distaddfile.pl | patch | blob | history | |
| scripts/dpkg-gencontrol.pl | patch | blob | history |
diff --git a/debian/changelog b/debian/changelog
--- a/debian/changelog
+++ b/debian/changelog
too. Closes: #595144
* Rewrite architecture.mk with explicit loops instead of duplicating many
similar lines. Based on a patch by Thorsten Glaser <tg@mirbsd.de>.
+ * Modify dpkg-gencontrol and dpkg-distaddfile to grab a write lock
+ on debian/control before updating debian/files to avoid simultaneous
+ updates. Closes: #642608
+ Add libfile-fcntllock-perl to dpkg-dev's Depends since we use this module
+ to handle the locking.
[ Jonathan Nieder ]
* Bump po4a version in Build-Depends to 0.41, since earlier versions do
diff --git a/debian/control b/debian/control
--- a/debian/control
+++ b/debian/control
Section: utils
Priority: optional
Architecture: all
-Depends: libdpkg-perl (= ${source:Version}), bzip2, xz-utils,
+Depends: libdpkg-perl (= ${source:Version}), libfile-fcntllock-perl, bzip2, xz-utils,
patch, make, binutils, base-files (>= 5.0.0), ${misc:Depends}
Recommends: gcc | c-compiler, build-essential, fakeroot, gnupg, gpgv, libalgorithm-merge-perl
Suggests: debian-keyring
use strict;
use warnings;
+use File::FcntlLock;
use POSIX;
use POSIX qw(:errno_h :signal_h);
use Dpkg;
($file =~ m/\s/ || $section =~ m/\s/ || $priority =~ m/\s/) &&
error(_g("filename, section and priority may contain no whitespace"));
+# Obtain a lock on debian/control to avoid simultaneous updates
+# of debian/files when parallel building is in use
+my $fs = File::FcntlLock->new(l_type => F_WRLCK);
+my $lockfh;
+sysopen($lockfh, "debian/control", O_WRONLY) ||
+ syserr(_g("cannot write %s"), "debian/control");
+$fs->lock($lockfh, F_SETLKW) ||
+ syserr(_("failed to get a write lock on %s"), "debian/control");
+
$fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
open(Y, "> $fileslistfile.new") || syserr(_g("open new files list file"));
if (open(X,"< $fileslistfile")) {
close(Y) || syserr(_g("close new files list file"));
rename("$fileslistfile.new", $fileslistfile) ||
syserr(_g("install new files list file"));
+
+# Release the lock
+close($lockfh) || syserr(_g("cannot close %s"), "debian/control");
use strict;
use warnings;
+use File::FcntlLock;
use POSIX;
use POSIX qw(:errno_h);
use Dpkg;
delete $fields->{$f};
}
+# Obtain a lock on debian/control to avoid simultaneous updates
+# of debian/files when parallel building is in use
+my $fs = File::FcntlLock->new(l_type => F_WRLCK);
+my $lockfh;
+sysopen($lockfh, "debian/control", O_WRONLY) ||
+ syserr(_g("cannot write %s"), "debian/control");
+$fs->lock($lockfh, F_SETLKW) ||
+ syserr(_("failed to get a write lock on %s"), "debian/control");
+
$fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/;
open(Y, ">", "$fileslistfile.new") || syserr(_g("open new files list file"));
binmode(Y);
close(Y) || syserr(_g("close new files list file"));
rename("$fileslistfile.new", $fileslistfile) || syserr(_g("install new files list file"));
+# Release the lock
+close($lockfh) || syserr(_g("cannot close %s"), "debian/control");
+
my $cf;
my $fh_output;
if (!$stdout) {
