<div dir="ltr"><div dir="ltr">On Thu, Jun 27, 2019 at 1:29 PM Donat Zenichev <<a href="mailto:donat.zenichev@gmail.com">donat.zenichev@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi systemd community.<br>Recently I've come accross one interesting problem with API of systemd.<br>The
problem is that, I'm not able to read commands comming to the AF_UNIX
socket, that was created by systemd and passed to my program using
sd_listen_fds(0) function.<br><br>What actually program requires, is AF_UNIX (AF_LOCAL) socket of type SOCK_STREAM.<br>In case if I create this socket manually, using socket(AF_LOCAL, SOCK_STREAM, 0) function, it works out as expected.<br><br>But, when I create a socket using systemd socket unit, reading fails with "-1" return value.<br><br>What
I actually do, is that I check if there are some sockets created for me
using sd_listen_fds(0), and in case it returns 1 (so 1 socket created),<br>program goes further and sets a file descriptor value to fd = SD_LISTEN_FDS_START + 0;<br>Since the SD_LISTEN_FDS_START is pre-defined to value '3', my file descriptor will always be '3'.<br><br>But when it comes to reading, with read() function, it fails with the errno EINVAL - Invalid argument.<br>It's not a matter of a other parameters than a file descriptor, since with manual creation of socket it works out as I said.<br><br>An initializing of the socket descriptor, when creating it by systemd passes as normal, so program starts.<br>But any further command received on fd fails with '-1' return value.<br></div></blockquote><div><br></div><div>As this is a stream socket, by default the program will receive the *listener* socket. Systemd will start your service as soon as someone connects, but your program still needs to <font face="courier new, monospace">accept()</font> each connection first.</div><div><br></div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div></div>