Sample Header Ad - 728x90

Communicate with UNIX sockets opened by dbus-daemon

0 votes
1 answer
509 views
I'm trying to learn how to interact with message buses under Linux, and doing so with shell commands that doesn't involve utilities packaged under dbus-*. For this instance, I want to understand how socket opened by dbus-daemon are interpreted, and how the socket behaves in response to some user input. (e.g, send commands and receive a response output) For the "reference implementation", namely dbus-daemon, looking at its user configuration file (session.conf) under /usr/share/dbus-1, the daemon opens an UNIX domain socket and listens on in based on transport names and subsequent options in the ` directive. By default, it is set to the transport name unix with a tmpdir set to /tmp. Modifying the line with path in place of tmpdir to where the socket must reside in disk, a socket file by the respective path is created by running dbus-deamon` as:
$ sudo dbus-daemon --session
By querying lsof to list open sockets
sudo lsof -c dbus-daemon -aU -a +E
it indeed lists the path that was written on the configuration file. Now, I want to interact with the socket by sending it some data and inspecting its response. So far, I've tried netcat and socat.
$ echo  | nc -U /tmp/socket -v
$ echo  | socat - /tmp/socket
2024/12/12 22:55:47 socat E read(5, 0x61fb9e544000, 8192): Connection reset by peer
While netcat returns with nothing, I get a "connection reset by peer" error from socat when "" is being piped out and it is a string of words. Instead, if the input is a newline or a blank, socat exits successfully (however with no output). It makes me suspect a formatting problem of the input that the socket may accept. I also tried configuring the daemon to open a TCP connection in the loopback address on port randomized by the kernel by setting port=0 (as mentioned in the manpage). Going by the output of lsof, I resolved the port which it's listening on.
$ echo  | nc localhost 39231
nc: connect to localhost (::1) port 39231 (tcp) failed: Connection refused
Connection to localhost (127.0.0.1) 39231 port [tcp/*] succeeded!
Returns with connection refused. It would be of help if anyone can explain: 1. The command interface for interacting with listening sockets 2. The right approach to send data to the socket 3. If it's possible to get a reply from the socket.
Asked by PatXio (1 rep)
Dec 12, 2024, 07:26 PM
Last activity: Dec 13, 2024, 06:16 AM