Discussion:
[systemd-devel] socket activation socket state
Ted Toth
2021-05-28 18:26:57 UTC
Permalink
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? 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.

Ted
Mantas Mikulėnas
2021-05-28 20:05:00 UTC
Permalink
Post by Ted Toth
When a socket service runs is there a way to determine the socket
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
Post by Ted Toth
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...
Post by Ted Toth
Ted
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
Mantas Mikulėnas
Loading...