Created
January 10, 2026 09:52
-
-
Save jasalt/2bd15809a370e0c89a0e28bc59cdb500 to your computer and use it in GitHub Desktop.
"Awaiting" D-Bus message in Bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Senging expected message: | |
| # dbus-send --session --type=signal /org/example/Test org.example.Test.TestSignal | |
| set -euo pipefail | |
| # Match the precise signal we’re interested in. | |
| MATCH="type='signal',interface='org.example.Test',member='TestSignal'" | |
| # Create a temporary FIFO to capture dbus-monitor output line-by-line. | |
| FIFO=$(mktemp -u) | |
| mkfifo "$FIFO" | |
| cleanup() { | |
| rm -f "$FIFO" | |
| } | |
| trap cleanup EXIT | |
| # Start dbus-monitor with a timeout so we don’t block forever. | |
| timeout 15s dbus-monitor --session "$MATCH" >"$FIFO" & | |
| MON_PID=$! | |
| # Consume the monitor output; react only when the actual signal arrives. | |
| while IFS= read -r line; do | |
| [[ $line == *"member=TestSignal"* ]] || continue | |
| echo "Signal received" | |
| kill "$MON_PID" >/dev/null 2>&1 || true | |
| exit 0 | |
| done <"$FIFO" | |
| # If we fall out of the loop, the monitor ended (timeout or other error). | |
| wait "$MON_PID" >/dev/null 2>&1 || true | |
| echo "Timed out without signal" | |
| exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment