From 25e9dbdc6c6c75931659a829875c351d884d966a Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Fri, 8 May 2015 20:22:50 +0200 Subject: [PATCH] Fix build with CYNARA_NO_LOGS Adding definition of CYNARA_NO_LOGS in top-level CMake enables build with all logs disabled. Unfortunately such a build would fail in few files. This patch fixes those files, enabling log-less build. Change-Id: Ib2ab690ff1774f987d2d498a27709a968985ae6d Signed-off-by: Rafal Krypa --- CMakeLists.txt | 4 ++++ src/client/logic/Logic.cpp | 3 ++- src/common/log/log.cpp | 7 +++++++ src/common/plugin/PluginManager.cpp | 5 +++-- src/service/sockets/SocketManager.cpp | 11 ++++++----- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab2cf62..3b53e66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,10 @@ IF (BUILD_WITH_SYSTEMD) ADD_DEFINITIONS("-DBUILD_WITH_SYSTEMD") ENDIF (BUILD_WITH_SYSTEMD) +IF (CYNARA_NO_LOGS) + ADD_DEFINITIONS("-DCYNARA_NO_LOGS") +ENDIF (CYNARA_NO_LOGS) + SET(TARGET_CYNARA "cynara") SET(TARGET_LIB_CYNARA "cynara-client") SET(TARGET_LIB_CYNARA_ASYNC "cynara-client-async") diff --git a/src/client/logic/Logic.cpp b/src/client/logic/Logic.cpp index 4280475..6f84fb6 100644 --- a/src/client/logic/Logic.cpp +++ b/src/client/logic/Logic.cpp @@ -95,8 +95,9 @@ int Logic::simpleCheck(const std::string &client, const ClientSession &session, PolicyResult result; ret = requestSimpleResult(key, result); if (ret != CYNARA_API_SUCCESS) { - if (ret != CYNARA_API_ACCESS_NOT_RESOLVED) + if (ret != CYNARA_API_ACCESS_NOT_RESOLVED) { LOGE("Error fetching response for simpleCheck."); + } return ret; } diff --git a/src/common/log/log.cpp b/src/common/log/log.cpp index 8ab77c8..fe6c569 100644 --- a/src/common/log/log.cpp +++ b/src/common/log/log.cpp @@ -27,6 +27,7 @@ #include #include +#ifndef CYNARA_NO_LOGS #ifdef BUILD_TYPE_DEBUG int __log_level = LOG_DEBUG; #else @@ -60,3 +61,9 @@ void init_log(void) { __log_level = strlog2intlog(env_val); } } + +#else + +void init_log(void) {} + +#endif //CYNARA_NO_LOGS diff --git a/src/common/plugin/PluginManager.cpp b/src/common/plugin/PluginManager.cpp index 4433ef1..b4291b7 100644 --- a/src/common/plugin/PluginManager.cpp +++ b/src/common/plugin/PluginManager.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -93,8 +94,8 @@ void PluginManager::loadPlugins(void) { int fileAmount = scandir(m_dir.c_str(), &nameList, pluginFilter, alphasort); if (fileAmount < 0) { - auto error = strerror(errno); - LOGE("Couldn't scan for plugins in <%s> : <%s>", m_dir.c_str(), error); + UNUSED int err = errno; + LOGE("Couldn't scan for plugins in <%s> : <%s>", m_dir.c_str(), strerror(err)); return; } diff --git a/src/service/sockets/SocketManager.cpp b/src/service/sockets/SocketManager.cpp index 0da326d..39a8c18 100644 --- a/src/service/sockets/SocketManager.cpp +++ b/src/service/sockets/SocketManager.cpp @@ -37,6 +37,7 @@ #include #endif +#include #include #include #include @@ -204,7 +205,7 @@ void SocketManager::readyForAccept(int fd) { unsigned int clientLen = sizeof(clientAddr); int clientFd = accept4(fd, (struct sockaddr*) &clientAddr, &clientLen, SOCK_NONBLOCK); if (clientFd == -1) { - int err = errno; + UNUSED int err = errno; LOGW("Error in accept on socket [%d]: <%s>", fd, strerror(err)); return; } @@ -275,7 +276,7 @@ int SocketManager::createDomainSocketHelp(const std::string &path, mode_t mask) int fd; if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - int err = errno; + UNUSED int err = errno; LOGE("Error during UNIX socket creation: <%s>", strerror(err)); throw InitException(); } @@ -284,7 +285,7 @@ int SocketManager::createDomainSocketHelp(const std::string &path, mode_t mask) if ((flags = fcntl(fd, F_GETFL, 0)) == -1) flags = 0; if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { - int err = errno; + UNUSED int err = errno; close(fd); LOGE("Error setting \"O_NONBLOCK\" on descriptor [%d] with fcntl: <%s>", fd, strerror(err)); @@ -306,7 +307,7 @@ int SocketManager::createDomainSocketHelp(const std::string &path, mode_t mask) originalUmask = umask(mask); if (bind(fd, (struct sockaddr*)&serverAddress, sizeof(serverAddress)) == -1) { - int err = errno; + UNUSED int err = errno; close(fd); LOGE("Error in bind socket descriptor [%d] to path <%s>: <%s>", fd, path.c_str(), strerror(err)); @@ -316,7 +317,7 @@ int SocketManager::createDomainSocketHelp(const std::string &path, mode_t mask) umask(originalUmask); if (listen(fd, 5) == -1) { - int err = errno; + UNUSED int err = errno; close(fd); LOGE("Error setting listen on file descriptor [%d], path <%s>: <%s>", fd, path.c_str(), strerror(err)); -- 2.7.4