[systemd-devel] Why systemd keeps references on passed sockets ?

Francis Moreau francis.moro at gmail.com
Tue Sep 8 15:35:53 UTC 2020


On Mon, Sep 7, 2020 at 4:38 PM Lennart Poettering
<lennart at poettering.net> wrote:
>
> "React on the socket close?" — What do you mean by that?
>

I mean if my service explicitly calls close() then systemd could stop
the socket on its side so its are freed until the service is
restarted. I think it is what you described below.

> Note that on Linux you can invoke shutdown() on a listening socket
> (i.e. not just on the connection socket, but on a listening
> socket). iirc in that case systemd actually notices and will put the
> .socket unit in failure mode...
>

I looked at the code and there is:

    if (state != SOCKET_LISTENING)
        socket_unwatch_fds(s);

So I'm not sure how systemd can react on shutdown(). And I tried to
call shutdown() in my service but it has no effects.

> Would that work for you? (Maybe we could even tweak this a bit in
> systemd, so that when you invoke shutdown() on the socket systemd
> holds for you we do not consider that a failure anymore, but a clean
> way to tell systemd to stop the socket).

That is a good idea especially if systemd doesn't consider an error
when the service closes or shutdown the socket.

But again in the code I can see:

  sd_event_add_io(UNIT(s)->manager->event, &p->event_source, p->fd,
EPOLLIN, socket_dispatch_io, p);

It seems that it only listens to "EPOLLIN" events. So it doesn't
listen to "EPOLLUP".

Thank you.
-- 
Francis


More information about the systemd-devel mailing list