From: Rafal Krypa Date: Mon, 3 Apr 2017 12:41:13 +0000 (+0200) Subject: Fix building libaskuser-notification against libsystemd X-Git-Tag: submit/tizen/20170405.143506~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97829a34cee99991d07f5ccde369becbb73c7b43;p=platform%2Fcore%2Fsecurity%2Faskuser.git Fix building libaskuser-notification against libsystemd NOTE: this fix works correctly when BUILD_WITH_SYSTEMD_DAEMON is set but will fail to build if it's not set and systemd build dependencies are not installed. Such case is not cover for a simple reason - this flaw is already present in several places of this project. It should be fixed in general way by some other commit. Change-Id: I422cedcc9f84faaf757a75a72c8a01e37bbe17b7 Signed-off-by: Rafal Krypa --- diff --git a/src/common/protocol/CMakeLists.txt b/src/common/protocol/CMakeLists.txt index dfae210..f9aa188 100644 --- a/src/common/protocol/CMakeLists.txt +++ b/src/common/protocol/CMakeLists.txt @@ -23,8 +23,14 @@ SET(ASKUSER_NOTIFICATION_VERSION ${ASKUSER_NOTIFICATION_VERSION_MAJOR}.1.0) SET(PC_FILE "askuser-notification.pc") +PKG_CHECK_MODULES(ASKUSER_NOTIFICATION_DEP + REQUIRED + libsystemd + ) + INCLUDE_DIRECTORIES( ${PROTOCOL_PATH} + ${ASKUSER_NOTIFICATION_DEP_INCLUDE_DIRS} ) SET(ASKUSER_NOTIFICATION_SOURCES @@ -49,7 +55,7 @@ SET_TARGET_PROPERTIES(${TARGET_ASKUSER_NOTIFICATION_LIB} VERSION ${ASKUSER_NOTIFICATION_VERSION} ) -TARGET_LINK_LIBRARIES(${TARGET_ASKUSER_NOTIFICATION_LIB}) +TARGET_LINK_LIBRARIES(${TARGET_ASKUSER_NOTIFICATION_LIB} ${ASKUSER_NOTIFICATION_DEP_LIBRARIES}) TARGET_LINK_LIBRARIES(${TARGET_ASKUSER_NOTIFICATION_TEST} ${TARGET_ASKUSER_NOTIFICATION_LIB}) INSTALL(TARGETS ${TARGET_ASKUSER_NOTIFICATION_LIB} diff --git a/src/common/protocol/sock.cpp b/src/common/protocol/sock.cpp index 18b65b4..afceddd 100644 --- a/src/common/protocol/sock.cpp +++ b/src/common/protocol/sock.cpp @@ -24,9 +24,9 @@ #include #include -#ifdef WITH_SYSTEMD +#ifdef BUILD_WITH_SYSTEMD_DAEMON #include -#endif // WITH_SYSTEMD +#endif // BUILD_WITH_SYSTEMD_DAEMON #include #include @@ -35,24 +35,6 @@ #include -namespace { - -int getSocketFromSystemD() { -#ifdef WITH_SYSTEMD - int n = sd_listen_fds(0); - - if (n < 0) - return -1; - - for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START+n; ++fd) - if (0 < sd_is_socket_unix(fd, getUnixSockType, 1, m_path.c_str(), 0)) - return fd; -#endif // WITH_SYSTEMD - return -1; -} - -} // namespace Anonymous - namespace AskUser { namespace Protocol { @@ -95,6 +77,20 @@ int Sock::getUnixSockType() const { return 0; } +int Sock::getSocketFromSystemD() { +#ifdef BUILD_WITH_SYSTEMD_DAEMON + int n = sd_listen_fds(0); + + if (n < 0) + return -1; + + for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START+n; ++fd) + if (0 < sd_is_socket_unix(fd, getUnixSockType(), 1, m_path.c_str(), 0)) + return fd; +#endif // BUILD_WITH_SYSTEMD_DAEMON + return -1; +} + int Sock::connect(const std::string &path) { if (m_fd != -1) return -1; diff --git a/src/common/protocol/sock.h b/src/common/protocol/sock.h index 499bf1c..a746908 100644 --- a/src/common/protocol/sock.h +++ b/src/common/protocol/sock.h @@ -53,7 +53,6 @@ public: int getType() const { return m_type; } int getUnixSockType() const; - int connect(const std::string &path); Sock accept(); void close(); @@ -63,6 +62,8 @@ public: int send(const RawBuffer &buffer); private: + int getSocketFromSystemD(); + Type m_type; int m_fd; std::string m_path;