Skip to content

Commit afae3e6

Browse files
committed
service: register on public bus to fix pre-3.5 service access
1 parent 1acde81 commit afae3e6

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

service/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ target_link_libraries (${BIN_NAME}
6868
${GLIB2_LDFLAGS}
6969
${PMLOG_LDFLAGS}
7070
)
71-
target_compile_options(${BIN_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror)
71+
target_compile_options(${BIN_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -DSECURITY_COMPATIBILITY)
7272

7373
file(COPY ${CMAKE_SOURCE_DIR}/services.json DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
7474
file(COPY ${CMAKE_SOURCE_DIR}/scripts/autostart.sh DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")

service/src/main.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010

1111
GMainLoop *gmainLoop;
1212

13+
// This is a deprecated symbol present in meta-lg-webos-ndk but missing in
14+
// latest buildroot NDK. It is required for proper public service registration
15+
// before webOS 3.5.
16+
//
17+
// SECURITY_COMPATIBILITY flag present in CMakeList disables deprecation notices, see:
18+
// https://github.com/webosose/luna-service2/blob/b74b1859372597fcd6f0f7d9dc3f300acbf6ed6c/include/public/luna-service2/lunaservice.h#L49-L53
19+
bool LSRegisterPubPriv(const char* name, LSHandle** sh,
20+
bool public_bus,
21+
LSError* lserror) __attribute__((weak));
22+
1323
bool is_elevated()
1424
{
1525
return (geteuid() == 0);
@@ -242,9 +252,17 @@ int main()
242252
// create a GMainLoop
243253
gmainLoop = g_main_loop_new(NULL, FALSE);
244254

245-
if(!LSRegister(SERVICE_NAME, &handle, &lserror)) {
255+
bool registered = false;
256+
257+
if (&LSRegisterPubPriv != 0) {
258+
registered = LSRegisterPubPriv(SERVICE_NAME, &handle, true, &lserror);
259+
} else {
260+
registered = LSRegister(SERVICE_NAME, &handle, &lserror);
261+
}
262+
263+
if (!registered) {
246264
LSErrorFree(&lserror);
247-
return 0;
265+
return -1;
248266
}
249267

250268
LSRegisterCategory(handle, "/", methods, NULL, NULL, &lserror);

0 commit comments

Comments
 (0)