[libvirt] [PATCH v2 1/3] cgroup: don't include sys/mount.h if not needed

From: Jasper Lievisse Adriaanse <jasper@openbsd.org> As cgroup implementation only works on Linux, it does not make much sense to include sys/mount.h if other requirements are not met, such as HAVE_MNTENT_H and HAVE_GETMNTENT_R. Also, it fixes build on OpenBSD that requires to include sys/param.h along with sys/mount.h. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/util/vircgroup.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e39c4d1..78f519c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -24,10 +24,9 @@ #include <config.h> #include <stdio.h> -#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R +#if defined HAVE_MNTENT_H && defined HAVE_SYS_MOUNT_H \ + && defined HAVE_GETMNTENT_R # include <mntent.h> -#endif -#if defined HAVE_SYS_MOUNT_H # include <sys/mount.h> #endif #include <fcntl.h> -- 2.4.6

From: Jasper Lievisse Adriaanse <jasper@openbsd.org> OpenBSD uses 'struct sockpeercred' instead of 'struct ucred'. Add a configure check that detects its presence and use if in the code that could be compiled on OpenBSD. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- configure.ac | 6 ++++++ src/rpc/virnetsocket.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/configure.ac b/configure.ac index a46f9b3..2acc0f2 100644 --- a/configure.ac +++ b/configure.ac @@ -393,6 +393,12 @@ AC_CHECK_TYPE([struct ifreq], #include <net/if.h> ]]) +AC_CHECK_TYPE([struct sockpeercred], + [AC_DEFINE([HAVE_STRUCT_SOCKPEERCRED], [1], + [Defined if struct sockpeercred is available])], + [], [[#include <sys/socket.h> + ]]) + AC_CHECK_DECLS([ETH_FLAG_TXVLAN, ETH_FLAG_NTUPLE, ETH_FLAG_RXHASH, ETH_FLAG_LRO, ETHTOOL_GGSO, ETHTOOL_GGRO, ETHTOOL_GFLAGS, ETHTOOL_GFEATURES], [], [], [[#include <linux/ethtool.h> diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 526d291..4f67c8f 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1259,7 +1259,11 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, pid_t *pid, unsigned long long *timestamp) { +# if defined(HAVE_STRUCT_SOCKPEERCRED) + struct sockpeercred cr; +# else struct ucred cr; +# endif socklen_t cr_len = sizeof(cr); int ret = -1; -- 2.4.6

From: Jasper Lievisse Adriaanse <jasper@openbsd.org> Some of the protocol files already include handing of the missing int types such as xdr_uint64_t, some don't. To fix it everywhere, move out of the appropriate defines to the utils/virxdrdefs.h file and include it where needed. Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/Makefile.am | 1 + src/admin/admin_protocol.x | 2 ++ src/lxc/lxc_monitor_protocol.x | 19 +------------------ src/remote/remote_protocol.x | 20 +------------------- src/rpc/virnetprotocol.x | 20 +------------------- src/util/virxdrdefs.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 56 deletions(-) create mode 100644 src/util/virxdrdefs.h diff --git a/src/Makefile.am b/src/Makefile.am index af22fc1..aa5ab69 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -171,6 +171,7 @@ UTIL_SOURCES = \ util/viruri.h util/viruri.c \ util/virutil.c util/virutil.h \ util/viruuid.c util/viruuid.h \ + util/virxdrdefs.h \ util/virxml.c util/virxml.h \ $(NULL) diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x index 878983d..711201a 100644 --- a/src/admin/admin_protocol.x +++ b/src/admin/admin_protocol.x @@ -22,6 +22,8 @@ * Author: Martin Kletzander <mkletzan@redhat.com> */ +%#include "virxdrdefs.h" + /*----- Data types. -----*/ /* Length of long, but not unbounded, strings. diff --git a/src/lxc/lxc_monitor_protocol.x b/src/lxc/lxc_monitor_protocol.x index 205d7c2..5e3d5d9 100644 --- a/src/lxc/lxc_monitor_protocol.x +++ b/src/lxc/lxc_monitor_protocol.x @@ -4,24 +4,7 @@ * the libvirt_lxc helper program. */ -/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t - * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 - */ -%#ifdef HAVE_XDR_U_INT64_T -%# define xdr_uint64_t xdr_u_int64_t -%#endif -%#ifndef IXDR_PUT_INT32 -%# define IXDR_PUT_INT32 IXDR_PUT_LONG -%#endif -%#ifndef IXDR_GET_INT32 -%# define IXDR_GET_INT32 IXDR_GET_LONG -%#endif -%#ifndef IXDR_PUT_U_INT32 -%# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG -%#endif -%#ifndef IXDR_GET_U_INT32 -%# define IXDR_GET_U_INT32 IXDR_GET_U_LONG -%#endif +%#include "virxdrdefs.h" enum virLXCMonitorExitStatus { VIR_LXC_MONITOR_EXIT_STATUS_ERROR, diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 80f4a8b..9f131f8 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -38,27 +38,9 @@ %#include <libvirt/libvirt.h> %#include "internal.h" +%#include "virxdrdefs.h" %#include <arpa/inet.h> -/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t - * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 - */ -%#ifdef HAVE_XDR_U_INT64_T -%# define xdr_uint64_t xdr_u_int64_t -%#endif -%#ifndef IXDR_PUT_INT32 -%# define IXDR_PUT_INT32 IXDR_PUT_LONG -%#endif -%#ifndef IXDR_GET_INT32 -%# define IXDR_GET_INT32 IXDR_GET_LONG -%#endif -%#ifndef IXDR_PUT_U_INT32 -%# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG -%#endif -%#ifndef IXDR_GET_U_INT32 -%# define IXDR_GET_U_INT32 IXDR_GET_U_LONG -%#endif - /*----- Data types. -----*/ /* Length of long, but not unbounded, strings. diff --git a/src/rpc/virnetprotocol.x b/src/rpc/virnetprotocol.x index 7b6f753..327a334 100644 --- a/src/rpc/virnetprotocol.x +++ b/src/rpc/virnetprotocol.x @@ -21,27 +21,9 @@ */ %#include "internal.h" +%#include "virxdrdefs.h" %#include <arpa/inet.h> -/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t - * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 - */ -%#ifdef HAVE_XDR_U_INT64_T -%# define xdr_uint64_t xdr_u_int64_t -%#endif -%#ifndef IXDR_PUT_INT32 -%# define IXDR_PUT_INT32 IXDR_PUT_LONG -%#endif -%#ifndef IXDR_GET_INT32 -%# define IXDR_GET_INT32 IXDR_GET_LONG -%#endif -%#ifndef IXDR_PUT_U_INT32 -%# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG -%#endif -%#ifndef IXDR_GET_U_INT32 -%# define IXDR_GET_U_INT32 IXDR_GET_U_LONG -%#endif - /*----- Data types. -----*/ /* Initial message size. diff --git a/src/util/virxdrdefs.h b/src/util/virxdrdefs.h new file mode 100644 index 0000000..40074dd --- /dev/null +++ b/src/util/virxdrdefs.h @@ -0,0 +1,43 @@ +/* + * virxdrdefs.h + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef __VIR_XDRDEFS_H__ +# define __VIR_XDRDEFS_H__ + +/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t + * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 + */ +# ifdef HAVE_XDR_U_INT64_T +# define xdr_uint64_t xdr_u_int64_t +# endif +# ifndef IXDR_PUT_INT32 +# define IXDR_PUT_INT32 IXDR_PUT_LONG +# endif +# ifndef IXDR_GET_INT32 +# define IXDR_GET_INT32 IXDR_GET_LONG +# endif +# ifndef IXDR_PUT_U_INT32 +# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG +# endif +# ifndef IXDR_GET_U_INT32 +# define IXDR_GET_U_INT32 IXDR_GET_U_LONG +# endif + +#endif /* __VIR_XDRDEFS_H__ */ -- 2.4.6

Should this patch by itself be enough to fix the OSX compilation problem? :) eg should I test it with just this? + Justin On 2016-01-11 00:34, Roman Bogorodskiy wrote:
From: Jasper Lievisse Adriaanse <jasper@openbsd.org>
Some of the protocol files already include handing of the missing int types such as xdr_uint64_t, some don't. To fix it everywhere, move out of the appropriate defines to the utils/virxdrdefs.h file and include it where needed.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com> --- src/Makefile.am | 1 + src/admin/admin_protocol.x | 2 ++ src/lxc/lxc_monitor_protocol.x | 19 +------------------ src/remote/remote_protocol.x | 20 +------------------- src/rpc/virnetprotocol.x | 20 +------------------- src/util/virxdrdefs.h | 43 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 49 insertions(+), 56 deletions(-) create mode 100644 src/util/virxdrdefs.h
diff --git a/src/Makefile.am b/src/Makefile.am index af22fc1..aa5ab69 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -171,6 +171,7 @@ UTIL_SOURCES = \ util/viruri.h util/viruri.c \ util/virutil.c util/virutil.h \ util/viruuid.c util/viruuid.h \ + util/virxdrdefs.h \ util/virxml.c util/virxml.h \ $(NULL)
diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x index 878983d..711201a 100644 --- a/src/admin/admin_protocol.x +++ b/src/admin/admin_protocol.x @@ -22,6 +22,8 @@ * Author: Martin Kletzander <mkletzan@redhat.com> */
+%#include "virxdrdefs.h" + /*----- Data types. -----*/
/* Length of long, but not unbounded, strings. diff --git a/src/lxc/lxc_monitor_protocol.x b/src/lxc/lxc_monitor_protocol.x index 205d7c2..5e3d5d9 100644 --- a/src/lxc/lxc_monitor_protocol.x +++ b/src/lxc/lxc_monitor_protocol.x @@ -4,24 +4,7 @@ * the libvirt_lxc helper program. */
-/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t - * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 - */ -%#ifdef HAVE_XDR_U_INT64_T -%# define xdr_uint64_t xdr_u_int64_t -%#endif -%#ifndef IXDR_PUT_INT32 -%# define IXDR_PUT_INT32 IXDR_PUT_LONG -%#endif -%#ifndef IXDR_GET_INT32 -%# define IXDR_GET_INT32 IXDR_GET_LONG -%#endif -%#ifndef IXDR_PUT_U_INT32 -%# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG -%#endif -%#ifndef IXDR_GET_U_INT32 -%# define IXDR_GET_U_INT32 IXDR_GET_U_LONG -%#endif +%#include "virxdrdefs.h"
enum virLXCMonitorExitStatus { VIR_LXC_MONITOR_EXIT_STATUS_ERROR, diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 80f4a8b..9f131f8 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -38,27 +38,9 @@
%#include <libvirt/libvirt.h> %#include "internal.h" +%#include "virxdrdefs.h" %#include <arpa/inet.h>
-/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t - * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 - */ -%#ifdef HAVE_XDR_U_INT64_T -%# define xdr_uint64_t xdr_u_int64_t -%#endif -%#ifndef IXDR_PUT_INT32 -%# define IXDR_PUT_INT32 IXDR_PUT_LONG -%#endif -%#ifndef IXDR_GET_INT32 -%# define IXDR_GET_INT32 IXDR_GET_LONG -%#endif -%#ifndef IXDR_PUT_U_INT32 -%# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG -%#endif -%#ifndef IXDR_GET_U_INT32 -%# define IXDR_GET_U_INT32 IXDR_GET_U_LONG -%#endif - /*----- Data types. -----*/
/* Length of long, but not unbounded, strings. diff --git a/src/rpc/virnetprotocol.x b/src/rpc/virnetprotocol.x index 7b6f753..327a334 100644 --- a/src/rpc/virnetprotocol.x +++ b/src/rpc/virnetprotocol.x @@ -21,27 +21,9 @@ */
%#include "internal.h" +%#include "virxdrdefs.h" %#include <arpa/inet.h>
-/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t - * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 - */ -%#ifdef HAVE_XDR_U_INT64_T -%# define xdr_uint64_t xdr_u_int64_t -%#endif -%#ifndef IXDR_PUT_INT32 -%# define IXDR_PUT_INT32 IXDR_PUT_LONG -%#endif -%#ifndef IXDR_GET_INT32 -%# define IXDR_GET_INT32 IXDR_GET_LONG -%#endif -%#ifndef IXDR_PUT_U_INT32 -%# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG -%#endif -%#ifndef IXDR_GET_U_INT32 -%# define IXDR_GET_U_INT32 IXDR_GET_U_LONG -%#endif - /*----- Data types. -----*/
/* Initial message size. diff --git a/src/util/virxdrdefs.h b/src/util/virxdrdefs.h new file mode 100644 index 0000000..40074dd --- /dev/null +++ b/src/util/virxdrdefs.h @@ -0,0 +1,43 @@ +/* + * virxdrdefs.h + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef __VIR_XDRDEFS_H__ +# define __VIR_XDRDEFS_H__ + +/* cygwin's xdr implementation defines xdr_u_int64_t instead of xdr_uint64_t + * and lacks IXDR_PUT_INT32 and IXDR_GET_INT32 + */ +# ifdef HAVE_XDR_U_INT64_T +# define xdr_uint64_t xdr_u_int64_t +# endif +# ifndef IXDR_PUT_INT32 +# define IXDR_PUT_INT32 IXDR_PUT_LONG +# endif +# ifndef IXDR_GET_INT32 +# define IXDR_GET_INT32 IXDR_GET_LONG +# endif +# ifndef IXDR_PUT_U_INT32 +# define IXDR_PUT_U_INT32 IXDR_PUT_U_LONG +# endif +# ifndef IXDR_GET_U_INT32 +# define IXDR_GET_U_INT32 IXDR_GET_U_LONG +# endif + +#endif /* __VIR_XDRDEFS_H__ */

Justin Clift wrote:
Should this patch by itself be enough to fix the OSX compilation problem? :)
eg should I test it with just this?
Yeah, it should. One thing, though: it patches the .x files, not the generated files. On OpenBSD I wasn't able to build things from git because rpcgen fails on some other things (does not seem to handle the 'hyper' type). So I had to create dist to test this. I'm not sure if OS X is affected by this rpcgen issue as well. Roman Bogorodskiy

On Mon, Jan 11, 2016 at 03:34:05AM +0300, Roman Bogorodskiy wrote:
From: Jasper Lievisse Adriaanse <jasper@openbsd.org>
Some of the protocol files already include handing of the missing int types such as xdr_uint64_t, some don't. To fix it everywhere, move out of the appropriate defines to the utils/virxdrdefs.h file and include it where needed.
ACK to all three, thanks for that.

Martin Kletzander wrote:
On Mon, Jan 11, 2016 at 03:34:05AM +0300, Roman Bogorodskiy wrote:
From: Jasper Lievisse Adriaanse <jasper@openbsd.org>
Some of the protocol files already include handing of the missing int types such as xdr_uint64_t, some don't. To fix it everywhere, move out of the appropriate defines to the utils/virxdrdefs.h file and include it where needed.
ACK to all three, thanks for that.
Pushed, thanks! Roman Bogorodskiy
participants (3)
-
Justin Clift
-
Martin Kletzander
-
Roman Bogorodskiy