Commit Graph

269 Commits

Author SHA1 Message Date
Anderson Lizardo 29110ab56b gdbus: Fix using NULL DBusPendingCall when disconnected from D-Bus
From D-Bus documentation for dbus_connection_send_with_reply():

"Warning: if the connection is disconnected or you try to send Unix file
descriptors on a connection that does not support them, the
DBusPendingCall will be set to NULL, so be careful with this."

Fix these errors when killing D-Bus daemon with the client still
running:

process 5712: arguments to dbus_pending_call_set_notify() were
incorrect, assertion "pending != NULL" failed in file
../../dbus/dbus-pending-call.c line 596.
This is normally a bug in some application using the D-Bus library.
process 5712: arguments to dbus_pending_call_unref() were incorrect,
assertion "pending != NULL" failed in file
../../dbus/dbus-pending-call.c line 572.
This is normally a bug in some application using the D-Bus library.
2026-04-20 14:50:25 +08:00
Anderson Lizardo 30f1a3707a gdbus: Fix segfault when D-Bus daemon exits
Fix this crash if D-Bus exits while the client is still connected to it:

==5570== Invalid read of size 1
==5570==    at 0x402D28E: strcmp (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==5570==    by 0x4070E22: g_str_equal (ghash.c:1704)
==5570==    by 0x8055F61: message_filter (client.c:1123)
==5570==    by 0x4141500: dbus_connection_dispatch (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==5570==    by 0x80506F7: message_dispatch (mainloop.c:76)
==5570==    by 0x4081A7E: g_timeout_dispatch (gmain.c:3882)
==5570==    by 0x4080D85: g_main_context_dispatch (gmain.c:2539)
==5570==    by 0x4081124: g_main_context_iterate.isra.21 (gmain.c:3146)
==5570==    by 0x408156A: g_main_loop_run (gmain.c:3340)
==5570==    by 0x41BF4D2: (below main) (libc-start.c:226)
==5570==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==5570==
==5570==
2026-04-20 14:50:25 +08:00
Luiz Augusto von Dentz 3329f1a1ba gdbus: Fix calling GetManagedObjects twice in a row
Calling g_dbus_client_new followed by g_dbus_client_set_proxy_handlers
cause two calls to GetManagedObjects in a row as GetNameOwner reply is
asyncronously it triggers the second call because the handlers have
been set by g_dbus_client_set_proxy_handlers.
2026-04-20 14:50:25 +08:00
Lucas De Marchi 9e04a31af5 gdbus: Use gcc builtin instead of g_atomic
g_atomic_* end up using G_STATIC_ASSERT, causing gcc 4.8 to yell due to
-Wunused-local-typedefs.

gdbus/client.c: In function ‘g_dbus_client_ref’:
/usr/include/glib-2.0/glib/gmacros.h:162:53: error: typedef ‘_GStaticAssertCompileTimeAssertion_2’ locally defined but not used [-Werror=unused-local-typedefs]
 #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]
2026-04-20 14:50:25 +08:00
Luiz Augusto von Dentz 868180af63 gdbus: Fix not calling property_changed callback
In case a property did not appear by the time proxy_added was called
property_changed has to be called if it appear latter otherwise the
application will be unaware of it.
2026-04-20 14:50:25 +08:00
Tomasz Bursztyka 2f881b023e gdbus: Always unreference the message in g_dbus_send_message()
A quick fix on g_dbus_send_message(), if check_signal() fails it returns
FALSE without unreferencing the message as it should. This patch fixes
it.
2026-04-20 14:50:25 +08:00
Denis Kenzior fd8ca0583b gdbus: Add g_dbus_proxy_set_removed_watch 2026-04-20 14:50:25 +08:00
Vinicius Costa Gomes 1e52a044b4 gdbus: Fix missing PropertiesChanged signal
If D-Bus ObjectManager is not supported, InterfacesAdded signal
checking needs to be ignored otherwise PropertiesChanged signal
will never be sent.
2026-04-20 14:50:25 +08:00
Marcel Holtmann 9926e9408a gdbus: Don't call property changed callback during client init
When the client uses ObjectManager to init properties, do not call
property changed callbacks. They should only be called once the proxy
added has been successfully signaled since the proxy itself provides
a full copy of available properties.
2026-04-20 14:50:25 +08:00
Johan Hedberg c1feb11966 gdbus: Fix unpublished interface signal emission
If we haven't published an interface yet (i.e. it's in the data->added
list), we should just ignore any property changed indications as the
values for the properties will anyway be part of the InterfacesAdded
signal.
2026-04-20 14:50:25 +08:00
Marcel Holtmann ff3b1dd5ed gdbus: Check for valid path before handling properties 2026-04-20 14:50:25 +08:00
Anderson Lizardo cb6ee55138 gdbus: Fix memory leak on properties_set()
The pointer returned by dbus_message_iter_get_signature() must be freed
with dbus_free().

Fixes this memory leak:

==1857== 16 bytes in 1 blocks are definitely lost in loss record 104 of
251
==1857==    at 0x402BF52: realloc (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1857==    by 0x415E286: dbus_realloc (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x415E70B: ??? (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x415F17B: ??? (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x414CB33: dbus_message_iter_get_signature (in
/lib/i386-linux-gnu/libdbus-1.so.3.5.8)
==1857==    by 0x8053239: properties_set (object.c:899)
==1857==    by 0x5FFFFF: ???
==1857==
2026-04-20 14:50:25 +08:00
Marcel Holtmann ee4f591eea gdbus: Check signature of property value before calling setter 2026-04-20 14:50:25 +08:00
Lucas De Marchi 133dc5f59c gdbus: Don't include just added interfaces in GetManagedObjects
If we received a call to ObjectManager.GetManagedObject we should not
include in the response the interfaces in data->added. This is because
it's not guaranteed that those interfaces will trigger an
InterfacesAdded signal, which is the case if the interface is removed in
the same mainloop iteration.
2026-04-20 14:50:25 +08:00
Lucas De Marchi 5f3ea0bc08 gdbus: Simplify generated introspection
The generated introspection is not supposed to be read as is by human,
so there's no point in printing the indentation or writing more code to
use auto-close tags.

If it's desired to read the raw xml file, user can always use other
tools to transform the output such as "xmllint --format".

This also fixes a missing </property> when property is deprecated.
2026-04-20 14:50:25 +08:00
Marcel Holtmann d1f969489f gdbus: Hold client reference during get name owner reply 2026-04-20 14:50:24 +08:00
Luiz Augusto von Dentz 2c1ef3134e gdbus: Call check_signals when sending signals with g_dbus_send_message
If message passed to g_dbus_send_message is a signal verify if it is a
valid and there really exists an interface with respective signal name.
2026-04-20 14:50:24 +08:00
Luiz Augusto von Dentz 743f7a45de gdbus: Check if the interface being registered is valid
This prevent registering interfaces that are empty or have all members
marked as experiemental.
2026-04-20 14:50:24 +08:00
Luiz Augusto von Dentz e42bd2c499 gdbus: Introduce G_DBUS_PROPERTY_FLAG_EXPERIMENTAL
This flag can be used to mark properties as experimental, marked
properties are disabled by default and can be enabled by setting
G_DBUS_FLAG_ENABLE_EXPERIMENTAL using g_dbus_set_flags.
2026-04-20 14:50:24 +08:00
Luiz Augusto von Dentz 1f1e3bacc0 gdbus: Introduce G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
This flag can be used to mark signals as experimental, marked
signals are disabled by default and can be enabled by setting
G_DBUS_FLAG_ENABLE_EXPERIMENTAL using g_dbus_set_flags.
2026-04-20 14:50:24 +08:00
Luiz Augusto von Dentz 9665b30c35 gdbus: Introduce G_DBUS_METHOD_FLAG_EXPERIMENTAL
This flag can be used to mark methods as experimental, marked
methods are disable by default and can be enabled by setting
G_DBUS_FLAG_ENABLE_EXPERIMENTAL using g_dbus_set_flags.
2026-04-20 14:50:24 +08:00
Marcel Holtmann 1d8f9add4f gdbus: Include changed properties only once per signal 2026-04-20 14:50:24 +08:00
Marcel Holtmann 8d63a2cdd4 gdbus: Update properties on D-Bus client re-connections 2026-04-20 14:50:24 +08:00
Marcel Holtmann 7ca3a1af97 gdbus: Add function to manually refresh properties 2026-04-20 14:50:24 +08:00
Marcel Holtmann c3c5491c80 gdbus: Add support for proxy property change notifications 2026-04-20 14:50:24 +08:00
Marcel Holtmann 8e72d42921 gdbus: Fix handling of client connect/disconnect signals 2026-04-20 14:50:24 +08:00
Marcel Holtmann ccfb46e665 gdbus: Protect standalone proxy creation with client reference 2026-04-20 14:50:24 +08:00
Marcel Holtmann 54bbe54320 gdbus: Use object manager only if callback functions are set 2026-04-20 14:50:24 +08:00
Marcel Holtmann 0dba02a469 gdbus: Use client service name and not hardcoded org.bluez 2026-04-20 14:50:24 +08:00
Marcel Holtmann 3996477b10 gdbus: Add support for creating D-Bus proxies without object manager 2026-04-20 14:50:24 +08:00
Marcel Holtmann 64c1838854 gdbus: Avoid using g_ptr_array_new_full convenience function
The g_ptr_array_new_full function only got introduced with GLib 2.30
and to avoid requiring a newer GLib use g_ptr_array_set_free_func instead.
2026-04-20 14:50:24 +08:00
Marcel Holtmann 4e136236b7 gdbus: Increase the method call timeout to 5 minutes 2026-04-20 14:50:24 +08:00
Marcel Holtmann f07eae8d44 gdbus: Add helper for sending async error replies 2026-04-20 14:50:24 +08:00
Marcel Holtmann 7de9641956 gdbus: Fix race condition with creating duplicate client proxies 2026-04-20 14:50:24 +08:00
Marcel Holtmann eaf85c24af gdbus: Fix issue with unref of client while parsing interfaces 2026-04-20 14:50:24 +08:00
Marcel Holtmann da15994542 gdbus: Fix issue with unref of client in connect handler 2026-04-20 14:50:24 +08:00
Marcel Holtmann fefd725ae4 gdbus: Add support for D-Bus client method calls 2026-04-20 14:50:24 +08:00
Marcel Holtmann 9e83020ee6 gdbus: Add callback support for handling property changes 2026-04-20 14:50:24 +08:00
Marcel Holtmann b598aa98cc gdbus: Handle property changed signals and update property 2026-04-20 14:50:24 +08:00
Marcel Holtmann 9f8a14f3b6 gdbus: Set property changed filter match rule for each proxy 2026-04-20 14:50:24 +08:00
Marcel Holtmann 71922cffb7 gdbus: Use a GPtrArray for the match rules 2026-04-20 14:50:24 +08:00
Marcel Holtmann f3449902c8 gdbus: Add support for setting D-Bus client basic properties 2026-04-20 14:50:24 +08:00
Marcel Holtmann 5aca075659 gdbus: Deep copy of variants also requires a signature 2026-04-20 14:50:24 +08:00
Marcel Holtmann feb46aa051 gdbus: Add support for complex D-Bus client properties 2026-04-20 14:50:23 +08:00
Marcel Holtmann 874e27aa36 gdbus: Add support for D-Bus client properties 2026-04-20 14:50:23 +08:00
Marcel Holtmann 5d49da13d4 gdbus: Add support for D-Bus client proxies 2026-04-20 14:50:23 +08:00
Marcel Holtmann e8987c5322 gdbus: Add helper functions for simple D-Bus clients 2026-04-20 14:50:23 +08:00
Johan Hedberg 5fea097260 Revert "Ensure config.h is included by using CPPFLAGS"
This reverts commit 76919ad7f431167cecdd3d608c1465961aa75423.

The patch needs to be split up and the gdbus/ changes were bogus
compared to the original commit message.

Conflicts:
	Makefile.am
	Makefile.obexd
	profiles/cyclingspeed/cyclingspeed.c
	profiles/heartrate/heartrate.c
	src/error.c
2026-04-20 14:50:23 +08:00
Lucas De Marchi cf6b8a5c15 Ensure config.h is included by using CPPFLAGS
Instead of trying to include config.h in each file over the tree and
possibly forgetting to include it, give a "-include config.h" argument
to the compiler so it's guaranteed that a) it will be included for all
source files and b) it will be the first header included.

gdbus/ directory is left out, since it would break other projects using
it.
2026-04-20 14:50:23 +08:00
Luiz Augusto von Dentz 7a059566f0 gdbus: Add g_dbus_add_properties_watch function
Convenient function to create watches for D-Bus properties.
2026-04-20 14:50:23 +08:00