Fix building libaskuser-notification against libsystemd 28/122828/1
authorRafal Krypa <r.krypa@samsung.com>
Mon, 3 Apr 2017 12:41:13 +0000 (14:41 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 3 Apr 2017 13:19:33 +0000 (15:19 +0200)
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 <r.krypa@samsung.com>
src/common/protocol/CMakeLists.txt
src/common/protocol/sock.cpp
src/common/protocol/sock.h

index dfae210..f9aa188 100644 (file)
@@ -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}
index 18b65b4..afceddd 100644 (file)
@@ -24,9 +24,9 @@
 #include <sys/un.h>
 #include <unistd.h>
 
-#ifdef WITH_SYSTEMD
+#ifdef BUILD_WITH_SYSTEMD_DAEMON
 #include <systemd/sd-daemon.h>
-#endif // WITH_SYSTEMD
+#endif // BUILD_WITH_SYSTEMD_DAEMON
 
 #include <string>
 #include <vector>
 
 #include <sock.h>
 
-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;
index 499bf1c..a746908 100644 (file)
@@ -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;