aboutsummaryrefslogtreecommitdiffstats
path: root/src/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bus.c')
-rw-r--r--src/bus.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/bus.c b/src/bus.c
index 5875b2b..f4f62c2 100644
--- a/src/bus.c
+++ b/src/bus.c
@@ -629,6 +629,12 @@ fail:
* * 0: stop listening
* * 1: continue listening
* * -1: an error has occurred
+ * However, the function [`bus_read`] will invoke
+ * `callback` with `message` one time directly after
+ * it has started listening on the bus. This is to
+ * the the program now it can safely continue with
+ * any action that requires that the programs is
+ * listening on the port.
* @return 0 on success, -1 on error
*/
int
@@ -636,6 +642,11 @@ bus_read(const bus_t *bus, int (*callback)(const char *message, void *user_data)
{
int r;
t(release_semaphore(bus, S, SEM_UNDO));
+ t(r = callback(NULL, user_data));
+ if (!r) {
+ t(acquire_semaphore(bus, S, SEM_UNDO));
+ return 0;
+ }
for (;;) {
t(release_semaphore(bus, Q, 0));
t(zero_semaphore(bus, Q));