From afae3e612ee2524738401568b21e9d4903b96973 Mon Sep 17 00:00:00 2001 From: tuxuser <462620+tuxuser@users.noreply.github.com> Date: Sat, 21 May 2022 22:41:41 +0200 Subject: [PATCH] service: register on public bus to fix pre-3.5 service access --- service/CMakeLists.txt | 2 +- service/src/main.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/service/CMakeLists.txt b/service/CMakeLists.txt index e6f739d..8491643 100644 --- a/service/CMakeLists.txt +++ b/service/CMakeLists.txt @@ -68,7 +68,7 @@ target_link_libraries (${BIN_NAME} ${GLIB2_LDFLAGS} ${PMLOG_LDFLAGS} ) -target_compile_options(${BIN_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror) +target_compile_options(${BIN_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -DSECURITY_COMPATIBILITY) file(COPY ${CMAKE_SOURCE_DIR}/services.json DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") file(COPY ${CMAKE_SOURCE_DIR}/scripts/autostart.sh DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") diff --git a/service/src/main.c b/service/src/main.c index 582c8b3..342b3ee 100644 --- a/service/src/main.c +++ b/service/src/main.c @@ -10,6 +10,16 @@ GMainLoop *gmainLoop; +// This is a deprecated symbol present in meta-lg-webos-ndk but missing in +// latest buildroot NDK. It is required for proper public service registration +// before webOS 3.5. +// +// SECURITY_COMPATIBILITY flag present in CMakeList disables deprecation notices, see: +// https://github.com/webosose/luna-service2/blob/b74b1859372597fcd6f0f7d9dc3f300acbf6ed6c/include/public/luna-service2/lunaservice.h#L49-L53 +bool LSRegisterPubPriv(const char* name, LSHandle** sh, + bool public_bus, + LSError* lserror) __attribute__((weak)); + bool is_elevated() { return (geteuid() == 0); @@ -242,9 +252,17 @@ int main() // create a GMainLoop gmainLoop = g_main_loop_new(NULL, FALSE); - if(!LSRegister(SERVICE_NAME, &handle, &lserror)) { + bool registered = false; + + if (&LSRegisterPubPriv != 0) { + registered = LSRegisterPubPriv(SERVICE_NAME, &handle, true, &lserror); + } else { + registered = LSRegister(SERVICE_NAME, &handle, &lserror); + } + + if (!registered) { LSErrorFree(&lserror); - return 0; + return -1; } LSRegisterCategory(handle, "/", methods, NULL, NULL, &lserror);