Skip to content

Commit

Permalink
service: register on public bus to fix pre-3.5 service access
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed May 21, 2022
1 parent 1acde81 commit afae3e6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
22 changes: 20 additions & 2 deletions service/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit afae3e6

Please sign in to comment.