Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/WTF/wtf/UniStdExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
namespace WTF {

WTF_EXPORT_PRIVATE bool setCloseOnExec(int fileDescriptor);
WTF_EXPORT_PRIVATE bool unsetCloseOnExec(int fileDescriptor);
WTF_EXPORT_PRIVATE int dupCloseOnExec(int fileDescriptor);

inline int closeWithRetry(int fileDescriptor)
Expand All @@ -57,6 +58,7 @@ WTF_EXPORT_PRIVATE bool setNonBlock(int fileDescriptor);
using WTF::closeWithRetry;
using WTF::dupCloseOnExec;
using WTF::setCloseOnExec;
using WTF::unsetCloseOnExec;
using WTF::setNonBlock;

#endif // UniStdExtras_h
5 changes: 5 additions & 0 deletions Source/WTF/wtf/playstation/UniStdExtrasPlayStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ bool setCloseOnExec(int)
return true;
}

bool unsetCloseOnExec(int)
{
return true;
}

int dupCloseOnExec(int fileDescriptor)
{
int duplicatedFileDescriptor = -1;
Expand Down
12 changes: 12 additions & 0 deletions Source/WTF/wtf/unix/UniStdExtrasUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ bool setCloseOnExec(int fileDescriptor)
return returnValue != -1;
}

bool unsetCloseOnExec(int fileDescriptor)
{
int returnValue = -1;
do {
int flags = fcntl(fileDescriptor, F_GETFD);
if (flags == -1)
returnValue = fcntl(fileDescriptor, F_SETFD, flags & ~FD_CLOEXEC);
} while (returnValue == -1 && errno == EINTR);

return returnValue != -1;
}

int dupCloseOnExec(int fileDescriptor)
{
int duplicatedFileDescriptor = -1;
Expand Down
30 changes: 20 additions & 10 deletions Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,19 +547,29 @@ bool Connection::sendOutputMessage(UnixMessage& outputMessage)
SocketPair createPlatformConnection(unsigned options)
{
int sockets[2];
RELEASE_ASSERT(socketpair(AF_UNIX, SOCKET_TYPE, 0, sockets) != -1);

if (options & SetCloexecOnServer) {
// Don't expose the child socket to the parent process.
if (!setCloseOnExec(sockets[1]))
RELEASE_ASSERT_NOT_REACHED();
}
#if OS(LINUX)
if ((options & SetCloexecOnServer) || (options & SetCloexecOnClient)) {
RELEASE_ASSERT(socketpair(AF_UNIX, SOCKET_TYPE | SOCK_CLOEXEC, 0, sockets) != -1);

if (!(options & SetCloexecOnServer))
RELEASE_ASSERT(unsetCloseOnExec(sockets[1]));

if (!(options & SetCloexecOnClient))
RELEASE_ASSERT(unsetCloseOnExec(sockets[0]));

if (options & SetCloexecOnClient) {
// Don't expose the parent socket to potential future children.
if (!setCloseOnExec(sockets[0]))
RELEASE_ASSERT_NOT_REACHED();
SocketPair socketPair = { sockets[0], sockets[1] };
return socketPair;
}
#endif

RELEASE_ASSERT(socketpair(AF_UNIX, SOCKET_TYPE, 0, sockets) != -1);

if (options & SetCloexecOnServer)
RELEASE_ASSERT(setCloseOnExec(sockets[1]));

if (options & SetCloexecOnClient)
RELEASE_ASSERT(setCloseOnExec(sockets[0]));

SocketPair socketPair = { sockets[0], sockets[1] };
return socketPair;
Expand Down