From 4ae887db6b770584219fab484dec027d278baef9 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Fri, 8 Aug 2014 06:12:04 +0200 Subject: Regression test portability: mknod Linux mknod(2) is able to create fifo and named sockets. NetBSD and FreeBSD use mkfifo(2) and socket(2)/bind(2) for that. BUG: 764655 Change-Id: I1d3969e3fcb6afdbd184c28bd268ffa2da7ae202 Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/8433 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- tests/basic/fops-sanity.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests') diff --git a/tests/basic/fops-sanity.c b/tests/basic/fops-sanity.c index 4dbb42fd82b..4f35a46e219 100644 --- a/tests/basic/fops-sanity.c +++ b/tests/basic/fops-sanity.c @@ -27,6 +27,12 @@ #include #include +#ifndef linux +#include +#include +#include +#endif + /* for fd based fops after unlink */ int fd_based_fops_1 (char *filename); /* for fd based fops before unlink */ @@ -452,7 +458,11 @@ path_based_fops (char *filename) } unlink("bspecial"); +#ifdef linux ret = mknod ("fifo", S_IFIFO|S_IRWXU|S_IRWXG, 0); +#else + ret = mkfifo ("fifo", 0); +#endif if (ret < 0) { fprintf (stderr, "fifo mknod failed: %s\n", strerror(errno)); @@ -460,12 +470,31 @@ path_based_fops (char *filename) } unlink("fifo"); +#ifdef linux ret = mknod ("sock", S_IFSOCK|S_IRWXU|S_IRWXG, 0); if (ret < 0) { fprintf (stderr, "sock mknod failed: %s\n", strerror(errno)); result |= ret; } +#else + { + int s; + const char *pathname = "sock"; + struct sockaddr_un addr; + + s = socket(PF_LOCAL, SOCK_STREAM, 0); + memset(&addr, 0, sizeof(addr)); + strncpy(addr.sun_path, pathname, sizeof(addr.sun_path)); + ret = bind(s, (const struct sockaddr *)&addr, SUN_LEN(&addr)); + if (ret < 0) { + fprintf (stderr, "fifo mknod failed: %s\n", + strerror(errno)); + result |= ret; + } + close(s); + } +#endif unlink("sock"); strcpy (newfilename, filename); -- cgit