From 8cd4946364d609d810569a2074b0a81bdb8b6529 Mon Sep 17 00:00:00 2001 From: Adam Malinowski Date: Tue, 22 Jul 2014 11:11:02 +0200 Subject: [PATCH] Add SIGPIPE ignoring in client and admin libraries Change-Id: I485dee789cc3916256affea310b7bd288200eec6 --- src/admin/api/admin-api.cpp | 3 +++ src/client/api/client-api.cpp | 4 ++++ src/common/CMakeLists.txt | 1 + src/common/system/signals.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/common/system/signals.h | 30 ++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 src/common/system/signals.cpp create mode 100644 src/common/system/signals.h diff --git a/src/admin/api/admin-api.cpp b/src/admin/api/admin-api.cpp index d6e6a12..3c72744 100644 --- a/src/admin/api/admin-api.cpp +++ b/src/admin/api/admin-api.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/src/client/api/client-api.cpp b/src/client/api/client-api.cpp index 4fc1c1d..8b34981 100644 --- a/src/client/api/client-api.cpp +++ b/src/client/api/client-api.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -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; diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d2d5e03..92874a7 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -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 index 0000000..6d74f4b --- /dev/null +++ b/src/common/system/signals.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Lukasz Wojciechowski + * + * 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 + * @version 1.0 + * @brief Implementation of signal related functions + */ + +#include +#include + +#include + +#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 index 0000000..ef21ebb --- /dev/null +++ b/src/common/system/signals.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Lukasz Wojciechowski + * + * 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 + * @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_ */ -- 2.7.4