Fix build with CYNARA_NO_LOGS 20/39120/8
authorRafal Krypa <r.krypa@samsung.com>
Fri, 8 May 2015 18:22:50 +0000 (20:22 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 31 Jul 2015 14:24:26 +0000 (07:24 -0700)
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 <r.krypa@samsung.com>
CMakeLists.txt
src/client/logic/Logic.cpp
src/common/log/log.cpp
src/common/plugin/PluginManager.cpp
src/service/sockets/SocketManager.cpp

index ab2cf62..3b53e66 100644 (file)
@@ -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")
index 4280475..6f84fb6 100644 (file)
@@ -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;
     }
 
index 8ab77c8..fe6c569 100644 (file)
@@ -27,6 +27,7 @@
 #include <cstring>
 #include <stdlib.h>
 
+#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
index 4433ef1..b4291b7 100644 (file)
@@ -30,6 +30,7 @@
 #include <dlfcn.h>
 #include <functional>
 
+#include <attributes/attributes.h>
 #include <exceptions/UnknownPolicyTypeException.h>
 #include <log/log.h>
 
@@ -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;
     }
 
index 0da326d..39a8c18 100644 (file)
@@ -37,6 +37,7 @@
 #include <systemd/sd-daemon.h>
 #endif
 
+#include <attributes/attributes.h>
 #include <log/log.h>
 #include <common.h>
 #include <config/PathConfig.h>
@@ -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));