2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 06:15:47 +00:00

socket-util: Use portable solution for setting Unix socket permissions.

Requested-by: Jesse Gross <jesse@nicira.com>
This commit is contained in:
Ben Pfaff
2011-04-21 09:22:39 -07:00
parent 7321e30ecc
commit 2cb351e851

View File

@@ -306,18 +306,11 @@ make_sockaddr_un(const char *name, struct sockaddr_un *un, socklen_t *un_len,
static int
bind_unix_socket(int fd, struct sockaddr *sun, socklen_t sun_len)
{
#ifdef __linux__
/* On Linux, calling fchmod() *before* bind() sets permissions for the file
* about to be created. Calling fchmod() *after* bind has no effect on the
* file that was created.) */
return fchmod(fd, 0700) || bind(fd, sun, sun_len) ? errno : 0;
#else
/* According to _Unix Network Programming_, umask should affect bind(). */
mode_t old_umask = umask(0077);
int error = bind(fd, sun, sun_len) ? errno : 0;
umask(old_umask);
return error;
#endif
}
/* Creates a Unix domain socket in the given 'style' (either SOCK_DGRAM or