On Thu, Jun 27, 2019 at 1:29 PM Donat Zenichev <[email protected]> wrote:
> Hi systemd community. > Recently I've come accross one interesting problem with API of systemd. > 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. > > What actually program requires, is AF_UNIX (AF_LOCAL) socket of type > SOCK_STREAM. > In case if I create this socket manually, using socket(AF_LOCAL, > SOCK_STREAM, 0) function, it works out as expected. > > But, when I create a socket using systemd socket unit, reading fails with > "-1" return value. > > 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), > program goes further and sets a file descriptor value to fd = > SD_LISTEN_FDS_START + 0; > Since the SD_LISTEN_FDS_START is pre-defined to value '3', my file > descriptor will always be '3'. > > But when it comes to reading, with read() function, it fails with the > errno EINVAL - Invalid argument. > 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. > > An initializing of the socket descriptor, when creating it by systemd > passes as normal, so program starts. > But any further command received on fd fails with '-1' return value. > 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 accept() each connection first. -- Mantas Mikulėnas
_______________________________________________ systemd-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/systemd-devel
