1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-24 00:48:53 +03:00

26 Commits

Author SHA1 Message Date
Bartosz Golaszewski
668a0efe91 dbus: fix the license of gpiodbus.h
The libgpiodbus library - which is entirely automatically generated with
gdbus-codegen - was meant to be available under LGPLv2.1 like all the
other shared libraries in this project. Change the SPDX tag in that
file to LGPL-2.1-or-later.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://patch.msgid.link/20260925-libgpiodbus-license-v1-1-d7ddafca8872@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-09-28 10:00:31 +02:00
Bartosz Golaszewski
7d7b077388 build: fix dependencies for generated files
Depending on the timing, we may try to build generated files that don't
exist yet. Generated .c and .h files need to be included in the sources
of the dependencies that need them so that they get generated before we
try to build them. Fix issues observed in dbus and GLib bindings.

Reported-by: Luca Weiss <luca@lucaweiss.eu>
Fixes: 97bab4cc87 ("build: replace autotools with meson & ninja")
Closes: https://github.com/brgl/libgpiod/issues/191
Link: https://patch.msgid.link/20260623-dbus-meson-deps-v1-1-b37604ecce3f@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-24 17:19:14 +02:00
Bartosz Golaszewski
40538a7b48 build: gate subdirectories on the *_enabled variables
The top-level meson.build descends into tests/ and dbus/ only when the
computed tests_enabled and dbus_enabled gates are true, so the test
helper libraries and D-Bus executables are only defined in those cases.
The per-component subdirectories instead re-checked opt_*.allowed(),
which is true under the default 'auto' even when the dependencies are
missing, and then referenced those undefined variables - failing the
configuration outright instead of quietly disabling the component.

Gate every subdirectory on the corresponding top-level *_enabled
variable for correct and consistent behavior.

Closes: https://github.com/brgl/libgpiod/discussions/190
Fixes: 97bab4cc87 ("build: replace autotools with meson & ninja")
Link: https://patch.msgid.link/20260617-meson-enabled-checks-v1-1-2ff45c7691fe@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-19 10:23:50 +02:00
Bartosz Golaszewski
84700a6d5f dbus: manager: move g_tree_remove() out of g_assert() in gpiodbus_id_free()
g_assert() is compiled out when G_DISABLE_ASSERT is defined, which would
cause the g_tree_remove() call to disappear entirely, leading to ID leaks
and eventual resource exhaustion. Move the side-effecting call outside
the assertion, consistent with the pattern used elsewhere in the daemon.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Assisted-by: Claude Opus 4.6
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260604-pre-2-3-fixes-v2-15-781bcaf47475@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-06-08 10:01:21 +02:00
Bartosz Golaszewski
cadfccff02 build: fix linking against libgpiodbus
Drop the 'sources' argument from meson's declare_dependency() for
libgpiodbus as this causes the build system to include the source files
in the source list of the targets using the dependency rather than link
against the libgpiodbus shared library.

Fixes: 97bab4cc87 ("build: replace autotools with meson & ninja")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-12 12:32:33 +02:00
Bartosz Golaszewski
97bab4cc87 build: replace autotools with meson & ninja
Port the project from autotools to meson. All build options are
preserved with the same semantics.

The goal of this change is to produce the same set of files as the
current autotools approach: libraries with correct SONAME/version,
headers, pkg-config files, GObject introspection data, Python extension
modules, D-Bus interface and configuration files. This is done to enable
a one-liner test command running all available test suites.

The only thing we drop is the `make docs` target as it's rarely used and
docs can be generated easily with sphinx directly. They are also not
required for testing.

The Rust workspace is built via a custom target that invokes cargo and
uses SYSTEM_DEPS_* environment variables to point the libgpiod-sys and
gpiosim-sys crates at the locally built C libraries.

In addition to porting the build files to meson, update the docs, remove
unneded items from .gitignore files (or remove them entirely if they're
no longer needed) and update the shunit2 test scripts to no longer care
about source directories.

