[systemd-devel] [PATCH] Describe handling of an AF_UNIX socket

Umut Tezduyar umut at tezduyar.com
Fri Jun 21 05:05:08 PDT 2013


On Fri, Jun 21, 2013 at 10:07 AM, Łukasz Stelmach
<l.stelmach at samsung.com> wrote:
> It was <2013-06-20 czw 20:57>, when Lennart Poettering wrote:
>> On Wed, 19.06.13 14:59, Łukasz Stelmach (l.stelmach at samsung.com) wrote:
>>
>>> Describe how to handle an AF_UNIX socket, with Accept set to false,
>>> received from systemd, upon exit.
>>>
>>> Signed-off-by: Łukasz Stelmach <l.stelmach at samsung.com>
>>> ---
>>>  man/systemd.socket.xml |   12 +++++++++---
>>>  1 file changed, 9 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
>>> index 6dc847d..f1e7d40 100644
>>> --- a/man/systemd.socket.xml
>>> +++ b/man/systemd.socket.xml
>>> @@ -381,9 +381,15 @@
>>>                                  performance reasons, it is recommended
>>>                                  to write new daemons only in a way
>>>                                  that is suitable for
>>> -                                <option>Accept=false</option>. This
>>> -                                option is mostly useful to allow
>>> -                                daemons designed for usage with
>>> +                                <option>Accept=false</option>. A daemon
>>> +                                listening on an AF_UNIX socket may, but does not need to, call
>>> +                                <citerefentry><refentrytitle>close</refentrytitle><manvolnum>2</manvolnum></citerefentry>
>>> +                                or
>>> +                                <citerefentry><refentrytitle>shutdown</refentrytitle><manvolnum>2</manvolnum></citerefentry>
>>> +                                on the received socket before exiting. However,
>>> +                                it must not unlink the socket from a
>>> +                                filesystem. This option is mostly useful
>>> +                                to allow daemons designed for usage with
>>
>> Hmm, calling shutdown() on a listening socket will actually do weird
>> things from which we cannot recover. Calling shutdown() is fine if you
>> do it on connection sockets, but not for listening sockets. (or in other
>> words: it's OK for Accept=yes, but not for Accept=no sockets.
>
> Does this mean close(sockfd) is not the same as
> shutdown(sockfd, SHUT_RDWR)? I've always thought it is.
The scope of close is per process and the scope of shutdown is per
socket. If 2 processes are sharing a socket fd and one is closing it
with close() doesn't stop other one reading/writing on it. On the
other hand, calling shutdown is no way going back. Especially if you
shutdown with shut_rdwr, I believe kernel will send the tcp finish
package once there is no data to send in the socket buffer.
>
> --
> Łukasz Stelmach
> Samsung R&D Institute Poland
> Samsung Electronics
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list