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 <e...@nuxi.nl> --- 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