Add SIGPIPE ignoring in client and admin libraries 05/24805/5
authorAdam Malinowski <a.malinowsk2@partner.samsung.com>
Tue, 22 Jul 2014 09:11:02 +0000 (11:11 +0200)
committerAdam Malinowski <a.malinowsk2@partner.samsung.com>
Tue, 29 Jul 2014 08:03:06 +0000 (10:03 +0200)
Change-Id: I485dee789cc3916256affea310b7bd288200eec6

src/admin/api/admin-api.cpp
src/client/api/client-api.cpp
src/common/CMakeLists.txt
src/common/system/signals.cpp [new file with mode: 0644]
src/common/system/signals.h [new file with mode: 0644]

index d6e6a12..3c72744 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <common.h>
 #include <log/log.h>
+#include <system/signals.h>
 #include <types/Policy.h>
 #include <types/PolicyBucketId.h>
 #include <types/PolicyKey.h>
@@ -61,6 +62,8 @@ int cynara_admin_initialize(struct cynara_admin **pp_cynara_admin) {
 
     init_log();
 
+    ignore_sigpipe();
+
     LOGD("Cynara admin initialized");
 
     return CYNARA_ADMIN_API_SUCCESS;
index 4fc1c1d..8b34981 100644 (file)
@@ -25,6 +25,7 @@
 #include <common.h>
 
 #include <log/log.h>
+#include <system/signals.h>
 
 #include <cynara-client.h>
 #include <api/ApiInterface.h>
@@ -53,6 +54,9 @@ int cynara_initialize(cynara **pp_cynara, const cynara_configuration *p_conf UNU
     }
 
     init_log();
+
+    ignore_sigpipe();
+
     LOGD("Cynara client initialized");
 
     return cynara_api_result::CYNARA_API_SUCCESS;
index d2d5e03..92874a7 100644 (file)
@@ -42,6 +42,7 @@ 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
     )
diff --git a/src/common/system/signals.cpp b/src/common/system/signals.cpp
new file mode 100644 (file)
index 0000000..6d74f4b
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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
new file mode 100644 (file)
index 0000000..ef21ebb
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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_ */