From: Ed Schouten <hidden> Date: 2016-03-03 11:23:08
If a UNIX socket does not have an address associated with it, it may
either be that a socket has been created through socket() and is still
in its initial state, or it has connected to a peer (e.g. by using
socketpair()). In both those cases listen() should fail.
Though the condition used to test for condition this is all right, POSIX
requires that two different error codes are returned: EINVAL if already
connected and EDESTADDRREQ if not bound.
Reference:
http://pubs.opengroup.org/onlinepubs/009695399/functions/listen.html
Signed-off-by: Ed Schouten <redacted>
---
net/unix/af_unix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -609,9 +609,9 @@ static int unix_listen(struct socket *sock, int backlog)err=-EOPNOTSUPP;if(sock->type!=SOCK_STREAM&&sock->type!=SOCK_SEQPACKET)gotoout;/* Only stream/seqpacket sockets accept */-err=-EINVAL;+err=unix_peer(sk)==NULL?-EDESTADDRREQ:-EINVAL;if(!u->addr)-gotoout;/* No listens on an unbound socket */+gotoout;/* No listen on a connected or unbound socket */unix_state_lock(sk);if(sk->sk_state!=TCP_CLOSE&&sk->sk_state!=TCP_LISTEN)gotoout_unlock;
From: Ed Schouten <hidden> Date: 2016-03-03 11:23:12
The POSIX article on open() is slightly confusing that it states which
error code needs to be returned when opened on a stale FIFO, character
device or block device (ENXIO), but fails to explicitly mention which
code should be returned when trying to open a UNIX socket. This is only
mentioned in a different chapter of the standard (EOPNOTSUPP).
While discussing this matter with the Austin Group, it turns out most
other systems (BSDs, HP-UX, Solaris) do return EOPNOTSUPP. The open()
article has since been extended to require this. Let's go ahead and stay
in sync with the rest.
References:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.htmlhttp://austingroupbugs.net/view.php?id=943
Signed-off-by: Ed Schouten <redacted>
---
fs/inode.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
From: Ed Schouten <hidden> Date: 2016-03-03 11:23:13
Both POSIX and our manual pages state that if send() or recv() is called
on an unconnected socket, ENOTCONN should be returned. It looks like our
implementation of send() already does this, but recv() does not.
Reference:
http://pubs.opengroup.org/onlinepubs/009695399/functions/send.html
Signed-off-by: Ed Schouten <redacted>
---
net/unix/af_unix.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)