From 76206c65074a62086d7625cf260ab4f6b9a2744b Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Tue, 14 Jan 2025 14:57:43 +0100 Subject: [PATCH 1/2] chore(linux): improve compatibility with Gentoo Linux Gentoo doesn't use systemd. `libelogind` or `basu` implement some aspects of systemd, so we use that on Gentoo (or rather when `libsystemd` is not available but `libelogind` or `basu` is). Patch from https://forums.gentoo.org/viewtopic.php?p=8850566. See also https://community.software.sil.org/t/keyman-for-gentoo-linux/9615. --- linux/ibus-keyman/meson.build | 10 +++++++++- .../ibus-keyman/src/KeymanSystemServiceClient.cpp | 5 +++++ linux/ibus-keyman/tests/KmDbusTestServer.cpp | 10 +++++++++- linux/ibus-keyman/tests/StopTestServer.cpp | 5 +++++ linux/ibus-keyman/tests/meson.build | 2 ++ linux/keyman-system-service/meson.build | 15 ++++++++++++++- .../com.keyman.SystemService1.service.basu | 7 +++++++ ... => com.keyman.SystemService1.service.systemd} | 1 + linux/keyman-system-service/resources/meson.build | 9 ++++++++- .../src/KeymanSystemService.cpp | 5 +++++ .../src/KeymanSystemService.h | 5 +++++ linux/keyman-system-service/src/meson.build | 1 + linux/keyman-system-service/tests/meson.build | 2 +- 13 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 linux/keyman-system-service/resources/com.keyman.SystemService1.service.basu rename linux/keyman-system-service/resources/{com.keyman.SystemService1.service => com.keyman.SystemService1.service.systemd} (78%) diff --git a/linux/ibus-keyman/meson.build b/linux/ibus-keyman/meson.build index 5a8958e983f..7859751af89 100644 --- a/linux/ibus-keyman/meson.build +++ b/linux/ibus-keyman/meson.build @@ -8,9 +8,17 @@ conf = configuration_data() ibus = dependency('ibus-1.0', version: '>= 1.2.0') gtk = dependency('gtk+-3.0', version: '>= 2.4') json_glib = dependency('json-glib-1.0', version: '>= 1.0') -systemd = dependency('libsystemd') icu = dependency('icu-i18n') +systemd = dependency('libsystemd', 'libelogind', required: false) +if systemd.found() + conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD') +else + # Gentoo can use libelogind or basu + systemd = dependency('basu') + conf.set('DBUS_IMPLEMENTATION', 'BASU') +endif + core_dir = meson.current_source_dir() / '../../core' common_dir = meson.current_source_dir() / '../../common' diff --git a/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp b/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp index 635c3ff22dd..50dbccba8d6 100644 --- a/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp +++ b/linux/ibus-keyman/src/KeymanSystemServiceClient.cpp @@ -1,5 +1,10 @@ +#include "config.h" #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #include "KeymanSystemServiceClient.h" #define KEYMAN_BUS_NAME "com.keyman.SystemService1" diff --git a/linux/ibus-keyman/tests/KmDbusTestServer.cpp b/linux/ibus-keyman/tests/KmDbusTestServer.cpp index e64a9354d8b..fda2a12c005 100644 --- a/linux/ibus-keyman/tests/KmDbusTestServer.cpp +++ b/linux/ibus-keyman/tests/KmDbusTestServer.cpp @@ -1,9 +1,14 @@ // DBus test server. The server will start and listen on a non-standard DBus. // It runs until the DBus Exit method gets called. +#include "config.h" #include #include #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #ifndef KEYMAN_TEST_SERVICE_PATH #warning KEYMAN_TEST_SERVICE_PATH is undefined @@ -73,7 +78,10 @@ KmDbusTestServer::~KmDbusTestServer() { if (bus) sd_bus_release_name(bus, KEYMAN_TESTSVC_BUS_NAME); if (slot) sd_bus_slot_unref(slot); - if (bus) sd_bus_close_unref(bus); + if (bus) { + sd_bus_close(bus); + sd_bus_unref(bus); + } g_test_dbus_down(dbus); g_object_unref(dbus); diff --git a/linux/ibus-keyman/tests/StopTestServer.cpp b/linux/ibus-keyman/tests/StopTestServer.cpp index 97ce5bfbe7f..2790e5b30ef 100644 --- a/linux/ibus-keyman/tests/StopTestServer.cpp +++ b/linux/ibus-keyman/tests/StopTestServer.cpp @@ -1,8 +1,13 @@ // Call the Exit method on the km-dbus-test-server. Remember to source // `/tmp/km-test-server.env` prior to running stop-test-server in order // to run on our non-standard DBus. +#include "config.h" #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif using namespace std; diff --git a/linux/ibus-keyman/tests/meson.build b/linux/ibus-keyman/tests/meson.build index 73ce8d84d08..cad98974161 100644 --- a/linux/ibus-keyman/tests/meson.build +++ b/linux/ibus-keyman/tests/meson.build @@ -38,6 +38,7 @@ dbus_test_server = executable( 'km-dbus-test-server', 'KmDbusTestServer.cpp', dependencies: dbus_deps, + include_directories: ['..'], cpp_args: [ '-DKEYMAN_TEST_SERVICE_PATH="' + system_service_dir + '"' ] @@ -47,6 +48,7 @@ stop_test_server = executable( 'stop-test-server', 'StopTestServer.cpp', dependencies: dbus_deps, + include_directories: ['..'], ) env_file = '/tmp/env.txt' diff --git a/linux/keyman-system-service/meson.build b/linux/keyman-system-service/meson.build index 66da8f98914..c4d48fba4fd 100644 --- a/linux/keyman-system-service/meson.build +++ b/linux/keyman-system-service/meson.build @@ -3,8 +3,21 @@ project('keyman-system-service', 'c', 'cpp', license: 'GPL-2+', meson_version: '>=0.61') +conf = configuration_data() + evdev = dependency('libevdev', version: '>= 1.9') -systemd = dependency('libsystemd') + +systemd = dependency('libsystemd', 'libelogind', required: false) +if systemd.found() + conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD') +else + # Gentoo can use libelogind or basu + systemd = dependency('basu') + conf.set('DBUS_IMPLEMENTATION', 'BASU') +endif + +configure_file(output : 'config.h', + configuration : conf) subdir('resources') subdir('src') diff --git a/linux/keyman-system-service/resources/com.keyman.SystemService1.service.basu b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.basu new file mode 100644 index 00000000000..67dd16eb5ad --- /dev/null +++ b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.basu @@ -0,0 +1,7 @@ +# /usr/share/dbus-1/system-services/com.keyman.SystemService1.service +# This version used with elogind and basu (e.g. on Gentoo) + +[D-BUS Service] +Name=com.keyman.SystemService1 +Exec=/usr/libexec/systemd-keyman.service +User=root diff --git a/linux/keyman-system-service/resources/com.keyman.SystemService1.service b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.systemd similarity index 78% rename from linux/keyman-system-service/resources/com.keyman.SystemService1.service rename to linux/keyman-system-service/resources/com.keyman.SystemService1.service.systemd index 3966fb1bbcb..65acc4067a4 100644 --- a/linux/keyman-system-service/resources/com.keyman.SystemService1.service +++ b/linux/keyman-system-service/resources/com.keyman.SystemService1.service.systemd @@ -1,4 +1,5 @@ # /usr/share/dbus-1/system-services/com.keyman.SystemService1.service +# This version used with systemd (e.g. on Debian) [D-BUS Service] Name=com.keyman.SystemService1 diff --git a/linux/keyman-system-service/resources/meson.build b/linux/keyman-system-service/resources/meson.build index c28cb81e585..663a3c558ab 100644 --- a/linux/keyman-system-service/resources/meson.build +++ b/linux/keyman-system-service/resources/meson.build @@ -1,3 +1,10 @@ install_data('com.keyman.SystemService1.conf', install_dir: get_option('datadir') / 'dbus-1/system.d/') -install_data('com.keyman.SystemService1.service', install_dir: get_option('datadir') / 'dbus-1/system-services/') + +if systemd.name() == 'libsystemd' + install_data('com.keyman.SystemService1.service.systemd', install_dir: get_option('datadir') / 'dbus-1/system-services/', rename: ['com.keyman.SystemService1.service']) +else + # libelogind or basu + install_data('com.keyman.SystemService1.service.basu', install_dir: get_option('datadir') / 'dbus-1/system-services/') +endif + install_data('systemd-keyman.service', install_dir: get_option('prefix') / 'lib/systemd/system/') diff --git a/linux/keyman-system-service/src/KeymanSystemService.cpp b/linux/keyman-system-service/src/KeymanSystemService.cpp index deceafd0c39..03d7add5334 100644 --- a/linux/keyman-system-service/src/KeymanSystemService.cpp +++ b/linux/keyman-system-service/src/KeymanSystemService.cpp @@ -2,6 +2,7 @@ // based on the sd-bus library, see // https://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html +#include "config.h" #include #include #include @@ -11,7 +12,11 @@ #include #include #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #include "KeymanSystemService.h" #include "KeyboardDevice.h" diff --git a/linux/keyman-system-service/src/KeymanSystemService.h b/linux/keyman-system-service/src/KeymanSystemService.h index 2686bfb99f9..86637f27a96 100644 --- a/linux/keyman-system-service/src/KeymanSystemService.h +++ b/linux/keyman-system-service/src/KeymanSystemService.h @@ -1,8 +1,13 @@ #ifndef __KEYMANSYSTEMSERVICE_H__ #define __KEYMANSYSTEMSERVICE_H__ +#include "config.h" #include +#if DBUS_IMPLEMENTATION == SYSTEMD #include +#else +#include +#endif #include "KeyboardDevice.h" using namespace std; diff --git a/linux/keyman-system-service/src/meson.build b/linux/keyman-system-service/src/meson.build index 51820ab9fa9..3c3dd27fa6e 100644 --- a/linux/keyman-system-service/src/meson.build +++ b/linux/keyman-system-service/src/meson.build @@ -10,6 +10,7 @@ exe = executable( 'keyman-system-service', sources: [service_files], dependencies: deps, + include_directories: ['..'], install: true, install_dir: get_option('libexecdir'), ) diff --git a/linux/keyman-system-service/tests/meson.build b/linux/keyman-system-service/tests/meson.build index f90e12d16a2..749e098591e 100644 --- a/linux/keyman-system-service/tests/meson.build +++ b/linux/keyman-system-service/tests/meson.build @@ -17,7 +17,7 @@ exe = executable( c_args: test_c_args, cpp_args: test_c_args, dependencies: deps, - include_directories: [ '../src' ] + include_directories: [ '..', '../src' ] ) # we currently don't have any unit tests for keyman-system-service. From dedd65350fb5a20b3280e76fadf8a3b4dfe25045 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Tue, 28 Jan 2025 16:11:45 +0100 Subject: [PATCH 2/2] chore(linux): make dependency requirements explicit `required: true` is the default for the meson `dependency` function, but it's easy to miss. --- linux/ibus-keyman/meson.build | 2 +- linux/keyman-system-service/meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/ibus-keyman/meson.build b/linux/ibus-keyman/meson.build index 7859751af89..8082814a6ce 100644 --- a/linux/ibus-keyman/meson.build +++ b/linux/ibus-keyman/meson.build @@ -15,7 +15,7 @@ if systemd.found() conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD') else # Gentoo can use libelogind or basu - systemd = dependency('basu') + systemd = dependency('basu', required: true) conf.set('DBUS_IMPLEMENTATION', 'BASU') endif diff --git a/linux/keyman-system-service/meson.build b/linux/keyman-system-service/meson.build index c4d48fba4fd..ec3c0c2d181 100644 --- a/linux/keyman-system-service/meson.build +++ b/linux/keyman-system-service/meson.build @@ -12,7 +12,7 @@ if systemd.found() conf.set('DBUS_IMPLEMENTATION', 'SYSTEMD') else # Gentoo can use libelogind or basu - systemd = dependency('basu') + systemd = dependency('basu', required: true) conf.set('DBUS_IMPLEMENTATION', 'BASU') endif