Tested-by: Erik Wierich <erik@riscstar.com>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260428-meson-build-v3-1-8da6976fb0a2@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-05-04 09:51:03 +02:00
Bartosz Golaszewski
aff7a6143b dbus: manager: use the correct loop counter in error path
In gpiodbus_daemon_export_lines(), the daemon iterates over all GPIO
lines on a chip and establishes kernel watch file descriptors for
line-info events. On failure, it attempts to clean up previously
established watches but it uses i instead of j to refer to the line it
wants to unwatch. Use the correct counter variable for the inner loop.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Reported-by: 4fqr <4fqr@proton.me>
Tested-by: Vincent Fazio <vfazio@xes-inc.com>
Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://patch.msgid.link/20260407-treewide-fixes-v1-14-66c9744a56a3@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-04-09 09:32:37 +02:00
Bartosz Golaszewski
80352a30a0 dbus: daemon: watch for "add"/"remove" uevents instead of "bind"/"unbind"
Linux has a stub driver for GPIO devices (the ones on the GPIO bus, not
their parent devices!) but it only actually *binds* to it those devices
that don't have a firmware node attached. This means that in some cases,
a "dynamic" GPIO controller can remain unnoticed by gpio-manager.

This behavior is related to fw_devlink handling and - even if we changed
the kernel to bind all GPIO devices to the stub driver - a fix in
gpio-manager is easier to distribute than a kernel fix.

Since an *added* GPIO device is considered functional, even without
binding to the stub driver, we can rely on the "add"/"remove" uevent
pair when detecting when GPIO chips come and go.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Reported-by: David Lechner <dlechner@baylibre.com>
Closes: https://github.com/brgl/libgpiod/issues/175
Tested-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20260218-gpio-manager-bind-vs-add-v1-1-0fb22c448de3@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-02-20 12:41:09 +01:00
David Lechner
ec908dafcd dbus: use prefix in gpio-manager.service
Change the gpio-manager.service file to gpio-manager.service.in template
and use @prefix@ in the ExecStart line. This way, when `make install` is
used to install the service file, it points to the same path where the
binary is actually installed.

Closes: https://github.com/brgl/libgpiod/issues/173
Signed-off-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20260216213223.984050-1-dlechner@baylibre.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
2026-02-17 15:02:37 +01:00
Bartosz Golaszewski
859b3c7106 dbus: manager: don't try to export the same chip twice
It's possible to get a second bind event from udevd (for instance:
manually triggered with `udevadm trigger -c bind`) on the same GPIO
chip so it already existing in the hashmap may actually happen unlike
what the comment in daemon.c states. We must not try to export the same
chip twice as it will crash the gpio-manager on the subsequent
assertion.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Reported-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Closes: https://github.com/brgl/libgpiod/issues/161
Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20251114132957.33750-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-11-17 09:09:01 +01:00
Bartosz Golaszewski
727d07ee53 dbus: don't install generated headers
The header generated by gdbus-codegen and the library wrapper around it
are not part of the stable API so don't install them.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-10-01 15:30:36 +02:00
Bartosz Golaszewski
6c4812be6a dbus: gpiocli: display the libgpiod package version for --version
Currently gpiocli does not display the libgpiod API version in the
output of gpiocli --version because it's not linked against libgpiod -
it's only a consumer of the DBus API.

However, with the recent changes to the versioning scheme and the
disassociation of the core C API from the libgpiod package version, it
now makes sense to display the latter so add it.

Acked-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250903-api-version-detach-v1-7-027ca5928518@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-09 10:24:00 +02:00
Bartosz Golaszewski
5204b44f83 dbus: manager: display C API *and* libgpiod package version for '-v'
With the recent changes to the versioning scheme and the disassociation
of the core C API from the libgpiod package version, it now makes sense
to display both in the output of 'gpio-manager --version'.

Acked-by: Erik Wierich <erik@riscstar.com>
Link: https://lore.kernel.org/r/20250903-api-version-detach-v1-6-027ca5928518@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-09-09 10:24:00 +02:00
Bartosz Golaszewski
91955a1f93 dbus: improve comments in API xml
The current comments don't follow any particular formatting so the
resulting .rst generated with gdbus-codegen is all mangled up. Use
proper .rst formatting to make docs better.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20250211-improve-docs-v4-10-dc56702c2ca8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-17 09:18:07 +01:00
Bartosz Golaszewski
1ddfa9fc4b dbus: client: tweak help text
help2man struggles to generate correct output with current help-text for
the sub-commands section. It doesn't break the lines correctly and the
resulting .rst generated with pandoc looks just as bad. Tweak the output
a bit to generate better man pages with correctly broken lines.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20250211-improve-docs-v4-9-dc56702c2ca8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-17 09:18:04 +01:00
Bartosz Golaszewski
681c0c2767 dbus: daemon: add a more detailed description to help text
In preparation for adding man pages for the daemon and the command-line
client, add a detailed description of what gpio-manager is and does to
the output presented to user when they pass --help as argument.

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20250211-improve-docs-v4-8-dc56702c2ca8@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-17 09:18:01 +01:00
Bartosz Golaszewski
f52874b19b dbus: client: tests: fix the way we wait for simulated chips to appear
The org.freedesktop.DBus.Peer.Ping() method isn't correct for checking
if a given object is exposed by a service. It only lets us know if the
service is available no matter the object on which it's called (in fact:
it will not return an error even if it's called on a nonexistent object).

