changeset 119:1a6520cd3e0d

cmake: check XDR struct xdr_ops member types Illumos and Linux have slightly different function signatures. To avoid warnings on both, check that the types and tweak the function signatures accordingly. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 17 Oct 2015 19:25:41 -0400
parents d01f527b9718
children ba786304afb3
files cmake/config.cmake cmake/config/xdr.cmake src/common/include/nomad/config.h.in src/common/xdrfd.c
diffstat 4 files changed, 74 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cmake/config.cmake	Sat Oct 17 19:05:15 2015 -0400
+++ b/cmake/config.cmake	Sat Oct 17 19:25:41 2015 -0400
@@ -21,12 +21,15 @@
 #
 
 include(CheckFunctionExists)
+include(CheckCSourceCompiles)
 
 check_function_exists(arc4random HAVE_ARC4RANDOM)
 check_function_exists(pthread_cond_reltimedwait_np HAVE_PTHREAD_COND_RELTIMEDWAIT_NP)
 check_function_exists(assfail HAVE_ASSFAIL)
 check_function_exists(assfail3 HAVE_ASSFAIL3)
 
+include(cmake/config/xdr.cmake)
+
 set(CMAKE_MODULE_PATH "${CMAKE_DIR}/Modules")
 find_package(umem)
 find_package(avl)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmake/config/xdr.cmake	Sat Oct 17 19:25:41 2015 -0400
@@ -0,0 +1,48 @@
+#
+# Copyright (c) 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+#
+
+set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror")
+
+macro(xdr_check var op args)
+	check_c_source_compiles("
+#include <rpc/rpc.h>
+
+static bool_t fxn(XDR *xdr, ${args})
+{
+	return FALSE;
+}
+
+static const struct xdr_ops ops = {
+	.x_${op} = fxn,
+};
+
+int main()
+{
+	return 0;
+}
+" ${var})
+endmacro()
+
+xdr_check(HAVE_XDR_GETBYTES_UINT_ARG "getbytes" "caddr_t addr, u_int len")
+xdr_check(HAVE_XDR_PUTBYTES_CONST_CHAR_ARG "putbytes" "const char *addr, u_int len")
+xdr_check(HAVE_XDR_PUTINT32_CONST_ARG "putint32" "const int32_t *ptr")
+xdr_check(HAVE_XDR_PUTLONG_CONST_ARG "putlong" "const long *ptr")
--- a/src/common/include/nomad/config.h.in	Sat Oct 17 19:05:15 2015 -0400
+++ b/src/common/include/nomad/config.h.in	Sat Oct 17 19:25:41 2015 -0400
@@ -28,4 +28,9 @@
 #cmakedefine HAVE_ASSFAIL 1
 #cmakedefine HAVE_ASSFAIL3 1
 
+#cmakedefine HAVE_XDR_GETBYTES_UINT_ARG 1
+#cmakedefine HAVE_XDR_PUTBYTES_CONST_CHAR_ARG 1
+#cmakedefine HAVE_XDR_PUTINT32_CONST_ARG 1
+#cmakedefine HAVE_XDR_PUTLONG_CONST_ARG 1
+
 #endif
--- a/src/common/xdrfd.c	Sat Oct 17 19:05:15 2015 -0400
+++ b/src/common/xdrfd.c	Sat Oct 17 19:25:41 2015 -0400
@@ -22,6 +22,7 @@
 
 #include <unistd.h>
 
+#include <nomad/config.h>
 #include <nomad/error.h>
 #include <nomad/rpc.h>
 
@@ -54,7 +55,7 @@
 	return total;
 }
 
-static ssize_t safe_write(int fd, void *buf, size_t nbyte)
+static ssize_t safe_write(int fd, const void *buf, size_t nbyte)
 {
 	const char *ptr = buf;
 	size_t total;
@@ -78,7 +79,11 @@
 	return total;
 }
 
+#ifdef HAVE_XDR_GETBYTES_UINT_ARG
+static bool_t xdrfd_getbytes(XDR *xdr, caddr_t addr, u_int len)
+#else
 static bool_t xdrfd_getbytes(XDR *xdr, caddr_t addr, int len)
+#endif
 {
 	int fd = xdr->x_handy;
 
@@ -87,7 +92,11 @@
 	return TRUE;
 }
 
+#ifdef HAVE_XDR_PUTBYTES_CONST_CHAR_ARG
+static bool_t xdrfd_putbytes(XDR *xdr, const char *addr, u_int len)
+#else
 static bool_t xdrfd_putbytes(XDR *xdr, caddr_t addr, int len)
+#endif
 {
 	int fd = xdr->x_handy;
 
@@ -113,7 +122,11 @@
 	return TRUE;
 }
 
+#ifdef HAVE_XDR_PUTINT32_CONST_ARG
+static bool_t xdrfd_putint32(XDR *xdr, const int32_t *p)
+#else
 static bool_t xdrfd_putint32(XDR *xdr, int32_t *p)
+#endif
 {
 	int fd = xdr->x_handy;
 	int32_t buf;
@@ -137,7 +150,11 @@
         return TRUE;
 }
 
+#ifdef HAVE_XDR_PUTLONG_CONST_ARG
+static bool_t xdrfd_putlong(XDR *xdrs, const long *p)
+#else
 static bool_t xdrfd_putlong(XDR *xdrs, long *p)
+#endif
 {
         int32_t tmp = *p;