From: Zofia Abramowska Date: Wed, 16 Jan 2013 13:44:23 +0000 (+0100) Subject: Fixing communication problem with security-server X-Git-Tag: submit/tizen_2.1/20130424.233001~5^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f09ae2f2a7a51a3e15cf71c613a99d0bc28364d;p=platform%2Fcore%2Fsecurity%2Fsecurity-server.git Fixing communication problem with security-server [Issue#] LINUXSWAP-454 [Bug] Security-server crashes [Cause] No handling of SIGPIPE signal when writing to closed socket [Solution] blocking SIGPIPE signal in all threads created by socket service and handling error returned by write [Verification] Build, run tests and check JIRA bug(N_SE-20154) Change-Id: Id6d15922bb9b94cb9ee565e9e90ed0e46a27e25c --- diff --git a/socket_connection/connection/SocketStream.cpp b/socket_connection/connection/SocketStream.cpp index 7172559..cc5d1a5 100644 --- a/socket_connection/connection/SocketStream.cpp +++ b/socket_connection/connection/SocketStream.cpp @@ -150,7 +150,7 @@ void SocketStream::Write(size_t num, const void * bytes){ if(FD_ISSET(m_socketFd, &wset)){ if(-1 == (write_res = write(m_socketFd, reinterpret_cast(bytes) + current_offset, bytes_to_write))){ - if(errno == ECONNRESET){ + if(errno == ECONNRESET || errno == EPIPE){ LogInfo("Connection closed : " << strerror(errno)); ThrowMsg(Exception::SocketStreamException, "Connection closed : " << strerror(errno) << ". Couldn't write whole data"); diff --git a/src/daemon/sockets/security_socket_service.cpp b/src/daemon/sockets/security_socket_service.cpp index 47d3769..689de1c 100644 --- a/src/daemon/sockets/security_socket_service.cpp +++ b/src/daemon/sockets/security_socket_service.cpp @@ -166,6 +166,7 @@ void SecuritySocketService::start(){ } pthread_t mainThread; + if((returned_value = pthread_create(&mainThread, NULL, &serverThread, this)) < 0){ errno = returned_value; throwWithErrnoMessage("pthread_create()"); @@ -218,6 +219,13 @@ void SecuritySocketService::mainLoop(){ timespec timeout; maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd); ++maxfd; + //this will block SIGPIPE for this thread and every thread created in it + //reason : from here on we don't won't to receive SIGPIPE on writing to closed socket + //instead of signal we want to receive error from write - hence blocking SIGPIPE + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGPIPE); + pthread_sigmask(SIG_BLOCK, &set, NULL); while(1){ timeout.tv_sec = TIMEOUT_SEC;