While this has worked for most part by accident, if the timing isn't
right, we may start calling methods in chips which are not yet fully
registered. We should try to read the chip's property instead and keep
on waiting for as long as org.freedesktop.DBus.Properties.Get() returns
an error.

While at it: fix the counter increment as its syntax is invalid.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://lore.kernel.org/r/20250203-fix-dbus-wait-for-chip-v1-1-563f7132c04f@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2025-02-05 10:50:14 +01:00
Bartosz Golaszewski
91b7811955 dbus: data: fix SPDX license identifier in D-Bus config file
Remove the .txt file extension from the license identifier as it got
there by mistake and makes `reuse lint` complain.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-15 20:37:13 +02:00
Bartosz Golaszewski
cfbaa54427 dbus: display D-Bus API versions implemented by the manager and gpiocli
When passing -v/--version to gpiocli or gpio-manager, it's useful to
also know the version of the GPIO D-Bus API the program implements.
Define the version in the gpiodbus.h header and print it together with
the library version.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-14 15:13:28 +02:00
Bartosz Golaszewski
392cae9e42 dbus: client: monitor: free the line list at exit
Free the list of line proxies stored for the duration of the program at
exit to fix a memory leak.

Note: these objects need to be kept alive for D-Bus events to work.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://lore.kernel.org/r/20241007-dbus-memory-fixes-v1-3-0d56d1aa032d@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-09 09:33:36 +02:00
Bartosz Golaszewski
85471d394b dbus: client: notify: free chip and line lists at exit
We don't free the lists storing line and chip objects for the duration
of the program when exiting. Fix it.

Note: these objects need to be kept alive for D-Bus events to work.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://lore.kernel.org/r/20241007-dbus-memory-fixes-v1-2-0d56d1aa032d@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-09 09:33:36 +02:00
Bartosz Golaszewski
c87847b23b dbus: client: notify: fix reference counting
There's a reference overflow when adding chips to the global list and an
underflow when fetching existing chips from that list in connect_line().
Fix both issues.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Link: https://lore.kernel.org/r/20241007-dbus-memory-fixes-v1-1-0d56d1aa032d@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-09 09:33:36 +02:00
Bartosz Golaszewski
4722e901ed dbus: include data and test files in dist tarballs
Several data and test files were not included in distro tarballs so add
"dist_" automake variable prefixes where required.

Fixes: a5ab76da1e ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-02 17:40:47 +02:00
Bartosz Golaszewski
6dfca9a39a dbus: client: fix format specifiers for 64-bit types
Use G_GUINT64_FORMAT whenever printing 64-bit types to avoid format
specifier warnings.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-01 20:07:48 +02:00
Bartosz Golaszewski
2df6347c08 dbus: use correct types for edge events
On 32-bit architectures the size of a gulong will typically be 4 bytes
while we try to package an 8-byte integer when creating the edge event
variant. The client also expects wrong types and crashes. Use strict
type sizes for sending the events.

Closes: https://github.com/brgl/libgpiod/issues/103
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-10-01 20:07:47 +02:00
Bartosz Golaszewski
a5ab76da1e dbus: add the D-Bus daemon, command-line client and tests
Add the D-Bus API definition and its implementation in the form of a GPIO
manager daemon and a companion command-line client as well as some
additional configuration and data files (systemd service, example udev
configuration, etc.) and test suites.

Tested-by: Alexander Sverdlin <alexander.sverdlin@siemens.com>
Link: https://lore.kernel.org/r/20240812-dbus-v5-4-ead288509217@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
2024-08-13 10:45:25 +02:00