Title: [151825] trunk/Source
Revision
151825
Author
[email protected]
Date
2013-06-20 23:02:58 -0700 (Thu, 20 Jun 2013)

Log Message

[WK2] Looping for EINTR on close() is incorrect for Linux, at least
https://bugs.webkit.org/show_bug.cgi?id=117266

Patch by Sergio Correia <[email protected]> on 2013-06-20
Reviewed by Darin Adler.

Source/WebKit2:

Call closeWithRetry() to work around a difference in how the retry needs to
be done on Linux.

* Platform/CoreIPC/unix/AttachmentUnix.cpp:
(CoreIPC::Attachment::dispose):
* Platform/CoreIPC/unix/ConnectionUnix.cpp:
(CoreIPC::Connection::platformInvalidate):
* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::Handle::~Handle):
(WebKit::SharedMemory::create):
(WebKit::SharedMemory::~SharedMemory):
(WebKit::SharedMemory::createHandle):
* PluginProcess/PluginProcess.cpp:
(WebKit::PluginProcess::createWebProcessConnection):
* SharedWorkerProcess/SharedWorkerProcess.cpp:
(WebKit::SharedWorkerProcess::createWebProcessConnection):
* UIProcess/Launcher/qt/ProcessLauncherQt.cpp:
(WebKit::ProcessLauncher::launchProcess): All these places had
``close-followed-by-EINTR-handling'' replaced with the new closeWithRetry()
function added in this commit.

Source/WTF:

Added file UniStdExtras with a closeWithRetry() function that works around
the EINTR behavior on Linux during a close() call: it closes the descriptor
unconditionally even when the call is interrupted.

* wtf/UniStdExtras.h: Added.
(WTF::closeWithRetry): Wrapper around POSIX close() that handles EINTR
correctly.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (151824 => 151825)


--- trunk/Source/WTF/ChangeLog	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WTF/ChangeLog	2013-06-21 06:02:58 UTC (rev 151825)
@@ -1,3 +1,18 @@
+2013-06-20  Sergio Correia  <[email protected]>
+
+        [WK2] Looping for EINTR on close() is incorrect for Linux, at least
+        https://bugs.webkit.org/show_bug.cgi?id=117266
+
+        Reviewed by Darin Adler.
+
+        Added file UniStdExtras with a closeWithRetry() function that works around
+        the EINTR behavior on Linux during a close() call: it closes the descriptor
+        unconditionally even when the call is interrupted.
+
+        * wtf/UniStdExtras.h: Added.
+        (WTF::closeWithRetry): Wrapper around POSIX close() that handles EINTR
+        correctly.
+
 2013-06-20  Mark Lam  <[email protected]>
 
         Refine the StackBounds computation for Windows.

Added: trunk/Source/WTF/wtf/UniStdExtras.h (0 => 151825)


--- trunk/Source/WTF/wtf/UniStdExtras.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/UniStdExtras.h	2013-06-21 06:02:58 UTC (rev 151825)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * 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 THE COPYRIGHT HOLDERS ``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 THE COPYRIGHT HOLDERS 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.
+ */
+
+#ifndef UniStdExtras_h
+#define UniStdExtras_h
+
+#include <errno.h>
+#include <unistd.h>
+
+namespace WTF {
+
+inline int closeWithRetry(int fileDescriptor)
+{
+    int ret;
+#if OS(LINUX)
+    // Workaround for the Linux behavior of closing the descriptor
+    // unconditionally, even if the close() call is interrupted.
+    // See https://bugs.webkit.org/show_bug.cgi?id=117266 for more
+    // details.
+    if ((ret = close(fileDescriptor)) == -1 && errno == EINTR)
+        return 0;
+#else
+    while ((ret = close(fileDescriptor)) == -1 && errno == EINTR) { }
+#endif
+    return ret;
+}
+
+} // namespace WTF
+
+using WTF::closeWithRetry;
+
+#endif // UniStdExtras_h

Modified: trunk/Source/WebKit2/ChangeLog (151824 => 151825)


