summaryrefslogtreecommitdiffstats
path: root/chrome/browser/process_singleton_linux.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 17:29:49 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 17:29:49 +0000
commitbecc0bb5838e50cf5c4da245d836a41aaed34fa3 (patch)
treeccab767fbb55244be79f7e3389fe995a27dee96e /chrome/browser/process_singleton_linux.cc
parent1cebf78b143cb46e840c4fdc4faa74aaf576db09 (diff)
downloadchromium_src-becc0bb5838e50cf5c4da245d836a41aaed34fa3.zip
chromium_src-becc0bb5838e50cf5c4da245d836a41aaed34fa3.tar.gz
chromium_src-becc0bb5838e50cf5c4da245d836a41aaed34fa3.tar.bz2
linux: set FD_CLOEXEC on the singleton socket
The IME library may spawn a subprocess, which will then hold open our singleton socket after we've shut down. BUG=17952 Review URL: http://codereview.chromium.org/160523 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton_linux.cc')
-rw-r--r--chrome/browser/process_singleton_linux.cc14
1 files changed, 14 insertions, 0 deletions
diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc
index eebbd39..f0d33e6 100644
--- a/chrome/browser/process_singleton_linux.cc
+++ b/chrome/browser/process_singleton_linux.cc
@@ -43,6 +43,7 @@ const char kTokenDelimiter = '\0';
const int kTimeOutInSeconds = 5;
const int kMaxMessageLength = 32 * 1024;
+// Set a file descriptor to be non-blocking.
// Return 0 on success, -1 on failure.
int SetNonBlocking(int fd) {
int flags = fcntl(fd, F_GETFL, 0);
@@ -53,6 +54,17 @@ int SetNonBlocking(int fd) {
return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
}
+// Set the close-on-exec bit on a file descriptor.
+// Returns 0 on success, -1 on failure.
+int SetCloseOnExec(int fd) {
+ int flags = fcntl(fd, F_GETFD, 0);
+ if (-1 == flags)
+ return flags;
+ if (flags & FD_CLOEXEC)
+ return 0;
+ return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+}
+
} // namespace
///////////////////////////////////////////////////////////////////////////////
@@ -428,6 +440,8 @@ void ProcessSingleton::SetupSocket(int* sock, struct sockaddr_un* addr) {
int rv = SetNonBlocking(*sock);
DCHECK_EQ(0, rv) << "Failed to make non-blocking socket.";
+ rv = SetCloseOnExec(*sock);
+ DCHECK_EQ(0, rv) << "Failed to set CLOEXEC on socket.";
addr->sun_family = AF_UNIX;
if (socket_path_.value().length() > sizeof(addr->sun_path) - 1)