[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

ossy at webkit.org ossy at webkit.org
Wed Dec 22 15:38:35 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit e0703ea242b85070382f2794484c995e2ac4c8f1
Author: ossy at webkit.org <ossy at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Nov 9 21:13:56 2010 +0000

    [NRWT] Make http locking similar to perl implementation
    https://bugs.webkit.org/show_bug.cgi?id=49187
    
    Patch by Gabor Rapcsanyi <rgabor at inf.u-szeged.hu> on 2010-11-09
    Reviewed by Tony Chang.
    
    * Scripts/webkitpy/common/system/file_lock.py: Added.
    * Scripts/webkitpy/common/system/file_lock_unittest.py: Added.
    * Scripts/webkitpy/layout_tests/port/http_lock.py:
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71672 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 3f43574..404f071 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,14 @@
+2010-11-09  Gabor Rapcsanyi  <rgabor at inf.u-szeged.hu>
+
+        Reviewed by Tony Chang.
+
+        [NRWT] Make http locking similar to perl implementation
+        https://bugs.webkit.org/show_bug.cgi?id=49187
+
+        * Scripts/webkitpy/common/system/file_lock.py: Added.
+        * Scripts/webkitpy/common/system/file_lock_unittest.py: Added.
+        * Scripts/webkitpy/layout_tests/port/http_lock.py:
+
 2010-11-09  James Kozianski  <koz at chromium.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebKitTools/Scripts/webkitpy/common/system/file_lock.py b/WebKitTools/Scripts/webkitpy/common/system/file_lock.py
new file mode 100644
index 0000000..09d03b8
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/common/system/file_lock.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+# Copyright (C) 2010 Gabor Rapcsanyi (rgabor at inf.u-szeged.hu), University of Szeged
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""This class helps to lock files exclusively across processes."""
+
+import os
+import sys
+
+
+class FileLock(object):
+
+    def __init__(self, lock_file_path):
+        self._lock_file_path = lock_file_path
+        self._lock_file_descriptor = None
+
+    def acquire_lock(self):
+        self._lock_file_descriptor = os.open(self._lock_file_path, os.O_CREAT)
+        if sys.platform in ('darwin', 'linux2', 'cygwin'):
+            import fcntl
+            lock_flags = fcntl.LOCK_EX | fcntl.LOCK_NB
+            fcntl.flock(self._lock_file_descriptor, lock_flags)
+        elif sys.platform == 'win32':
+            import msvcrt
+            lock_flags = msvcrt.LK_NBLCK
+            msvcrt.locking(self._lock_file_descriptor, lock_flags, 32)
+
+    def release_lock(self):
+        if self._lock_file_descriptor:
+            os.close(self._lock_file_descriptor)
+            os.unlink(self._lock_file_path)
diff --git a/WebKitTools/Scripts/webkitpy/common/system/file_lock_unittest.py b/WebKitTools/Scripts/webkitpy/common/system/file_lock_unittest.py
new file mode 100644
index 0000000..8fb8a82
--- /dev/null
+++ b/WebKitTools/Scripts/webkitpy/common/system/file_lock_unittest.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+# Copyright (C) 2010 Gabor Rapcsanyi (rgabor at inf.u-szeged.hu), University of Szeged
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import os
+import tempfile
+import unittest
+
+from webkitpy.common.system.file_lock import FileLock
+
+
+class FileLockTest(unittest.TestCase):
+
+    def setUp(self):
+        self._lock_name = "TestWebKit" + str(os.getpid()) + ".lock"
+        self._lock_path = os.path.join(tempfile.gettempdir(), self._lock_name)
+        self._file_lock = FileLock(self._lock_path)
+
+    def tearDown(self):
+        if os.path.exists(self._lock_path):
+            os.unlink(self._lock_path)
+
+    def test_lock_lifecycle(self):
+        # Create the lock.
+        self._file_lock.acquire_lock()
+        self.assertTrue(os.path.exists(self._lock_path))
+
+        # Try to lock again.
+        self.assertRaises((OSError, IOError), self._file_lock.acquire_lock)
+
+        # Release the lock.
+        self._file_lock.release_lock()
+        self.assertFalse(os.path.exists(self._lock_path))
+
+    def test_stuck_lock(self):
+        open(self._lock_path, 'w').close()
+        self._file_lock.acquire_lock()
+        self._file_lock.release_lock()
diff --git a/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py b/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py
index d65801d..41d56b4 100644
--- a/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py
+++ b/WebKitTools/Scripts/webkitpy/layout_tests/port/http_lock.py
@@ -36,6 +36,7 @@ import tempfile
 import time
 
 from webkitpy.common.system.executive import Executive
+from webkitpy.common.system.file_lock import FileLock
 
 
 _log = logging.getLogger("webkitpy.layout_tests.port.http_lock")
@@ -52,6 +53,7 @@ class HttpLock(object):
         self._lock_file_path_prefix = os.path.join(self._lock_path,
                                                    self._lock_file_prefix)
         self._guard_lock_file = os.path.join(self._lock_path, guard_lock)
+        self._guard_lock = FileLock(self._guard_lock_file)
         self._process_lock_file_name = ""
         self._executive = Executive()
         # maximum wait time for the lock creation
@@ -95,7 +97,7 @@ class HttpLock(object):
                 _log.debug("Removing stuck lock file: %s" % lock_list[0])
                 os.unlink(lock_list[0])
                 return
-        except IOError, OSError:
+        except (IOError, OSError):
             return
         return int(current_pid)
 
@@ -110,17 +112,16 @@ class HttpLock(object):
         start_time = time.time()
         while(True):
             try:
-                sequential_guard_lock = os.open(self._guard_lock_file, os.O_CREAT | os.O_EXCL)
+                self._guard_lock.acquire_lock()
                 self._process_lock_file_name = (self._lock_file_path_prefix +
                                                 str(self._next_lock_number()))
                 lock_file = open(self._process_lock_file_name, 'w')
                 _log.debug("Creating lock file: %s" % self._process_lock_file_name)
                 lock_file.write(str(os.getpid()))
                 lock_file.close()
-                os.close(sequential_guard_lock)
-                os.unlink(self._guard_lock_file)
+                self._guard_lock.release_lock()
                 return True
-            except OSError:
+            except (IOError, OSError):
                 if time.time() - start_time > self._guard_lock_max_wait:
                     _log.debug("Lock does not created: %s" % str(sys.exc_info()))
                     return False

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list