socket-util: Properly set socket permissions in make_unix_socket().
authorBen Pfaff <blp@nicira.com>
Mon, 18 Apr 2011 18:24:50 +0000 (11:24 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 Apr 2011 21:31:59 +0000 (14:31 -0700)
commit2556693b6dfa48afdd39c891350fb6e0a8013374
tree54ef3c6c68e01f0760aa22390b1fde655e620010
parentc100c5cadcfbaf2fb55720f94c385cc0955a520a
socket-util: Properly set socket permissions in make_unix_socket().

Under Linux, at least, bind and fchmod interact for Unix sockets in a way
that surprised me.  Calling fchmod() on a Unix socket successfully sets the
permissions for the socket's own inode.  But that has no effect on any
inode that has already been created in the file system by bind(), because
that inode is not the same as the one for the Unix socket itself.

However, if you bind() *after* calling fchmod(), then the bind() takes the
permissions for the new inode from the Unix socket inode, which has the
desired effect.

This also adds a more portable fallback for non-Linux systems.

Reported-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
lib/socket-util.c