diff options
author | Jeffrey C Honig <jeffrey.honig@windriver.com> | 2012-07-16 20:48:57 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-07-17 10:54:07 +0100 |
commit | 4b8f43aaa6e612d3233ed87ed82b3e1229a9c17d (patch) | |
tree | ae348899d7352ecd15598d849ea29627312534b5 /bitbake | |
parent | 05e5ec2be8c0cf291956b46885bd847bb1987a3b (diff) | |
download | 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>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/siggen.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/bitbake/lib/bb/siggen.py b/bitbake/lib/bb/siggen.py index edd98fcfc0..02a426864f 100644 --- a/bitbake/lib/bb/siggen.py +++ b/bitbake/lib/bb/siggen.py | |||
@@ -2,6 +2,7 @@ import hashlib | |||
2 | import logging | 2 | import logging |
3 | import os | 3 | import os |
4 | import re | 4 | import re |
5 | import tempfile | ||
5 | import bb.data | 6 | import bb.data |
6 | 7 | ||
7 | logger = logging.getLogger('BitBake.SigGen') | 8 | logger = logging.getLogger('BitBake.SigGen') |
@@ -236,10 +237,20 @@ class SignatureGeneratorBasic(SignatureGenerator): | |||
236 | if taint: | 237 | if taint: |
237 | data['taint'] = taint | 238 | data['taint'] = taint |
238 | 239 | ||
239 | with open(sigfile, "wb") as f: | 240 | fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.") |
240 | p = pickle.Pickler(f, -1) | 241 | try: |
241 | p.dump(data) | 242 | with os.fdopen(fd, "wb") as stream: |
242 | os.chmod(sigfile, 0664) | 243 | p = pickle.dump(data, stream, -1) |
244 | stream.flush() | ||
245 | os.fsync(fd) | ||
246 | os.chmod(tmpfile, 0664) | ||
247 | os.rename(tmpfile, sigfile) | ||
248 | except (OSError, IOError), err: | ||
249 | try: | ||
250 | os.unlink(tmpfile) | ||
251 | except OSError: | ||
252 | pass | ||
253 | raise err | ||
243 | 254 | ||
244 | def dump_sigs(self, dataCache): | 255 | def dump_sigs(self, dataCache): |
245 | for fn in self.taskdeps: | 256 | for fn in self.taskdeps: |