# nfs: a unix-domain-socket should not be created as fifo
# BUG: https://bugzilla.redhat.com/show_bug.cgi?id=1244118
# GERRIT: http://review.gluster.org/#/c/11710/

diff -Naur glusterfs-3.5.2.orig/tests/bugs/nfs/socket-as-fifo.py glusterfs-3.5.2/tests/bugs/nfs/socket-as-fifo.py
--- glusterfs-3.5.2.orig/tests/bugs/nfs/socket-as-fifo.py	1970-01-01 01:00:00.000000000 +0100
+++ glusterfs-3.5.2/tests/bugs/nfs/socket-as-fifo.py	2015-07-29 20:25:20.521530328 +0200
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+#
+# Create a unix domain socket and test if it is a socket (and not a fifo/pipe).
+#
+# Author: Niels de Vos <ndevos@redhat.com>
+#
+
+import os
+import stat
+import sys
+import socket
+
+ret = 1
+
+if len(sys.argv) != 2:
+        print 'Usage: %s <socket>' % (sys.argv[0])
+        sys.exit(ret)
+
+path = sys.argv[1]
+
+sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+sock.bind(path)
+
+stbuf = os.stat(path)
+mode = stbuf.st_mode
+
+if stat.S_ISSOCK(mode):
+        ret = 0
+
+sock.close()
+os.unlink(path)
+
+sys.exit(ret)
diff -Naur glusterfs-3.5.2.orig/tests/bugs/nfs/socket-as-fifo.t glusterfs-3.5.2/tests/bugs/nfs/socket-as-fifo.t
--- glusterfs-3.5.2.orig/tests/bugs/nfs/socket-as-fifo.t	1970-01-01 01:00:00.000000000 +0100
+++ glusterfs-3.5.2/tests/bugs/nfs/socket-as-fifo.t	2015-07-29 20:25:20.521530328 +0200
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+. $(dirname $0)/../../nfs.rc
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+
+TEST $CLI volume create $V0 $H0:$B0/$V0
+TEST $CLI volume start $V0
+EXPECT_WITHIN $NFS_EXPORT_TIMEOUT "1" is_nfs_export_available;
+TEST mount_nfs $H0:/$V0 $N0 nolock
+
+# this is the actual test
+TEST $(dirname $0)/socket-as-fifo.py $N0/not-a-fifo.socket
+
+TEST umount_nfs $N0
+
+cleanup
diff -Naur glusterfs-3.5.2.orig/xlators/nfs/server/src/nfs3.c glusterfs-3.5.2/xlators/nfs/server/src/nfs3.c
--- glusterfs-3.5.2.orig/xlators/nfs/server/src/nfs3.c	2014-07-31 13:05:35.000000000 +0200
+++ glusterfs-3.5.2/xlators/nfs/server/src/nfs3.c	2015-07-29 20:25:20.525530253 +0200
@@ -3158,11 +3158,10 @@
 
 
 int
-nfs3_mknod_fifo (nfs3_call_state_t *cs)
+nfs3_mknod_fifo (nfs3_call_state_t *cs, mode_t mode)
 {
         int                             ret = -EFAULT;
         nfs_user_t                      nfu = {0, };
-        mode_t                          mode = S_IFIFO;
 
         if (!cs)
                 return ret;
@@ -3200,8 +3199,10 @@
                 ret = nfs3_mknod_device (cs);
                 break;
         case NF3SOCK:
+                ret = nfs3_mknod_fifo (cs, S_IFSOCK);
+                break;
         case NF3FIFO:
-                ret = nfs3_mknod_fifo (cs);
+                ret = nfs3_mknod_fifo (cs, S_IFIFO);
                 break;
         default:
                 ret = -EBADF;
