From: Georgia Brikis Date: Wed, 2 Mar 2016 14:44:47 +0000 (+0100) Subject: Use endpoints provided by socket activation X-Git-Tag: accepted/tizen/unified/20180426.145755~10^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F62993%2F7;p=sdk%2Ftarget%2Fsdbd.git Use endpoints provided by socket activation 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 [Rebased for Tizen 5.0] Signed-off-by: Paweł Szewczyk Signed-off-by: Krzysztof Opasiak --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4416ce1..080dbcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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( diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 06f955f..3c09c79 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -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) diff --git a/src/usb_funcfs_client.c b/src/usb_funcfs_client.c index 3e1ef6b..94f56f4 100644 --- a/src/usb_funcfs_client.c +++ b/src/usb_funcfs_client.c @@ -24,6 +24,7 @@ #include #include #include +#include #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;