Handle SIGPIPE more elegant way 43/25243/5
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 31 Jul 2014 16:13:37 +0000 (18:13 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 1 Aug 2014 09:59:15 +0000 (11:59 +0200)
Remove SIGPIPE ignoring in libraries. Use send with MSG_NOSIGNAL
instead of write in libraries Socket classes.

Change-Id: I2876d0ae80a21c7e2e3314f718c974cb7a1d389f

src/admin/api/admin-api.cpp
src/client/api/client-api.cpp
src/common/CMakeLists.txt
src/common/sockets/Socket.cpp
src/common/system/signals.cpp [deleted file]
src/common/system/signals.h [deleted file]

index 3c72744..d6e6a12 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <common.h>
 #include <log/log.h>
-#include <system/signals.h>
 #include <types/Policy.h>
 #include <types/PolicyBucketId.h>
 #include <types/PolicyKey.h>
@@ -62,8 +61,6 @@ int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) {
 
     init_log();
 
-    ignore_sigpipe();
-
     LOGD("Cynara admin initialized");
 
     return CYNARA_ADMIN_API_SUCCESS;
index 186e043..b6f139f 100644 (file)
@@ -25,7 +25,6 @@
 #include <common.h>
 
 #include <log/log.h>
-#include <system/signals.h>
 
 #include <cynara-client.h>
 #include <api/ApiInterface.h>
@@ -55,8 +54,6 @@ int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNU
 
     init_log();
 
-    ignore_sigpipe();
-
     LOGD("Cynara client initialized");
 
     return CYNARA_API_SUCCESS;
index 5f25aea..aef2ae7 100644 (file)
@@ -42,7 +42,6 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/response/ResponseTaker.cpp
     ${COMMON_PATH}/sockets/Socket.cpp
     ${COMMON_PATH}/sockets/SocketClient.cpp
-    ${COMMON_PATH}/system/signals.cpp
     ${COMMON_PATH}/types/PolicyBucket.cpp
     ${COMMON_PATH}/types/PolicyKey.cpp
     ${COMMON_PATH}/types/PolicyKeyHelpers.cpp
index c61134a..1c5ac3c 100644 (file)
@@ -182,8 +182,8 @@ bool Socket::sendToServer(BinaryQueue &queue) {
                 LOGE("Error in poll(POLLOUT)");
                 throw ServerConnectionErrorException();
             }
-            ssize_t t = TEMP_FAILURE_RETRY(write(m_sock, buffer.data() + done,
-                                           buffer.size() - done));
+            ssize_t t = TEMP_FAILURE_RETRY(send(m_sock, buffer.data() + done,
+                                           buffer.size() - done, MSG_NOSIGNAL));
             if (t == -1) {
                 int err = errno;
                 if (err == EPIPE) {
diff --git a/src/common/system/signals.cpp b/src/common/system/signals.cpp
deleted file mode 100644 (file)
index 6d74f4b..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Contact: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file        signals.cpp
- * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
- * @version     1.0
- * @brief       Implementation of signal related functions
- */
-
-#include <signal.h>
-#include <string.h>
-
-#include <log/log.h>
-
-#include "signals.h"
-
-void ignore_sigpipe(void)
-{
-    struct sigaction act;
-
-    memset(&act, 0, sizeof(act));
-    act.sa_handler = SIG_IGN;
-
-    if (sigaction(SIGPIPE, &act, NULL))
-        LOGE("sigaction failed during setting SIGPIPE handler to ignore");
-}
diff --git a/src/common/system/signals.h b/src/common/system/signals.h
deleted file mode 100644 (file)
index ef21ebb..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *  Contact: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-/*
- * @file        signals.h
- * @author      Adam Malinowski <a.malinowsk2@partner.samsung.com>
- * @version     1.0
- * @brief       Declaration of signal related functions
- */
-
-#ifndef SRC_COMMON_SYSTEM_SIGNALS_H_
-#define SRC_COMMON_SYSTEM_SIGNALS_H_
-
-void ignore_sigpipe(void);
-
-#endif /* SRC_COMMON_SYSTEM_SIGNALS_H_ */