Use endpoints provided by socket activation 93/62993/7
authorGeorgia Brikis <g.brikis@samsung.com>
Wed, 2 Mar 2016 14:44:47 +0000 (15:44 +0100)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Wed, 7 Mar 2018 19:17:33 +0000 (20:17 +0100)
Enable sdbd to receive preinitialized sockets from systemd. And enable
sdbd to use the endpoints passed by the systemd for opening a usb
thread (old functionality remains if socket activation is not used).

Change-Id: I0c08a82ad200aa042e095e1abf08d8e48de9c62d
Signed-off-by: Georgia Brikis <g.brikis@samsung.com>
[Rebased for Tizen 5.0]
Signed-off-by: Paweł Szewczyk <p.szewczyk@samsung.com>
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
CMakeLists.txt
packaging/sdbd.spec
src/usb_funcfs_client.c

index 4416ce1..080dbcc 100644 (file)
@@ -99,11 +99,19 @@ IF(WEARABLE_PROFILE STREQUAL on)
         ADD_DEFINITIONS("-D_WEARABLE")
 ENDIF()
 
+# Get systemd
+pkg_check_modules(SYSTEMD REQUIRED libsystemd)
+foreach(flag ${SYSTEMD_CFLAGS})
+       set(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+endforeach(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
 find_package(Threads REQUIRED)
 
 ADD_EXECUTABLE(sdbd ${SDBD_SRCS})
 ADD_EXECUTABLE(sdbd-user ${SDBD_SUBS})
-TARGET_LINK_LIBRARIES(sdbd -pie -lsmack -lresolv -ldl ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(sdbd -pie -lsmack -lresolv -ldl ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS} ${SYSTEMD_LDFLAGS})
 TARGET_LINK_LIBRARIES(sdbd-user -pie ${CMAKE_THREAD_LIBS_INIT} ${pkgs_LDFLAGS})
 
 set_property(
index 06f955f..3c09c79 100644 (file)
@@ -17,6 +17,8 @@ Source1006:    sdbd_emulator_tv.service
 
 BuildRequires: capi-system-info-devel >= 0.2.0
 BuildRequires: cmake >= 2.8.3
+BuildRequires: pkgconfig
+BuildRequires: pkgconfig(libsystemd)
 BuildRequires:  pkgconfig(libtzplatform-config)
 #BuildRequires: sec-product-features
 BuildRequires: pkgconfig(libsmack)
index 3e1ef6b..94f56f4 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/poll.h>
 #include <dirent.h>
 #include <errno.h>
+#include <systemd/sd-daemon.h>
 
 #include "sysdeps.h"
 
@@ -138,7 +139,18 @@ static void *usb_open_thread(void *x)
 {
     struct usb_handle *usb = (struct usb_handle *)x;
 
-    init_functionfs(usb);
+    /* Endpoints are received from sytemd */
+    if (sd_listen_fds(0) >= 3) {
+        sdb_mutex_lock(&usb->control_lock);
+        usb->control = SD_LISTEN_FDS_START + 0;
+        usb->bulk_out = SD_LISTEN_FDS_START + 1;
+        usb->bulk_in = SD_LISTEN_FDS_START + 2;
+        sdb_cond_signal(&usb->control_notify);
+        sdb_mutex_unlock(&usb->control_lock);
+    } else {
+        init_functionfs(usb);
+    }
+
     if (usb->control < 0 || usb->bulk_in < 0 || usb->bulk_out < 0) {
         D("[ opening device failed ]\n");
         return (void *)-1;
@@ -394,7 +406,7 @@ void ffs_usb_init()
         perror("[ failed to allocate memory for usb FunctionFS bulk device ]\n");
         return;
     }
-    if (autoconfig(h) < 0) {
+    if (sd_listen_fds(0) < 3 && autoconfig(h) < 0) {
         perror("[ can't recognize usb FunctionFS bulk device ]\n");
         free(h);
         return;