#1056361 socat: should provide a way to wait until a listening socket is ready

Package:
socat
Source:
socat
Description:
multipurpose relay for bidirectional data transfer
Submitter:
Michael Gold
Date:
2023-11-21 17:24:03 UTC
Severity:
normal
#1056361#5
Date:
2023-11-21 17:15:12 UTC
From:
To:
While there are several ways to create listening sockets via socat, I've
been unable to find a good way to make a script wait for socat to set up
that socket.  For example, the manual page gives this command:
    socat UNIX-LISTEN:/tmp/.X11-unix/X1,fork \
    SOCKS4:host.victim.org:127.0.0.1:6000,socksuser=nobody,sourceport=20

I might want to put something like that in a script, and immediately run
"DISPLAY=:1 xmessage test" to use the connection.  If I put a "&" at the
end of the socat command, it could fail to listen without me knowing, or
xmessage might fail because it runs before the socket's ready.  Adding a
"sleep" command usually works but can't be considered reliable.  I guess
with 2 "-d" options I could parse stderr with the shell's "read" command
and look for "] N listening ".

It would be nice to have an easy way to do this.  For example, an option
that makes socat spawn a sub-process when ready, and shut down when that
sub-process exits.  Another way would be an option to make socat go into
the background when ready (but then a script would have to find some way
to kill it when done with it).

- Michael