Hi Bartosz! On Mon, 2024-08-12 at 10:22 +0200, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> > > 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@xxxxxxxxxxx> > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> [] > diff --git a/dbus/client/wait.c b/dbus/client/wait.c > new file mode 100644 > index 0000000..d65c4e7 > --- /dev/null > +++ b/dbus/client/wait.c > @@ -0,0 +1,188 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +// SPDX-FileCopyrightText: 2023 Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx> > + > +#include <stdlib.h> > + > +#include "common.h" > + > +typedef struct { > + gboolean name_done; > + gboolean chip_done; > + const gchar *label; > +} WaitData; > + > +static void obj_match_label(GpiodbusObject *chip_obj, WaitData *data) > +{ > + GpiodbusChip *chip = gpiodbus_object_peek_chip(chip_obj); > + > + if (g_strcmp0(gpiodbus_chip_get_label(chip), data->label) == 0) > + data->chip_done = TRUE; > +} > + > +static void check_label(gpointer elem, gpointer user_data) > +{ > + WaitData *data = user_data; > + GpiodbusObject *obj = elem; > + > + obj_match_label(obj, data); > +} > + > +static void on_object_added(GDBusObjectManager *manager G_GNUC_UNUSED, > + GpiodbusObject *obj, gpointer user_data) > +{ > + WaitData *data = user_data; > + > + obj_match_label(GPIODBUS_OBJECT(obj), data); > +} > + > +static void wait_for_chip(WaitData *data) > +{ > + g_autoptr(GDBusObjectManager) manager = NULL; > + g_autolist(GpiodbusObject) objs = NULL; > + > + manager = get_object_manager_client("/io/gpiod1/chips"); > + > + g_signal_connect(manager, "object-added", > + G_CALLBACK(on_object_added), data); > + > + objs = g_dbus_object_manager_get_objects(manager); > + g_list_foreach(objs, check_label, data); Strange, I'd expect from this code to detect pre-existing chips immediately, but this is not what I observe in practice: $ gpiocli info --chip=gpiochip0 | head -n 1 gpiochip0 - 24 lines: $ gpiocli wait --chip=gpiochip0 --timeout=1 gpiocli wait: wait timed out! (without timeout it would wait endlessly) This is not expected, right, otherwise it would be counter-intuitive and racy? -- Alexander Sverdlin Siemens AG www.siemens.com