[systemd-devel] Stopping services started by Systemd socket

Lennart Poettering lennart at poettering.net
Tue Jan 23 17:39:16 UTC 2018


On Mo, 22.01.18 20:06, Liam Kelly (liamkelly17 at gmail.com) wrote:

> How does Systemd communicate to socket activated application that
> the connection has been closed? How can I modify my application to
> detect this event if it cannot be configured to be closed
> automatically?

systemd does not. You get the original kernel socket passed and you'll
see EOF/POLLHUP on it when the connection is terminated. systemd won't
signal anything there, and in fact it's entirely up to your app to
exit or stick around after EOF/POLLHUP. 

> We are trying to add network support to legacy code using Systemd
> sockets. Using the 0pointer tutorials, we were able to configure a
> listening TCP port and launch an instance of the application when a
> TCP connection came in. The problem is that when the connection is
> closed, the service is still running.

Just call exit() from your app's sources as soon as you get read()
returning 0 on the socket (which is how the kernel reports EOF
in-line), or poll() returning POLLHUP on it (which is how the kernel
reports EOF out-of-line), depending on your context.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list