Thread (3 messages) 3 messages, 1 author, 2016-03-03

[PATCH 2/3] Let open() on a UNIX socket return EOPNOTSUPP.

flat view
STALE3878d

From: Ed Schouten <hidden>
Date: 2016-03-03 11:23:12
Subsystem: filesystems (vfs and infrastructure), the rest · Maintainers: Alexander Viro, Christian Brauner, Linus Torvalds

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.html
http://austingroupbugs.net/view.php?id=943

Signed-off-by: Ed Schouten <redacted>
---
 fs/inode.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/fs/inode.c b/fs/inode.c
index 69b8b52..6e63ca7 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1911,8 +1911,15 @@ void __init inode_init(void)
 		INIT_HLIST_HEAD(&inode_hashtable[loop]);
 }
 
+static int no_open_sock(struct inode *inode, struct file *file)
+{
+	return -EOPNOTSUPP;
+}
+
 void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
 {
+	static const struct file_operations sock_fops = {.open = no_open_sock};
+
 	inode->i_mode = mode;
 	if (S_ISCHR(mode)) {
 		inode->i_fop = &def_chr_fops;
@@ -1923,7 +1930,11 @@ void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
 	} else if (S_ISFIFO(mode))
 		inode->i_fop = &pipefifo_fops;
 	else if (S_ISSOCK(mode))
-		;	/* leave it no_open_fops */
+		/*
+		 * open() on a socket needs to return EOPNOTSUPP,
+		 * whereas the default inode operations return ENXIO.
+		 */
+		inode->i_fop = &sock_fops;
 	else
 		printk(KERN_DEBUG "init_special_inode: bogus i_mode (%o) for"
 				  " inode %s:%lu\n", mode, inode->i_sb->s_id,
-- 
2.5.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help