text
stringlengths
0
234
by sending each file descriptor with
.br sendmsg (2)
and then closing the file descriptor so that it was not accounted against the
.b rlimit_nofile
resource limit.
.pp
other errors can be generated by the generic socket layer or
by the filesystem while generating a filesystem socket object.
see the appropriate manual pages for more information.
.sh versions
.b scm_credentials
and the abstract namespace were introduced with linux 2.2 and should not
be used in portable programs.
(some bsd-derived systems also support credential passing,
but the implementation details differ.)
.sh notes
binding to a socket with a filename creates a socket
in the filesystem that must be deleted by the caller when it is no
longer needed (using
.br unlink (2)).
the usual unix close-behind semantics apply; the socket can be unlinked
at any time and will be finally removed from the filesystem when the last
reference to it is closed.
.pp
to pass file descriptors or credentials over a
.br sock_stream
socket, you must
send or receive at least one byte of nonancillary data in the same
.br sendmsg (2)
or
.br recvmsg (2)
call.
.pp
unix domain stream sockets do not support the notion of out-of-band data.
.\"
.sh bugs
when binding a socket to an address,
linux is one of the implementations that appends a null terminator
if none is supplied in
.ir sun_path .
in most cases this is unproblematic:
when the socket address is retrieved,
it will be one byte longer than that supplied when the socket was bound.
however, there is one case where confusing behavior can result:
if 108 non-null bytes are supplied when a socket is bound,
then the addition of the null terminator takes the length of
the pathname beyond
.ir sizeof(sun_path) .
consequently, when retrieving the socket address
(for example, via
.br accept (2)),
.\" the behavior on solaris is quite similar.
if the input
.i addrlen
argument for the retrieving call is specified as
.ir "sizeof(struct sockaddr_un)" ,
then the returned address structure
.i won't
have a null terminator in
.ir sun_path .
.pp
in addition, some implementations
.\" i.e., traditional bsd
don't require a null terminator when binding a socket (the
.i addrlen
argument is used to determine the length of
.ir sun_path )
and when the socket address is retrieved on these implementations,
there is no null terminator in
.ir sun_path .
.pp
applications that retrieve socket addresses can (portably) code
to handle the possibility that there is no null terminator in
.ir sun_path
by respecting the fact that the number of valid bytes in the pathname is:
.pp
strnlen(addr.sun_path, addrlen \- offsetof(sockaddr_un, sun_path))
.\" the following patch to amend kernel behavior was rejected:
.\" http://thread.gmane.org/gmane.linux.kernel.api/2437
.\" subject: [patch] fix handling of overlength pathname in af_unix sun_path
.\" 2012-04-17
.\" and there was a related discussion in the austin list:
.\" http://thread.gmane.org/gmane.comp.standards.posix.austin.general/5735
.\" subject: having a sun_path with no null terminator
.\" 2012-04-18
.\"
.\" fixme . track http://austingroupbugs.net/view.php?id=561
.pp
alternatively, an application can retrieve
the socket address by allocating a buffer of size
.i "sizeof(struct sockaddr_un)+1"
that is zeroed out before the retrieval.
the retrieving call can specify
.i addrlen
as
.ir "sizeof(struct sockaddr_un)" ,
and the extra zero byte ensures that there will be
a null terminator for the string returned in
.ir sun_path :
.pp