summaryrefslogtreecommitdiffstats
path: root/rpc/rpc-transport/socket
diff options
context:
space:
mode:
authorPranith K <pranithk@gluster.com>2011-03-10 02:18:22 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-10 08:09:30 -0800
commitd23585307a0e333c9b1ff627df4c7e30b3642201 (patch)
tree0e900775fff91686474051cf55375966e7028eec /rpc/rpc-transport/socket
parent45fd0d904d11f07f8b523af2d1357f081e3c5dc1 (diff)
rpc: Changes for handling unix domain sockets avoid race
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1965 (need a cmd to get io-stat details) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1965
Diffstat (limited to 'rpc/rpc-transport/socket')
-rw-r--r--rpc/rpc-transport/socket/src/socket.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c
index 4ae49815a58..cbd303496ae 100644
--- a/rpc/rpc-transport/socket/src/socket.c
+++ b/rpc/rpc-transport/socket/src/socket.c
@@ -298,6 +298,8 @@ __socket_server_bind (rpc_transport_t *this)
socket_private_t *priv = NULL;
int ret = -1;
int opt = 1;
+ int reuse_check_sock = -1;
+ struct sockaddr_storage unix_addr = {0};
if (!this || !this->private)
goto out;
@@ -312,6 +314,20 @@ __socket_server_bind (rpc_transport_t *this)
"setsockopt() for SO_REUSEADDR failed (%s)",
strerror (errno));
}
+ //reuse-address doesnt work for unix type sockets
+ if (AF_UNIX == SA (&this->myinfo.sockaddr)->sa_family) {
+ memcpy (&unix_addr, SA (&this->myinfo.sockaddr),
+ this->myinfo.sockaddr_len);
+ reuse_check_sock = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (reuse_check_sock > 0) {
+ ret = connect (reuse_check_sock, SA (&unix_addr),
+ this->myinfo.sockaddr_len);
+ if ((ret == -1) && (ECONNREFUSED == errno)) {
+ unlink (((struct sockaddr_un*)&unix_addr)->sun_path);
+ }
+ close (reuse_check_sock);
+ }
+ }
ret = bind (priv->sock, (struct sockaddr *)&this->myinfo.sockaddr,
this->myinfo.sockaddr_len);