Skip to contentSkip to conversation

{unix,socket,bind}.7: General Unix Domain Socket fixes

PATCH Superseded Günther Noack 3 participants 28 messages Oct 21 – Oct 27 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover {unix,socket,bind}.7: General Unix Domain Socket fixes

Hello!

This is patch set (A) spun off from the "Documentation fixes in unix(7)" patch set [1], which is now split into these three parts:

(A) Miscellaneous fixes, mostly in unix.7, one in socket.7 <-- this one
(B) Socket options and Socket-level Control Messages (SCM_*)
(C) sock_diag.7

This patch set fixes miscellaneous inaccuracies and documents missing error codes. It applies cleanly on the current "master".

Thank you for your reviews on v1 and v2 of the still-joined patch set. Compared to v2, the following things happened:

* Some commit message rewording (especially quoted the kernel code more directly).
* In the Abstract UDS scoping commit below, reworded the subsequent paragraph sligthly to avoid confusion with the "namespace" terminology being used differently in adjacent paragraphs.
* I removed the commit that changed the wording about Out-of-Band messaging, per Kuniyuki's suggestion in [2].

This patch set has been produced with the help of a LLM, which was helpful for spotting a long list of inaccuracies, comparing the documentation with the kernel implementation. (More details in [1])

–Günther

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/CAAVpQUBh+J-aBLbkpzT7qmt7B714O529HWcTuQsVLT4wLBnDJA@mail.gmail.com/

Günther Noack (8):
man/man7/socket.7: SO_PEEK_OFF: This option is no longer specific to

    unix(7)

man/man7/unix.7: SO_PEERCRED: Also works for SOCK_SEQPACKET man/man7/unix.7: SIOCINQ: Document behavior for SOCK_SEQPACKET man/man7/unix.7: Explain Abstract UDS scoping to the network namespace man/man7/unix.7: SOCK_RAW is accepted as an alias for SOCK_DGRAM man/man7/unix.7: ERRORS: EPROTONOSUPPORT: Protocol 0 is also accepted man/man2/bind.2: ERRORS: EACCES: Write permission on the directory is
required
man/man7/unix.7: ERRORS: Document EACCES, EAGAIN, EMSGSIZE, ENOSPC,
and EPERM

 man/man2/bind.2   |  4 ++-
 man/man7/socket.7 | 16 ++++++++--
 man/man7/unix.7   | 75 ++++++++++++++++++++++++++++++++++++++++-------
 3 files changed, 80 insertions(+), 15 deletions(-)
Signature · 1 line
2.56.0
#1 lore raw

PATCH 1/8 man/man7/socket.7: SO_PEEK_OFF: This option is no longer specific to unix(7)

The option is implemented through proto_ops->set_peek_off, which is nowadays also set for UDP and TCP sockets:

	linux.git 627d2d6b5500 (2016-04-05; "udp: enable MSG_PEEK at non-zero offset")
		Linux 4.7, UDP over IPv4 and IPv6
	linux.git 05ea491641d3 (2024-04-11; "tcp: add support for SO_PEEK_OFF socket option")
		Linux 6.10, TCP over IPv4
	linux.git be9a4fb831b8 (2024-08-29; "tcp: add SO_PEEK_OFF socket option tor TCPv6")
		Linux 6.12, TCP over IPv6
Cc Jon Maloy <[email protected]>
Cc samanthakumar <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Double checked in code -- this feature has been added to these other protocols since that man page section was written; I made sure that we have all relevant commits listed as comments in the man page source.

 man/man7/socket.7 | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
man/man7/socket.7 +13 -3
index 96f6f173a40b..ebe0264d7ae4 100644
@@ -662,14 +662,24 @@ For more information, see
 .TP
 .BR SO_PEEK_OFF " (since Linux 3.4)"
 .\" commit ef64a54f6e558155b4f149bb10666b9e914b6c54
-This option, which is currently supported only for
-.BR unix (7)
-sockets, sets the value of the "peek offset" for the
+This option sets the value of the "peek offset" for the
 .BR recv (2)
 system call when used with
 .B MSG_PEEK
 flag.
 .IP
+This option is supported for
+.\" commit f55bb7f9cb82dec2f2e803d7bd0fc5929248e4d8
+.BR unix (7)
+sockets since Linux 3.4,
+.\" commit 627d2d6b550094d88f9e518e15967e7bf906ebbf
+for UDP sockets since Linux 4.7,
+and for TCP sockets since
+.\" commit 05ea491641d338422edbd87af3b311c16ea762f5
+Linux 6.10 (IPv4) and
+.\" commit be9a4fb831b8b6dc5724dd3e61973ea91b413ec1
+Linux 6.12 (IPv6).
+.IP
 When this option is set to a negative value
 (it is set to \-1 for all new sockets),
 traditional behavior is provided:
Signature · 1 line
2.56.0
maintainer Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] man/man7/socket.7: SO_PEEK_OFF: This option is no longer specific to unix(7)

Hi,

Quoted 13 lines

Date: 2026-10-21 23:07:53+0200
From: Günther Noack <[email protected]>

The option is implemented through proto_ops->set_peek_off, which is nowadays also set for UDP and TCP sockets:

	linux.git 627d2d6b5500 (2016-04-05; "udp: enable MSG_PEEK at non-zero offset")
		Linux 4.7, UDP over IPv4 and IPv6
	linux.git 05ea491641d3 (2024-04-11; "tcp: add support for SO_PEEK_OFF socket option")
		Linux 6.10, TCP over IPv4
	linux.git be9a4fb831b8 (2024-08-29; "tcp: add SO_PEEK_OFF socket option tor TCPv6")
		Linux 6.12, TCP over IPv6
Quoted 5 lines
Cc Jon Maloy <[email protected]>
Cc samanthakumar <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM
Quoted 6 lines

---

Notes:
Double checked in code -- this feature has been added to these other protocols since that man page section was written; I made sure that we have all relevant commits listed as comments in the man page source.

Actually, I prefer them in the commit message. These days of git(1), the comments in the source code are less useful and more noise.

Cheers,
Alex

Quoted 40 lines
 man/man7/socket.7 | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
man/man7/socket.7 +13 -3
index 96f6f173a40b..ebe0264d7ae4 100644
@@ -662,14 +662,24 @@ For more information, see
 .TP
 .BR SO_PEEK_OFF " (since Linux 3.4)"
 .\" commit ef64a54f6e558155b4f149bb10666b9e914b6c54
