summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey C Honig <jeffrey.honig@windriver.com>2012-07-16 20:48:57 -0400
committerRichard Purdie <richard.purdie@linuxfoundation.org>2012-07-17 10:54:07 +0100
commit4b8f43aaa6e612d3233ed87ed82b3e1229a9c17d (patch)
treeae348899d7352ecd15598d849ea29627312534b5
parent05e5ec2be8c0cf291956b46885bd847bb1987a3b (diff)
downloadast2050-yocto-poky-4b8f43aaa6e612d3233ed87ed82b3e1229a9c17d.zip
ast2050-yocto-poky-4b8f43aaa6e612d3233ed87ed82b3e1229a9c17d.tar.gz
bitbake: siggen.py: Insure .siginfo files writes into shared sstate cache are atomic
Use tempfile.mkstemp to create a temporary file in the sstate dir and move it into place after closing. The previous code would fail in the chmod() if two users were running jobs that touched the same signature file. (Bitbake rev: ff11e9ac5eba2d957917664a7b91b1277d8ad548) Signed-off-by: Jeffrey C Honig <jeffrey.honig@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/siggen.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/bitbake/lib/bb/siggen.py b/bitbake/lib/bb/siggen.py
index edd98fc..02a4268 100644
--- a/bitbake/lib/bb/siggen.py
+++ b/bitbake/lib/bb/siggen.py
@@ -2,6 +2,7 @@ import hashlib
import logging
import os
import re
+import tempfile
import bb.data
logger = logging.getLogger('BitBake.SigGen')
@@ -236,10 +237,20 @@ class SignatureGeneratorBasic(SignatureGenerator):
if taint:
data['taint'] = taint
- with open(sigfile, "wb") as f:
- p = pickle.Pickler(f, -1)
- p.dump(data)
- os.chmod(sigfile, 0664)
+ fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.")
+ try:
+ with os.fdopen(fd, "wb") as stream:
+ p = pickle.dump(data, stream, -1)
+ stream.flush()
+ os.fsync(fd)
+ os.chmod(tmpfile, 0664)
+ os.rename(tmpfile, sigfile)
+ except (OSError, IOError), err:
+ try:
+ os.unlink(tmpfile)
+ except OSError:
+ pass
+ raise err
def dump_sigs(self, dataCache):
for fn in self.taskdeps:
OpenPOWER on IntegriCloud