--- trunk/Source/WebKit2/ChangeLog	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WebKit2/ChangeLog	2013-06-21 06:02:58 UTC (rev 151825)
@@ -1,3 +1,31 @@
+2013-06-20  Sergio Correia  <[email protected]>
+
+        [WK2] Looping for EINTR on close() is incorrect for Linux, at least
+        https://bugs.webkit.org/show_bug.cgi?id=117266
+
+        Reviewed by Darin Adler.
+
+        Call closeWithRetry() to work around a difference in how the retry needs to
+        be done on Linux.
+
+        * Platform/CoreIPC/unix/AttachmentUnix.cpp:
+        (CoreIPC::Attachment::dispose):
+        * Platform/CoreIPC/unix/ConnectionUnix.cpp:
+        (CoreIPC::Connection::platformInvalidate):
+        * Platform/unix/SharedMemoryUnix.cpp:
+        (WebKit::SharedMemory::Handle::~Handle):
+        (WebKit::SharedMemory::create):
+        (WebKit::SharedMemory::~SharedMemory):
+        (WebKit::SharedMemory::createHandle):
+        * PluginProcess/PluginProcess.cpp:
+        (WebKit::PluginProcess::createWebProcessConnection):
+        * SharedWorkerProcess/SharedWorkerProcess.cpp:
+        (WebKit::SharedWorkerProcess::createWebProcessConnection):
+        * UIProcess/Launcher/qt/ProcessLauncherQt.cpp:
+        (WebKit::ProcessLauncher::launchProcess): All these places had
+        ``close-followed-by-EINTR-handling'' replaced with the new closeWithRetry()
+        function added in this commit.
+
 2013-06-20  Brady Eidson  <[email protected]>
 
         WebProcess hangs loading eff.org (Waiting forever on a sync XHR, NetworkProcess unable to service it).

Modified: trunk/Source/WebKit2/Platform/CoreIPC/unix/AttachmentUnix.cpp (151824 => 151825)


--- trunk/Source/WebKit2/Platform/CoreIPC/unix/AttachmentUnix.cpp	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WebKit2/Platform/CoreIPC/unix/AttachmentUnix.cpp	2013-06-21 06:02:58 UTC (rev 151825)
@@ -27,8 +27,7 @@
 #include "config.h"
 #include "Attachment.h"
 
-#include <unistd.h>
-#include <errno.h>
+#include <wtf/UniStdExtras.h>
 
 namespace CoreIPC {
 
@@ -49,7 +48,7 @@
 void Attachment::dispose()
 {
     if (m_fileDescriptor != -1)
-        while (close(m_fileDescriptor) == -1 && (errno == EINTR)) { }
+        closeWithRetry(m_fileDescriptor);
 }
 
 } // namespace CoreIPC

Modified: trunk/Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp (151824 => 151825)


--- trunk/Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WebKit2/Platform/CoreIPC/unix/ConnectionUnix.cpp	2013-06-21 06:02:58 UTC (rev 151825)
@@ -37,6 +37,7 @@
 #include <wtf/Assertions.h>
 #include <wtf/Functional.h>
 #include <wtf/OwnArrayPtr.h>
+#include <wtf/UniStdExtras.h>
 
 #if PLATFORM(QT)
 #include <QPointer>
@@ -136,7 +137,7 @@
     // In GTK+ platform the socket is closed by the work queue.
 #if !PLATFORM(GTK)
     if (m_socketDescriptor != -1)
-        while (close(m_socketDescriptor) == -1 && errno == EINTR) { }
+        closeWithRetry(m_socketDescriptor);
 #endif
 
     if (!m_isConnected)

Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (151824 => 151825)


--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp	2013-06-21 06:02:58 UTC (rev 151825)
@@ -41,6 +41,7 @@
 #include <wtf/Assertions.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/RandomNumber.h>
