[systemd-devel] socket activation socket state

Mantas Mikulėnas grawity at gmail.com
Fri May 28 20:05:00 UTC 2021


On Fri, 28 May 2021 at 21:27, Ted Toth <txtoth at gmail.com> wrote:

> When a socket service runs is there a way to determine the socket
> state? If the socket file contains:
> Accept=true
>
> does systemd call accept with the socket before execing the service in
> which case I don't have to call accept?


Yes, with Accept=yes (similar to inetd’s “nowait”) systemd itself will
accept connections and will start a separate instance of your templated
service per connection.

With Accept=no you get the listening socket instead and a single
non-templated service handles everything.

Is there a way to
> differentiate a socket with Accept set to true versus one without
> Accept or with it set to false? I've read the sd_is_socket man page
> but it's not clear to me if it can answer the question I posed.


Normally a service would just expect to be given one or the other... But I
think you can use this getsockopt(SO_ACCEPTCONN) to check:
https://stackoverflow.com/q/10260600

You could also just try calling accept() on it, I guess...



>
> Ted
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
-- 
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20210528/d4475242/attachment-0001.htm>


More information about the systemd-devel mailing list