From 84288a8e7231304b7b5d2e35353b9c66c07bc90e Mon Sep 17 00:00:00 2001 From: darin Date: Thu, 13 Jun 2019 11:45:02 +0800 Subject: [PATCH] Fix close server fd repeatedly (#2543) --- .../android/multiprocess/weex_js_connection.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/weex_core/Source/android/multiprocess/weex_js_connection.cpp b/weex_core/Source/android/multiprocess/weex_js_connection.cpp index 251bc02967..6cfe2084bc 100644 --- a/weex_core/Source/android/multiprocess/weex_js_connection.cpp +++ b/weex_core/Source/android/multiprocess/weex_js_connection.cpp @@ -45,6 +45,9 @@ static bool s_in_find_icu = false; static std::string g_crashFileName; + +volatile static bool fd_server_closed = false; + static void doExec(int fdClient, int fdServer, bool traceEnable, bool startupPie); static int copyFile(const char *SourceFile, const char *NewFile); @@ -53,6 +56,13 @@ static void closeAllButThis(int fd, int fd2); static void printLogOnFile(const char *log); +static void closeServerFd(int fd) { + if(fd_server_closed) + return; + close(fd); + fd_server_closed = true; +} + static bool checkOrCreateCrashFile(const char* file) { if (file == nullptr) { LOGE("checkOrCreateCrashFile Pass error file name!"); @@ -180,7 +190,7 @@ static void *newIPCServer(void *_td) { listener->listen(); } catch (IPCException &e) { LOGE("server died"); - close(td->ipcServerFd); + closeServerFd(td->ipcServerFd); base::android::DetachFromVM(); pthread_exit(NULL); } @@ -210,6 +220,7 @@ IPCSender *WeexJSConnection::start(IPCHandler *handler, IPCHandler *serverHandle if (-1 == fd2) { throw IPCException("failed to create ashmem region: %s", strerror(errno)); } + fd_server_closed = false; ThreadData td = { static_cast(fd2), static_cast(serverHandler) }; pthread_attr_t threadAttr; @@ -272,7 +283,7 @@ IPCSender *WeexJSConnection::start(IPCHandler *handler, IPCHandler *serverHandle int myerrno = errno; munmap(base, IPCFutexPageQueue::ipc_size); close(fd); - close(fd2); + closeServerFd(fd2); throw IPCException("failed to fork: %s", strerror(myerrno)); } else if (child == 0) { LOGE("weexcore fork child success\n"); @@ -287,7 +298,7 @@ IPCSender *WeexJSConnection::start(IPCHandler *handler, IPCHandler *serverHandle } else { printLogOnFile("fork success on main process and start m_impl->futexPageQueue->spinWaitPeer()"); close(fd); - close(fd2); + closeServerFd(fd2); m_impl->child = child; try { m_impl->futexPageQueue->spinWaitPeer();