+#include <wtf/UniStdExtras.h>
 #include <wtf/text/CString.h>
 
 namespace WebKit {
@@ -54,7 +55,7 @@
 SharedMemory::Handle::~Handle()
 {
     if (!isNull())
-        while (close(m_fileDescriptor) == -1 && errno == EINTR) { }
+        closeWithRetry(m_fileDescriptor);
 }
 
 bool SharedMemory::Handle::isNull() const
@@ -116,7 +117,7 @@
 
     while (ftruncate(fileDescriptor, size) == -1) {
         if (errno != EINTR) {
-            while (close(fileDescriptor) == -1 && errno == EINTR) { }
+            closeWithRetry(fileDescriptor);
             shm_unlink(tempName.data());
             return 0;
         }
@@ -124,7 +125,7 @@
 
     void* data = "" size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0);
     if (data == MAP_FAILED) {
-        while (close(fileDescriptor) == -1 && errno == EINTR) { }
+        closeWithRetry(fileDescriptor);
         shm_unlink(tempName.data());
         return 0;
     }
@@ -170,7 +171,7 @@
 SharedMemory::~SharedMemory()
 {
     munmap(m_data, m_size);
-    while (close(m_fileDescriptor) == -1 && errno == EINTR) { }
+    closeWithRetry(m_fileDescriptor);
 }
 
 static inline int accessModeFile(SharedMemory::Protection protection)
@@ -202,7 +203,7 @@
     while ((fcntl(duplicatedHandle, F_SETFD, FD_CLOEXEC | accessModeFile(protection)) == -1)) {
         if (errno != EINTR) {
             ASSERT_NOT_REACHED();
-            while (close(duplicatedHandle) == -1 && errno == EINTR) { }
+            closeWithRetry(duplicatedHandle);
             return false;
         }
     }

Modified: trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp (151824 => 151825)


--- trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp	2013-06-21 06:02:58 UTC (rev 151825)
@@ -50,6 +50,7 @@
 #include <sys/resource.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <wtf/UniStdExtras.h>
 
 #ifdef SOCK_SEQPACKET
 #define SOCKET_TYPE SOCK_SEQPACKET
@@ -192,8 +193,8 @@
     while (fcntl(sockets[1], F_SETFD, FD_CLOEXEC)  == -1) {
         if (errno != EINTR) {
             ASSERT_NOT_REACHED();
-            while (close(sockets[0]) == -1 && errno == EINTR) { }
-            while (close(sockets[1]) == -1 && errno == EINTR) { }
+            closeWithRetry(sockets[0]);
+            closeWithRetry(sockets[1]);
             return;
         }
     }
@@ -202,8 +203,8 @@
     while (fcntl(sockets[0], F_SETFD, FD_CLOEXEC) == -1) {
         if (errno != EINTR) {
             ASSERT_NOT_REACHED();
-            while (close(sockets[0]) == -1 && errno == EINTR) { }
-            while (close(sockets[1]) == -1 && errno == EINTR) { }
+            closeWithRetry(sockets[0]);
+            closeWithRetry(sockets[1]);
             return;
         }
     }

Modified: trunk/Source/WebKit2/SharedWorkerProcess/SharedWorkerProcess.cpp (151824 => 151825)


--- trunk/Source/WebKit2/SharedWorkerProcess/SharedWorkerProcess.cpp	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WebKit2/SharedWorkerProcess/SharedWorkerProcess.cpp	2013-06-21 06:02:58 UTC (rev 151825)
@@ -46,6 +46,7 @@
 #include <sys/resource.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <wtf/UniStdExtras.h>
 
 #ifdef SOCK_SEQPACKET
 #define SOCKET_TYPE SOCK_SEQPACKET
@@ -139,8 +140,8 @@
     while (fcntl(sockets[1], F_SETFD, FD_CLOEXEC)  == -1) {
         if (errno != EINTR) {
             ASSERT_NOT_REACHED();
-            while (close(sockets[0]) == -1 && errno == EINTR) { }
-            while (close(sockets[1]) == -1 && errno == EINTR) { }
+            closeWithRetry(sockets[0]);
+            closeWithRetry(sockets[1]);
             return;
         }
     }
@@ -149,8 +150,8 @@
     while (fcntl(sockets[0], F_SETFD, FD_CLOEXEC) == -1) {
         if (errno != EINTR) {
             ASSERT_NOT_REACHED();
-            while (close(sockets[0]) == -1 && errno == EINTR) { }
-            while (close(sockets[1]) == -1 && errno == EINTR) { }
+            closeWithRetry(sockets[0]);
+            closeWithRetry(sockets[1]);
             return;
         }
     }

Modified: trunk/Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp (151824 => 151825)


--- trunk/Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp	2013-06-21 04:21:54 UTC (rev 151824)
+++ trunk/Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp	2013-06-21 06:02:58 UTC (rev 151825)
@@ -50,6 +50,7 @@
 #include <sys/resource.h>
 #include <sys/socket.h>
 #include <unistd.h>
+#include <wtf/UniStdExtras.h>
 #endif
 
 #if defined(Q_OS_LINUX)
@@ -162,8 +163,8 @@
     while (fcntl(sockets[1], F_SETFD, FD_CLOEXEC)  == -1) {
         if (errno != EINTR) {
             ASSERT_NOT_REACHED();
-            while (close(sockets[0]) == -1 && errno == EINTR) { }
-            while (close(sockets[1]) == -1 && errno == EINTR) { }
+            closeWithRetry(sockets[0]);
+            closeWithRetry(sockets[1]);
             return;
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to