-This option, which is currently supported only for
-.BR unix (7)
-sockets, sets the value of the "peek offset" for the
+This option sets the value of the "peek offset" for the
 .BR recv (2)
 system call when used with
 .B MSG_PEEK
 flag.
 .IP
+This option is supported for
+.\" commit f55bb7f9cb82dec2f2e803d7bd0fc5929248e4d8
+.BR unix (7)
+sockets since Linux 3.4,
+.\" commit 627d2d6b550094d88f9e518e15967e7bf906ebbf
+for UDP sockets since Linux 4.7,
+and for TCP sockets since
+.\" commit 05ea491641d338422edbd87af3b311c16ea762f5
+Linux 6.10 (IPv4) and
+.\" commit be9a4fb831b8b6dc5724dd3e61973ea91b413ec1
+Linux 6.12 (IPv6).
+.IP
 When this option is set to a negative value
 (it is set to \-1 for all new sockets),
 traditional behavior is provided:
Signature · 1 line
2.56.0
Signature · 1 line
<https://www.alejandro-colomar.es>
#3 lore raw

Re: [PATCH 1/8] man/man7/socket.7: SO_PEEK_OFF: This option is no longer specific to unix(7)

Thank you for the review!

Quoted 7 lines · Alejandro Colomar
Quoted 4 lines

Notes:
Double checked in code -- this feature has been added to these other protocols since that man page section was written; I made sure that we have all relevant commits listed as comments in the man page source.

Actually, I prefer them in the commit message. These days of git(1), the comments in the source code are less useful and more noise.

Fair, I'll drop the newly introduced commit hashes from the source and list them all in the commit message in a slightly more comprehensive form (including the Unix commits).

–Günther

Reviewed-by on v1 1/8
#4 lore raw

Re: [PATCH 1/8] man/man7/socket.7: SO_PEEK_OFF: This option is no longer specific to unix(7)

In reply to Günther Noack
Quoted 10 lines · Günther Noack

The option is implemented through proto_ops->set_peek_off, which is nowadays also set for UDP and TCP sockets:

	linux.git 627d2d6b5500 (2016-04-05; "udp: enable MSG_PEEK at non-zero offset")
		Linux 4.7, UDP over IPv4 and IPv6
	linux.git 05ea491641d3 (2024-04-11; "tcp: add support for SO_PEEK_OFF socket option")
		Linux 6.10, TCP over IPv4
	linux.git be9a4fb831b8 (2024-08-29; "tcp: add SO_PEEK_OFF socket option tor TCPv6")
		Linux 6.12, TCP over IPv6
Quoted 5 lines
Cc Jon Maloy <[email protected]>
Cc samanthakumar <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM
#5 lore raw

PATCH 2/8 man/man7/unix.7: SO_PEERCRED: Also works for SOCK_SEQPACKET

In reply to Günther Noack

SOCK_SEQPACKET sockets use unix_stream_connect() as their connect operation (as defined in the ops structure unix_seqpacket_ops in linux.git net/unix/af_unix.c). That function records the peer credentials for both ends for later lookup.

unix_socketpair() records them for socket pairs of every type.

Connected SOCK_DGRAM sockets (unix_dgram_connect()) still don't record peer credentials, so those remain excluded.

In the code, the function that initializes the peercred is init_peercred()/update_peercred().

Fixes 73b3a5686084 (2005-08-16; "Clarified details of use of SO_PEERCRED.")
Cc Michael Kerrisk <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Double checked in code.

The unix(7) SOCK_SEQPACKET socket type is also connection-oriented and shares the "connect" logic with SOCK_STREAM sockets.

 man/man7/unix.7 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
man/man7/unix.7 +2 -2
index 1054d7f52a30..d0c1765dfd79 100644
@@ -342,9 +342,9 @@ feature test macro to obtain the definition of that structure from
 .IP
 The use of this option is possible only for connected
 .B AF_UNIX
-stream sockets and for
+stream and sequenced-packet sockets, and for
 .B AF_UNIX
-stream and datagram socket pairs created using
+socket pairs created using
 .BR socketpair (2).
 .\"
 .SS Autobind feature
Signature · 1 line
2.56.0
Reviewed-by on v1 2/8
#6 lore raw

Re: [PATCH 2/8] man/man7/unix.7: SO_PEERCRED: Also works for SOCK_SEQPACKET

Quoted 10 lines · Günther Noack

SOCK_SEQPACKET sockets use unix_stream_connect() as their connect operation (as defined in the ops structure unix_seqpacket_ops in linux.git net/unix/af_unix.c). That function records the peer credentials for both ends for later lookup.

unix_socketpair() records them for socket pairs of every type.

Connected SOCK_DGRAM sockets (unix_dgram_connect()) still don't record peer credentials, so those remain excluded.

Quoted 8 lines

In the code, the function that initializes the peercred is init_peercred()/update_peercred().

Fixes 73b3a5686084 (2005-08-16; "Clarified details of use of SO_PEERCRED.")
Cc Michael Kerrisk <[email protected]>
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM
#7 lore raw

PATCH 3/8 man/man7/unix.7: SIOCINQ: Document behavior for SOCK_SEQPACKET

In reply to Günther Noack

Document the SIOCINQ behavior for SOCK_SEQPACKET, which sums up the lengths of all messages in the receive queue.

Restructure sentence order, so that socket type differences are discussed in on paragraph, and commonalities in the next.

For reference, the SIOCINQ lookup is implemented in unix_inq_len() in linux.git net/unix/af_unix.c.

This function first rejects SIOCINQ for listening sockets with -EINVAL, then does a case analysis for the three types of Unix Domain Sockets:

For SOCK_STREAM, the result is:

	return READ_ONCE(unix_sk(sk)->inq_len);

For SOCK_SEQPACKET, the result is calculated using:

	skb_queue_walk(&sk->sk_receive_queue, skb)
        	amount += unix_skb_len(skb);

