All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] siggen.py: Insure .siginfo files writes into shared sstate cache are atomic
@ 2012-07-17  0:48 Jeffrey C Honig
  2012-07-17  9:53 ` Richard Purdie
  0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey C Honig @ 2012-07-17  0:48 UTC (permalink / raw)
  To: bitbake-devel

   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.

Signed-off-by: Jeffrey C Honig <jeffrey.honig@windriver.com>
---
 lib/bb/siggen.py |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/bb/siggen.py b/lib/bb/siggen.py
index edd98fc..02a4268 100644
--- a/lib/bb/siggen.py
+++ b/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:
-- 
1.7.5.4




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] siggen.py: Insure .siginfo files writes into shared sstate cache are atomic
  2012-07-17  0:48 [PATCH] siggen.py: Insure .siginfo files writes into shared sstate cache are atomic Jeffrey C Honig
@ 2012-07-17  9:53 ` Richard Purdie
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Purdie @ 2012-07-17  9:53 UTC (permalink / raw)
  To: Jeffrey C Honig; +Cc: bitbake-devel

On Mon, 2012-07-16 at 20:48 -0400, Jeffrey C Honig wrote:
> 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.
> 
> Signed-off-by: Jeffrey C Honig <jeffrey.honig@windriver.com>
> ---
>  lib/bb/siggen.py |   19 +++++++++++++++----
>  1 files changed, 15 insertions(+), 4 deletions(-)

Merged to master, thanks.

Richard




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] siggen.py: Insure .siginfo files writes into shared sstate cache are atomic
@ 2012-07-17  0:27 Jeffrey C Honig
  0 siblings, 0 replies; 3+ messages in thread
From: Jeffrey C Honig @ 2012-07-17  0:27 UTC (permalink / raw)
  To: bitbake-devel

   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.

Signed-off-by: Jeffrey C Honig <jeffrey.honig@windriver.com>
---
 lib/bb/siggen.py |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lib/bb/siggen.py b/lib/bb/siggen.py
index edd98fc..02a4268 100644
--- a/lib/bb/siggen.py
+++ b/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:
-- 
1.7.5.4




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-17 10:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-17  0:48 [PATCH] siggen.py: Insure .siginfo files writes into shared sstate cache are atomic Jeffrey C Honig
2012-07-17  9:53 ` Richard Purdie
  -- strict thread matches above, loose matches on Subject: below --
2012-07-17  0:27 Jeffrey C Honig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.