For SOCK_DGRAM, the result is:

	skb = skb_peek(&sk->sk_receive_queue);
	if (skb)
		amount = skb->len;
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
I double checked this all in the code, and quoted the code. Both the commit message and commit body were substantially edited based on the initial LLM-based version. (Nevertheless, I would have likely missed the inaccuracy if the LLM hadn't found it.)

The LLM initially just slapped an additional sentence into the paragraph, but that was mixing the socket-type-specific concerns with the general description -- I split that paragraph apart so that we have one paragraph for the three socket types and one for the socket-type-independent description.

 man/man7/unix.7 | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
man/man7/unix.7 +13 -7
index d0c1765dfd79..4c46b54206a5 100644
@@ -606,6 +606,19 @@ can be:
 For
 .B SOCK_STREAM
 sockets, this call returns the number of unread bytes in the receive buffer.
+For
+.B SOCK_DGRAM
+sockets,
+the returned value is the same as
+for Internet domain datagram sockets;
+see
+.BR udp (7).
+For
+.B SOCK_SEQPACKET
+sockets,
+this call returns the total number of bytes
+in all messages queued in the receive buffer.
+.IP
 The socket must not be in LISTEN state, otherwise an error
 .RB ( EINVAL )
 is returned.
@@ -625,13 +638,6 @@ defined in
 .\" That number is normally larger than the number of bytes of pending
 .\" output.  Since this info is, from userland's point of view, imprecise,
 .\" and it may well change, probably best not to document this now.
-For
-.B SOCK_DGRAM
-sockets,
-the returned value is the same as
-for Internet domain datagram sockets;
-see
-.BR udp (7).
 .SH ERRORS
 .TP
 .B EADDRINUSE
Signature · 1 line
2.56.0
#8 lore raw

Re: [PATCH 3/8] man/man7/unix.7: SIOCINQ: Document behavior for SOCK_SEQPACKET

Quoted 53 lines · Günther Noack

Document the SIOCINQ behavior for SOCK_SEQPACKET, which sums up the lengths of all messages in the receive queue.

Restructure sentence order, so that socket type differences are discussed in on paragraph, and commonalities in the next.

For reference, the SIOCINQ lookup is implemented in unix_inq_len() in linux.git net/unix/af_unix.c.

This function first rejects SIOCINQ for listening sockets with -EINVAL, then does a case analysis for the three types of Unix Domain Sockets:

For SOCK_STREAM, the result is:

	return READ_ONCE(unix_sk(sk)->inq_len);

For SOCK_SEQPACKET, the result is calculated using:

	skb_queue_walk(&sk->sk_receive_queue, skb)
        	amount += unix_skb_len(skb);

For SOCK_DGRAM, the result is:

	skb = skb_peek(&sk->sk_receive_queue);
	if (skb)
		amount = skb->len;
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
I double checked this all in the code, and quoted the code. Both the commit message and commit body were substantially edited based on the initial LLM-based version. (Nevertheless, I would have likely missed the inaccuracy if the LLM hadn't found it.)

The LLM initially just slapped an additional sentence into the paragraph, but that was mixing the socket-type-specific concerns with the general description -- I split that paragraph apart so that we have one paragraph for the three socket types and one for the socket-type-independent description.

 man/man7/unix.7 | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
man/man7/unix.7 +0 -0
index d0c1765dfd79..4c46b54206a5 100644

man/man7/unix.7 can be: · line 607

Quoted 2 lines
man/man7/unix.7 +0 -0
@@ -606,6 +606,19 @@ can be:
 For
 .B SOCK_STREAM

and SOCK_SEQPACKET

man/man7/unix.7 can be: · line 615

Quoted 8 lines
man/man7/unix.7 +7 -0
 sockets, this call returns the number of unread bytes in the receive buffer.
+For
+.B SOCK_DGRAM
+sockets,
+the returned value is the same as
+for Internet domain datagram sockets;
+see
+.BR udp (7).

Simply say it's the length of the first datagram.
so that we don't need to jump to udp doc.

Quoted 26 lines
man/man7/unix.7 +6 -7
+For
+.B SOCK_SEQPACKET
+sockets,
+this call returns the total number of bytes
+in all messages queued in the receive buffer.
+.IP
 The socket must not be in LISTEN state, otherwise an error
 .RB ( EINVAL )
 is returned.
@@ -625,13 +638,6 @@ defined in
 .\" That number is normally larger than the number of bytes of pending
 .\" output.  Since this info is, from userland's point of view, imprecise,
 .\" and it may well change, probably best not to document this now.
-For
-.B SOCK_DGRAM
-sockets,
-the returned value is the same as
-for Internet domain datagram sockets;
-see
-.BR udp (7).
 .SH ERRORS
 .TP
 .B EADDRINUSE
Signature · 1 line
2.56.0
#9 lore raw

Re: [PATCH 3/8] man/man7/unix.7: SIOCINQ: Document behavior for SOCK_SEQPACKET

Quoted 49 lines · Kuniyuki Iwashima
Quoted 48 lines · Günther Noack

Document the SIOCINQ behavior for SOCK_SEQPACKET, which sums up the lengths of all messages in the receive queue.

Restructure sentence order, so that socket type differences are discussed in on paragraph, and commonalities in the next.

For reference, the SIOCINQ lookup is implemented in unix_inq_len() in linux.git net/unix/af_unix.c.

This function first rejects SIOCINQ for listening sockets with -EINVAL, then does a case analysis for the three types of Unix Domain Sockets:

For SOCK_STREAM, the result is:

	return READ_ONCE(unix_sk(sk)->inq_len);

For SOCK_SEQPACKET, the result is calculated using:

	skb_queue_walk(&sk->sk_receive_queue, skb)
        	amount += unix_skb_len(skb);

For SOCK_DGRAM, the result is:

	skb = skb_peek(&sk->sk_receive_queue);
	if (skb)
		amount = skb->len;
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
I double checked this all in the code, and quoted the code. Both the commit message and commit body were substantially edited based on the initial LLM-based version. (Nevertheless, I would have likely missed the inaccuracy if the LLM hadn't found it.)

The LLM initially just slapped an additional sentence into the paragraph, but that was mixing the socket-type-specific concerns with the general description -- I split that paragraph apart so that we have one paragraph for the three socket types and one for the socket-type-independent description.

 man/man7/unix.7 | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
Quoted 9 lines

man/man7/unix.7 can be: · line 607

Quoted 7 lines
man/man7/unix.7 +0 -0
index d0c1765dfd79..4c46b54206a5 100644
@@ -606,6 +606,19 @@ can be:
 For
 .B SOCK_STREAM

and SOCK_SEQPACKET

OK fair. This was explained a bit below, but maybe too close to the implementation. When I initially looked at this, I found it a bit surprising that for SOCK_SEQPACKET, it returns the size of all of them combined, but for SOCK_DGRAM only the size of the next one.

I'll conflate this as you suggested into "For SOCK_STREAM and SOCK_SEQPACKET..." (dropping the other sentence about SOCK_SEQPACKET.)

Quoted 11 lines

man/man7/unix.7 can be: · line 615

Quoted 8 lines
man/man7/unix.7 +7 -0
 sockets, this call returns the number of unread bytes in the receive buffer.
+For
+.B SOCK_DGRAM
+sockets,
+the returned value is the same as
+for Internet domain datagram sockets;
+see
+.BR udp (7).

Simply say it's the length of the first datagram.
so that we don't need to jump to udp doc.

Sounds good, it now reads:

For SOCK_DGRAM sockets, this call returns the size of the next pending datagram, or 0 when no datagram is pending.

(Using the same wording as udp(7))

Quoted 6 lines

man/man7/unix.7 can be: · line 621

Quoted 6 lines
man/man7/unix.7 +6 -0
+For
+.B SOCK_SEQPACKET
+sockets,
+this call returns the total number of bytes
+in all messages queued in the receive buffer.
+.IP

(Dropped this part as discussed above)

–Günther

#10 lore raw

PATCH 4/8 man/man7/unix.7: Explain Abstract UDS scoping to the network namespace

In reply to Günther Noack

Point out that Abstract Unix Domain Sockets are visible within the current network namespace, unlike Named Unix Domain Sockets, where the remote socket is looked up through the mount namespace.

To avoid confusion, remove the word "namespace" from the subsequent paragraph, where it is used in a more colloquial form (there is no abstract socket namespace in the sense of namespaces(7)).

This is already described in network_namespaces(7) as well, but might be mentionworthy here too.

The lookup of Abtract addresses happens in __unix_find_socket_byname() in linux.git net/unix/af_unix.c, where it is looked up in the network namespace (struct net *net) in a hash table in that namespace:

	sk_for_each(s, &net->unx.table.buckets[hash]) {
		// ...
	}
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Verified in code

 man/man7/unix.7 | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
man/man7/unix.7 +11 -1
index 4c46b54206a5..232fdbf4c3cd 100644
@@ -257,7 +257,17 @@ has no effect on the accessibility of the socket.
 Abstract sockets automatically disappear when all open references
 to the socket are closed.
 .P
-The abstract socket namespace is a nonportable Linux extension.
+Each network namespace has its own abstract socket namespace (see
+.BR network_namespaces (7)):
+a socket can connect or send to an abstract address
+only if the socket bound to that address
+is in the same network namespace.
+In contrast,
+pathname sockets are not confined to a network namespace;
+they can be reached from any network namespace
+in which the socket file is accessible.
+.P
+Abstract sockets are a nonportable Linux extension.
 .\"
 .SS Socket options
 For historical reasons, these socket options are specified with a
Signature · 1 line
2.56.0
#11 lore raw

Re: [PATCH 4/8] man/man7/unix.7: Explain Abstract UDS scoping to the network namespace

Quoted 2 lines · Günther Noack

Point out that Abstract Unix Domain Sockets are visible within the current network namespace, unlike Named Unix Domain Sockets, where the

s/Named/pathname/.

pathname, unnamed, abstract are used in Address format section.

Quoted 5 lines

remote socket is looked up through the mount namespace.

To avoid confusion, remove the word "namespace" from the subsequent paragraph, where it is used in a more colloquial form (there is no abstract socket namespace in the sense of namespaces(7)).

The change still uses "abstract socket namespace".

Quoted 28 lines

This is already described in network_namespaces(7) as well, but might be mentionworthy here too.

The lookup of Abtract addresses happens in __unix_find_socket_byname() in linux.git net/unix/af_unix.c, where it is looked up in the network namespace (struct net *net) in a hash table in that namespace:

	sk_for_each(s, &net->unx.table.buckets[hash]) {
		// ...
	}
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Verified in code

 man/man7/unix.7 | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
man/man7/unix.7 +0 -0
index 4c46b54206a5..232fdbf4c3cd 100644

man/man7/unix.7 has no effect on the accessibility of the socket. · line 261

Quoted 6 lines
man/man7/unix.7 +2 -1
@@ -257,7 +257,17 @@ has no effect on the accessibility of the socket.
 Abstract sockets automatically disappear when all open references
 to the socket are closed.
 .P
-The abstract socket namespace is a nonportable Linux extension.
+Each network namespace has its own abstract socket namespace (see
+.BR network_namespaces (7)):

Remove this sentence and...

man/man7/unix.7 has no effect on the accessibility of the socket. · line 264

Quoted 3 lines
man/man7/unix.7 +3 -0
+a socket can connect or send to an abstract address
+only if the socket bound to that address
+is in the same network namespace.

add "(see network_namespaces (7))" here.

Quoted 12 lines
man/man7/unix.7 +6 -0
+In contrast,
+pathname sockets are not confined to a network namespace;
+they can be reached from any network namespace
+in which the socket file is accessible.
+.P
+Abstract sockets are a nonportable Linux extension.
 .\"
 .SS Socket options
 For historical reasons, these socket options are specified with a
Signature · 1 line
2.56.0
#12 lore raw

Re: [PATCH 4/8] man/man7/unix.7: Explain Abstract UDS scoping to the network namespace

Hello! Thanks for the review!

Quoted 7 lines · Kuniyuki Iwashima
Quoted 2 lines · Günther Noack

Point out that Abstract Unix Domain Sockets are visible within the current network namespace, unlike Named Unix Domain Sockets, where the

s/Named/pathname/.

pathname, unnamed, abstract are used in Address format section.

Thanks, fixed.

Quoted 7 lines
Quoted 5 lines

remote socket is looked up through the mount namespace.

To avoid confusion, remove the word "namespace" from the subsequent paragraph, where it is used in a more colloquial form (there is no abstract socket namespace in the sense of namespaces(7)).

The change still uses "abstract socket namespace".

In the "Abstract Sockets" section, the word "namespace" is not used any more in the general sense, but only in the sense of a setns(2)/namespaces(7) namespace.

There are some places in the man page where the word "namespace" is still used colloquially, but these are not in the vicinity of this change and feel less prone to confusion. Do you think I should update these all in the same commit?

Quoted 37 lines
Quoted 27 lines

This is already described in network_namespaces(7) as well, but might be mentionworthy here too.

The lookup of Abtract addresses happens in __unix_find_socket_byname() in linux.git net/unix/af_unix.c, where it is looked up in the network namespace (struct net *net) in a hash table in that namespace:

	sk_for_each(s, &net->unx.table.buckets[hash]) {
		// ...
	}
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Verified in code

 man/man7/unix.7 | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
man/man7/unix.7 +0 -0
index 4c46b54206a5..232fdbf4c3cd 100644

man/man7/unix.7 has no effect on the accessibility of the socket. · line 261

Quoted 6 lines
man/man7/unix.7 +2 -1
@@ -257,7 +257,17 @@ has no effect on the accessibility of the socket.
 Abstract sockets automatically disappear when all open references
 to the socket are closed.
 .P
-The abstract socket namespace is a nonportable Linux extension.
+Each network namespace has its own abstract socket namespace (see
+.BR network_namespaces (7)):

Remove this sentence and...

Quoted 5 lines

man/man7/unix.7 has no effect on the accessibility of the socket. · line 264

Quoted 3 lines
man/man7/unix.7 +3 -0
+a socket can connect or send to an abstract address
+only if the socket bound to that address
+is in the same network namespace.

add "(see network_namespaces (7))" here.

Good idea, that's shorter.

Quoted 4 lines
Quoted 4 lines
man/man7/unix.7 +4 -0
+In contrast,
+pathname sockets are not confined to a network namespace;
+they can be reached from any network namespace
+in which the socket file is accessible.
Quoted 8 lines
Quoted 8 lines
man/man7/unix.7 +2 -0
+.P
+Abstract sockets are a nonportable Linux extension.
 .\"
 .SS Socket options
 For historical reasons, these socket options are specified with a
Signature · 1 line
2.56.0

Thanks,
–Günther

#13 lore raw

Re: [PATCH 4/8] man/man7/unix.7: Explain Abstract UDS scoping to the network namespace

Quoted 22 lines · Günther Noack

Hello! Thanks for the review!

Quoted 7 lines · Kuniyuki Iwashima
Quoted 2 lines · Günther Noack

Point out that Abstract Unix Domain Sockets are visible within the current network namespace, unlike Named Unix Domain Sockets, where the

s/Named/pathname/.

pathname, unnamed, abstract are used in Address format section.

Thanks, fixed.

Quoted 7 lines
Quoted 5 lines

remote socket is looked up through the mount namespace.

To avoid confusion, remove the word "namespace" from the subsequent paragraph, where it is used in a more colloquial form (there is no abstract socket namespace in the sense of namespaces(7)).

The change still uses "abstract socket namespace".

Quoted 8 lines

In the "Abstract Sockets" section, the word "namespace" is not used any more in the general sense, but only in the sense of a setns(2)/namespaces(7) namespace.

There are some places in the man page where the word "namespace" is still used colloquially, but these are not in the vicinity of this change and feel less prone to confusion. Do you think I should update these all in the same commit?

I understand the "namespace" itself is a generic word but it feels a bit odd as it most likely means CLONE_NEWXXX in Linux.

But fixing up all would be apparently boring, so I'll let you decide, and leaving them as is is 100% fine ;)

Quoted 63 lines
Quoted 39 lines
Quoted 29 lines

This is already described in network_namespaces(7) as well, but might be mentionworthy here too.

The lookup of Abtract addresses happens in __unix_find_socket_byname() in linux.git net/unix/af_unix.c, where it is looked up in the network namespace (struct net *net) in a hash table in that namespace:

	sk_for_each(s, &net->unx.table.buckets[hash]) {
		// ...
	}
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Verified in code

 man/man7/unix.7 | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
man/man7/unix.7 +0 -0
index 4c46b54206a5..232fdbf4c3cd 100644

man/man7/unix.7 has no effect on the accessibility of the socket. · line 261

Quoted 6 lines
man/man7/unix.7 +2 -1
@@ -257,7 +257,17 @@ has no effect on the accessibility of the socket.
 Abstract sockets automatically disappear when all open references
 to the socket are closed.
 .P
-The abstract socket namespace is a nonportable Linux extension.
+Each network namespace has its own abstract socket namespace (see
+.BR network_namespaces (7)):

Remove this sentence and...

Quoted 5 lines

man/man7/unix.7 has no effect on the accessibility of the socket. · line 264

Quoted 3 lines
man/man7/unix.7 +3 -0
+a socket can connect or send to an abstract address
+only if the socket bound to that address
+is in the same network namespace.

add "(see network_namespaces (7))" here.

Good idea, that's shorter.

Quoted 4 lines
Quoted 4 lines
man/man7/unix.7 +4 -0
+In contrast,
+pathname sockets are not confined to a network namespace;
+they can be reached from any network namespace
+in which the socket file is accessible.
Quoted 8 lines
Quoted 8 lines
man/man7/unix.7 +2 -0
+.P
+Abstract sockets are a nonportable Linux extension.
 .\"
 .SS Socket options
 For historical reasons, these socket options are specified with a
Signature · 1 line
2.56.0

Thanks,
–Günther

#14 lore raw

Re: [PATCH 4/8] man/man7/unix.7: Explain Abstract UDS scoping to the network namespace

Thanks for the review!

Quoted 19 lines · Kuniyuki Iwashima
Quoted 9 lines · Günther Noack
Quoted 7 lines · Kuniyuki Iwashima
Quoted 5 lines

remote socket is looked up through the mount namespace.

To avoid confusion, remove the word "namespace" from the subsequent paragraph, where it is used in a more colloquial form (there is no abstract socket namespace in the sense of namespaces(7)).

The change still uses "abstract socket namespace".

Quoted 8 lines

In the "Abstract Sockets" section, the word "namespace" is not used any more in the general sense, but only in the sense of a setns(2)/namespaces(7) namespace.

There are some places in the man page where the word "namespace" is still used colloquially, but these are not in the vicinity of this change and feel less prone to confusion. Do you think I should update these all in the same commit?

Quoted 5 lines

I understand the "namespace" itself is a generic word but it feels a bit odd as it most likely means CLONE_NEWXXX in Linux.

But fixing up all would be apparently boring, so I'll let you decide, and leaving them as is is 100% fine ;)

On the other hand, it's not much work either. I'll create a small extra patch as part of this series to clean up the remaining uses of namespace. We can discuss that separately then.

–Günther

#15 lore raw

PATCH 5/8 man/man7/unix.7: SOCK_RAW is accepted as an alias for SOCK_DGRAM

In reply to Günther Noack

unix_create() in linux.git net/unix/af_unix.c does:

	case SOCK_RAW:
		sock->type = SOCK_DGRAM;
		fallthrough;
	case SOCK_DGRAM:

so both socket(AF_UNIX, SOCK_RAW, 0) and the equivalent socketpair() invocation succeed and create datagram sockets.

Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
For completeness;

It is more complete to spell it out, but on the other hand, people should not be passing the SOCK_RAW type when they really mean SOCK_DGRAM. I'm on the fence about whether this is useful. If you want to omit this one, it also feels reasonable.

 man/man7/unix.7 | 5 +++++
 1 file changed, 5 insertions(+)
man/man7/unix.7 +5 -0
index 232fdbf4c3cd..29843235def0 100644
@@ -39,6 +39,11 @@ and (since Linux 2.6.4)
 for a sequenced-packet socket that is connection-oriented,
 preserves message boundaries,
 and delivers messages in the order that they were sent.
+On Linux,
+.B SOCK_RAW
+.\" unix_create() in net/unix/af_unix.c
+is also accepted as an alias for
+.BR SOCK_DGRAM .
 .P
 UNIX domain sockets support passing file descriptors or process credentials
 to other processes using ancillary data.
Signature · 1 line
2.56.0
#16 lore raw

Re: [PATCH 5/8] man/man7/unix.7: SOCK_RAW is accepted as an alias for SOCK_DGRAM

Quoted 15 lines · Günther Noack

unix_create() in linux.git net/unix/af_unix.c does:

	case SOCK_RAW:
		sock->type = SOCK_DGRAM;
		fallthrough;
	case SOCK_DGRAM:

so both socket(AF_UNIX, SOCK_RAW, 0) and the equivalent socketpair() invocation succeed and create datagram sockets.

Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Quoted 7 lines

Notes:
For completeness;

It is more complete to spell it out, but on the other hand, people should not be passing the SOCK_RAW type when they really mean SOCK_DGRAM. I'm on the fence about whether this is useful. If you want to omit this one, it also feels reasonable.

Yes, please drop this patch.

There is fallback but only for a historical reason; just to support too old BSD program IIRC.

We should not say it's officially supported when it's just converted to SOCK_DGRAM.

Quoted 23 lines
 man/man7/unix.7 | 5 +++++
 1 file changed, 5 insertions(+)
man/man7/unix.7 +5 -0
index 232fdbf4c3cd..29843235def0 100644
@@ -39,6 +39,11 @@ and (since Linux 2.6.4)
 for a sequenced-packet socket that is connection-oriented,
 preserves message boundaries,
 and delivers messages in the order that they were sent.
+On Linux,
+.B SOCK_RAW
+.\" unix_create() in net/unix/af_unix.c
+is also accepted as an alias for
+.BR SOCK_DGRAM .
 .P
 UNIX domain sockets support passing file descriptors or process credentials
 to other processes using ancillary data.
Signature · 1 line
2.56.0
#17 lore raw

Re: [PATCH 5/8] man/man7/unix.7: SOCK_RAW is accepted as an alias for SOCK_DGRAM

Quoted 24 lines · Kuniyuki Iwashima
Quoted 15 lines · Günther Noack

unix_create() in linux.git net/unix/af_unix.c does:

	case SOCK_RAW:
		sock->type = SOCK_DGRAM;
		fallthrough;
	case SOCK_DGRAM:

so both socket(AF_UNIX, SOCK_RAW, 0) and the equivalent socketpair() invocation succeed and create datagram sockets.

Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Quoted 7 lines

Notes:
For completeness;

It is more complete to spell it out, but on the other hand, people should not be passing the SOCK_RAW type when they really mean SOCK_DGRAM. I'm on the fence about whether this is useful. If you want to omit this one, it also feels reasonable.

Quoted 7 lines

Yes, please drop this patch.

There is fallback but only for a historical reason; just to support too old BSD program IIRC.

We should not say it's officially supported when it's just converted to SOCK_DGRAM.

Sounds good, dropping it.

–Günther

#18 lore raw

PATCH 6/8 man/man7/unix.7: ERRORS: EPROTONOSUPPORT: Protocol 0 is also accepted

In reply to Günther Noack

unix_create() in linux.git net/unix/af_unix.c starts with this check:

	if (protocol && protocol != PF_UNIX)
        	return -EPROTONOSUPPORT;

Therefore, not only AF_UNIX (a.k.a. PF_UNIX) is accepted as a protocol value in the unix(7) socket(2) invocation, but also 0. 0 is the usual value, and is also given as example in the SYNOPSIS at the top of unix(7).

Fixes 9d1fd1157306 (1999-06-15, 2022-12-19; "man-pages 1.24")
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
I double checked it in the code.

 man/man7/unix.7 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
man/man7/unix.7 +1 -1
index 29843235def0..054f1af75dd5 100644
@@ -729,7 +729,7 @@ or
 .BR sendmsg (2).
 .TP
 .B EPROTONOSUPPORT
-Passed protocol is not
+Passed protocol is neither 0 nor
 .BR AF_UNIX .
 .TP
 .B EPROTOTYPE
Signature · 1 line
2.56.0
#19 lore raw

Re: [PATCH 6/8] man/man7/unix.7: ERRORS: EPROTONOSUPPORT: Protocol 0 is also accepted

Quoted 9 lines · Günther Noack

unix_create() in linux.git net/unix/af_unix.c starts with this check:

	if (protocol && protocol != PF_UNIX)
        	return -EPROTONOSUPPORT;

Therefore, not only AF_UNIX (a.k.a. PF_UNIX) is accepted as a protocol value in the unix(7) socket(2) invocation, but also 0. 0 is the usual value, and is also given as example in the SYNOPSIS at the top of unix(7).

For the same reason with the previous patch, please drop this change.

It's not worth documenting.

Quoted 29 lines
Fixes 9d1fd1157306 (1999-06-15, 2022-12-19; "man-pages 1.24")
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
I double checked it in the code.

 man/man7/unix.7 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
man/man7/unix.7 +1 -1
index 29843235def0..054f1af75dd5 100644
@@ -729,7 +729,7 @@ or
 .BR sendmsg (2).
 .TP
 .B EPROTONOSUPPORT
-Passed protocol is not
+Passed protocol is neither 0 nor
 .BR AF_UNIX .
 .TP
 .B EPROTOTYPE
Signature · 1 line
2.56.0
#20 lore raw

Re: [PATCH 6/8] man/man7/unix.7: ERRORS: EPROTONOSUPPORT: Protocol 0 is also accepted

Quoted 6 lines · Kuniyuki Iwashima
Quoted 5 lines · Günther Noack

unix_create() in linux.git net/unix/af_unix.c starts with this check:

	if (protocol && protocol != PF_UNIX)
        	return -EPROTONOSUPPORT;
Quoted 8 lines
Quoted 4 lines

Therefore, not only AF_UNIX (a.k.a. PF_UNIX) is accepted as a protocol value in the unix(7) socket(2) invocation, but also 0. 0 is the usual value, and is also given as example in the SYNOPSIS at the top of unix(7).

For the same reason with the previous patch, please drop this change.

It's not worth documenting.

Fair enough, dropped.

–Günther

#21 lore raw

PATCH 7/8 man/man2/bind.2: ERRORS: EACCES: Write permission on the directory is required

In reply to Günther Noack

In addition to the search permission, binding a named UNIX domain socket requires write permission on the parent directory. Bring the wording in line with similar documentation for EACCES on other syscalls such as mkdir(2), mknod(2), connect(2), link(2) and rename(2).

Fixes 9d1fd1157306 (1999-06-15, 2022-12-19; "man-pages 1.24")
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Reworded commit message and made sure that wording is in-line with other man pages.

 man/man2/bind.2 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
man/man2/bind.2 +3 -1
index ccb77e553cb2..6838a9d164aa 100644
@@ -150,7 +150,9 @@ The following errors are specific to UNIX domain
 sockets:
 .TP
 .B EACCES
-Search permission is denied on a component of the path prefix.
+Write permission is denied on the directory
+in which the socket would be created,
+or search permission is denied on a component of the path prefix.
 (See also
 .BR path_resolution (7).)
 .TP
Signature · 1 line
2.56.0
Reviewed-by on v1 7/8
#22 lore raw

Re: [PATCH 7/8] man/man2/bind.2: ERRORS: EACCES: Write permission on the directory is required

Quoted 10 lines · Günther Noack

In addition to the search permission, binding a named UNIX domain socket requires write permission on the parent directory. Bring the wording in line with similar documentation for EACCES on other syscalls such as mkdir(2), mknod(2), connect(2), link(2) and rename(2).

Fixes 9d1fd1157306 (1999-06-15, 2022-12-19; "man-pages 1.24")
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM
#23 lore raw

Re: [PATCH 7/8] man/man2/bind.2: ERRORS: EACCES: Write permission on the directory is required

Quoted 2 lines · Kuniyuki Iwashima
Quoted 1 line · Günther Noack

In addition to the search permission, binding a named UNIX domain

nit: s/named/pathname/

Quoted 11 lines
Quoted 9 lines

socket requires write permission on the parent directory. Bring the wording in line with similar documentation for EACCES on other syscalls such as mkdir(2), mknod(2), connect(2), link(2) and rename(2).

Fixes 9d1fd1157306 (1999-06-15, 2022-12-19; "man-pages 1.24")
Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM
#24 lore raw

Re: [PATCH 7/8] man/man2/bind.2: ERRORS: EACCES: Write permission on the directory is required

Quoted 5 lines · Kuniyuki Iwashima
Quoted 2 lines · Kuniyuki Iwashima
Quoted 1 line · Günther Noack

In addition to the search permission, binding a named UNIX domain

nit: s/named/pathname/

Thanks, fixed.

–Günther

#25 lore raw

PATCH 8/8 man/man7/unix.7: ERRORS: Document EACCES, EAGAIN, EMSGSIZE, ENOSPC, and EPERM

In reply to Günther Noack

These are all returned directly from linux.git net/unix/af_unix.c:

EACCES
unix_find_bsd() checks path_permission(&path, MAY_WRITE) on the socket file of the remote address. The rule was already described in prose, but the error was not listed.

EAGAIN
unix_stream_connect() returns -EAGAIN when the listener's backlog is full and the socket is nonblocking (there is no EINPROGRESS for AF_UNIX). unix_dgram_sendmsg() returns -EAGAIN when the receiver's queue is full and the send would block.

EMSGSIZE

	unix_dgram_sendmsg() fails if 'len > sk->sk_sndbuf - 32'.  This is
	the limit described in "Sockets API".

ENOSPC
unix_autobind() fails when all 2^20 autobind names are taken.

EPERM
unix_dgram_connect() and unix_dgram_sendmsg() fail if !unix_may_send(), that is, if the target datagram socket is connected to a socket other than the caller's.

This is not something that the remote end normally does, but it's a possible corner case.

Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Verified in code. Kept LLM wording, which seemed OK.

Remark:

The case where the remote end is connected to a different socket is obscure, but still possible with Unix Domain Sockets, when a program first bind(2)s to a name, and then connect(2)s to another name. Then that socket can be discovered by another process through the bound name, but sending a dgram fails if the sender is not the one that that socket has connected to.

 man/man7/unix.7 | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
man/man7/unix.7 +32 -0
index 054f1af75dd5..79198445c581 100644
@@ -655,10 +655,25 @@ defined in
 .\" and it may well change, probably best not to document this now.
 .SH ERRORS
 .TP
+.B EACCES
+The caller does not have write permission on the socket file
+specified as the remote address to
+.BR connect (2)
+or
+.BR sendto (2)
+(see "Pathname socket ownership and permissions", above).
+.TP
 .B EADDRINUSE
 The specified local address is already in use or the filesystem socket
 object already exists.
 .TP
+.B EAGAIN
+The socket is nonblocking, and either
+.BR connect (2)
+was called on a stream or sequenced-packet socket
+and the backlog of the listening socket is full,
+or a datagram was sent to a socket whose receive queue is full.
+.TP
 .B EBADF
 This error can occur for
 .BR sendmsg (2)
@@ -694,6 +709,11 @@ invalid state for the applied operation.
 called on an already connected socket or a target address was
 specified on a connected socket.
 .TP
+.B EMSGSIZE
+The datagram to be sent is larger than the limit imposed by the
+.B SO_SNDBUF
+socket option (see "Sockets API", above).
+.TP
 .B ENFILE
 The system-wide limit on the total number of open files has been reached.
 .TP
@@ -705,6 +725,11 @@ did not exist.
 .B ENOMEM
 Out of memory.
 .TP
+.B ENOSPC
+The socket was to be autobound,
+but all autobind addresses are in use
+(see "Autobind feature", above).
+.TP
 .B ENOTCONN
 Socket operation needs a target address, but the socket is not connected.
 .TP
@@ -716,6 +741,13 @@ use the out-of-band data option.
 The sender passed invalid credentials in the
 .IR "struct ucred" .
 .TP
+.B EPERM
+.BR connect (2)
+or
+.BR sendto (2)
+specified a datagram socket as the remote address,
+but that socket is connected to a different socket.
+.TP
 .B EPIPE
 Remote socket was closed on a stream socket.
 If enabled, a
Signature · 1 line
2.56.0
#26 lore raw

Re: [PATCH 8/8] man/man7/unix.7: ERRORS: Document EACCES, EAGAIN, EMSGSIZE, ENOSPC, and EPERM

Quoted 53 lines · Günther Noack

These are all returned directly from linux.git net/unix/af_unix.c:

EACCES
unix_find_bsd() checks path_permission(&path, MAY_WRITE) on the socket file of the remote address. The rule was already described in prose, but the error was not listed.

EAGAIN
unix_stream_connect() returns -EAGAIN when the listener's backlog is full and the socket is nonblocking (there is no EINPROGRESS for AF_UNIX). unix_dgram_sendmsg() returns -EAGAIN when the receiver's queue is full and the send would block.

EMSGSIZE

	unix_dgram_sendmsg() fails if 'len > sk->sk_sndbuf - 32'.  This is
	the limit described in "Sockets API".

ENOSPC
unix_autobind() fails when all 2^20 autobind names are taken.

EPERM
unix_dgram_connect() and unix_dgram_sendmsg() fail if !unix_may_send(), that is, if the target datagram socket is connected to a socket other than the caller's.

This is not something that the remote end normally does, but it's a possible corner case.

Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Verified in code. Kept LLM wording, which seemed OK.

Remark:

The case where the remote end is connected to a different socket is obscure, but still possible with Unix Domain Sockets, when a program first bind(2)s to a name, and then connect(2)s to another name. Then that socket can be discovered by another process through the bound name, but sending a dgram fails if the sender is not the one that that socket has connected to.

 man/man7/unix.7 | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
man/man7/unix.7 +0 -0
index 054f1af75dd5..79198445c581 100644

man/man7/unix.7 defined in · line 659

Quoted 5 lines
man/man7/unix.7 +2 -0
@@ -655,10 +655,25 @@ defined in
 .\" and it may well change, probably best not to document this now.
 .SH ERRORS
 .TP
+.B EACCES
+The caller does not have write permission on the socket file

If we align with other doc, "write permission is denied..."

man/man7/unix.7 defined in · line 668

Quoted 9 lines
man/man7/unix.7 +6 -0
+specified as the remote address to
+.BR connect (2)
+or
+.BR sendto (2)
+(see "Pathname socket ownership and permissions", above).
+.TP
 .B EADDRINUSE
 The specified local address is already in use or the filesystem socket
 object already exists.

s/filesystem socket object/file/

Two sockets can have the same address once one's file is removed even without closing the socket.

Quoted 52 lines
man/man7/unix.7 +24 -0
 .TP
+.B EAGAIN
+The socket is nonblocking, and either
+.BR connect (2)
+was called on a stream or sequenced-packet socket
+and the backlog of the listening socket is full,
+or a datagram was sent to a socket whose receive queue is full.
+.TP
 .B EBADF
 This error can occur for
 .BR sendmsg (2)
@@ -694,6 +709,11 @@ invalid state for the applied operation.
 called on an already connected socket or a target address was
 specified on a connected socket.
 .TP
+.B EMSGSIZE
+The datagram to be sent is larger than the limit imposed by the
+.B SO_SNDBUF
+socket option (see "Sockets API", above).
+.TP
 .B ENFILE
 The system-wide limit on the total number of open files has been reached.
 .TP
@@ -705,6 +725,11 @@ did not exist.
 .B ENOMEM
 Out of memory.
 .TP
+.B ENOSPC
+The socket was to be autobound,
+but all autobind addresses are in use
+(see "Autobind feature", above).
+.TP
 .B ENOTCONN
 Socket operation needs a target address, but the socket is not connected.
 .TP
@@ -716,6 +741,13 @@ use the out-of-band data option.
 The sender passed invalid credentials in the
 .IR "struct ucred" .
 .TP
+.B EPERM
+.BR connect (2)
+or
+.BR sendto (2)
+specified a datagram socket as the remote address,
+but that socket is connected to a different socket.
+.TP
 .B EPIPE
 Remote socket was closed on a stream socket.
 If enabled, a
Signature · 1 line
2.56.0
#27 lore raw

Re: [PATCH 8/8] man/man7/unix.7: ERRORS: Document EACCES, EAGAIN, EMSGSIZE, ENOSPC, and EPERM

Thanks for the review!

Quoted 49 lines · Kuniyuki Iwashima
Quoted 48 lines · Günther Noack

These are all returned directly from linux.git net/unix/af_unix.c:

EACCES
unix_find_bsd() checks path_permission(&path, MAY_WRITE) on the socket file of the remote address. The rule was already described in prose, but the error was not listed.

EAGAIN
unix_stream_connect() returns -EAGAIN when the listener's backlog is full and the socket is nonblocking (there is no EINPROGRESS for AF_UNIX). unix_dgram_sendmsg() returns -EAGAIN when the receiver's queue is full and the send would block.

EMSGSIZE

	unix_dgram_sendmsg() fails if 'len > sk->sk_sndbuf - 32'.  This is
	the limit described in "Sockets API".

ENOSPC
unix_autobind() fails when all 2^20 autobind names are taken.

EPERM
unix_dgram_connect() and unix_dgram_sendmsg() fail if !unix_may_send(), that is, if the target datagram socket is connected to a socket other than the caller's.

This is not something that the remote end normally does, but it's a possible corner case.

Cc Kuniyuki Iwashima <[email protected]>
Assisted-by LLM

---

Notes:
Verified in code. Kept LLM wording, which seemed OK.

Remark:

The case where the remote end is connected to a different socket is obscure, but still possible with Unix Domain Sockets, when a program first bind(2)s to a name, and then connect(2)s to another name. Then that socket can be discovered by another process through the bound name, but sending a dgram fails if the sender is not the one that that socket has connected to.

 man/man7/unix.7 | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
Quoted 12 lines

man/man7/unix.7 defined in · line 659

Quoted 10 lines
man/man7/unix.7 +2 -0
index 054f1af75dd5..79198445c581 100644
@@ -655,10 +655,25 @@ defined in
 .\" and it may well change, probably best not to document this now.
 .SH ERRORS
 .TP
+.B EACCES
+The caller does not have write permission on the socket file

If we align with other doc, "write permission is denied..."

Done.

(IIRC, the man pages have similar, but inconsistent, wording for this, but this is the shorter variant.)

Quoted 12 lines

man/man7/unix.7 defined in · line 668

Quoted 9 lines
man/man7/unix.7 +6 -0
+specified as the remote address to
+.BR connect (2)
+or
+.BR sendto (2)
+(see "Pathname socket ownership and permissions", above).
+.TP
 .B EADDRINUSE
 The specified local address is already in use or the filesystem socket
 object already exists.

s/filesystem socket object/file/

Quoted 2 lines

Two sockets can have the same address once one's file is removed even without closing the socket.

Sounds good, changed it to "file"; I guess it does not matter what kind of file is preexisting under the desired name.

–Günther