1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

build: fix build on mingw with winpthreads

On my Fedora 20 box with mingw cross-compiler, the build failed with:

../../src/rpc/virnetclient.c: In function 'virNetClientSetTLSSession':
../../src/rpc/virnetclient.c:745:14: error: unused variable 'oldmask' [-Werror=unused-variable]
     sigset_t oldmask, blockedsigs;
              ^

I traced it to the fact that mingw64-winpthreads installs a header
that does #define pthread_sigmask(...) 0, which means any argument
only ever passed to pthread_sigmask is reported as unused.  This
patch works around the compilation failure, with behavior no worse
than what mingw already gives us regarding the function being a
no-op.

* configure.ac (pthread_sigmask): Probe for broken mingw macro.
* src/util/virutil.h (pthread_sigmask): Rewrite to something that
avoids unused variables.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2014-01-10 14:01:10 -07:00
parent d952619894
commit c91d13bd0f
2 changed files with 36 additions and 6 deletions

View File

@ -1,6 +1,6 @@
dnl Process this file with autoconf to produce a configure script. dnl Process this file with autoconf to produce a configure script.
dnl Copyright (C) 2005-2013 Red Hat, Inc. dnl Copyright (C) 2005-2014 Red Hat, Inc.
dnl dnl
dnl This library is free software; you can redistribute it and/or dnl This library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public dnl modify it under the terms of the GNU Lesser General Public
@ -276,6 +276,22 @@ dnl LIB_PTHREAD and LIBMULTITHREAD were set during gl_INIT by gnulib.
old_LIBS=$LIBS old_LIBS=$LIBS
LIBS="$LIBS $LIB_PTHREAD $LIBMULTITHREAD" LIBS="$LIBS $LIB_PTHREAD $LIBMULTITHREAD"
AC_CHECK_FUNCS([pthread_mutexattr_init]) AC_CHECK_FUNCS([pthread_mutexattr_init])
dnl At least mingw64-winpthreads #defines pthread_sigmask to 0,
dnl which in turn causes compilation to complain about unused variables.
dnl Expose this broken implementation, so we can work around it.
AC_CACHE_CHECK([whether pthread_sigmask does anything],
[lv_cv_pthread_sigmask_works],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <signal.h>
]], [[
int (*foo)(int, const sigset_t *, sigset_t *) = &pthread_sigmask;
return !foo;
]])], [lv_cv_pthread_sigmask_works=yes], [lv_cv_pthread_sigmask_works=no])])
if test "x$lv_cv_pthread_sigmask_works" != xyes; then
AC_DEFINE([FUNC_PTHREAD_SIGMASK_BROKEN], [1],
[Define to 1 if pthread_sigmask is not a real function])
fi
LIBS=$old_libs LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing). dnl Availability of various common headers (non-fatal if missing).

View File

@ -1,7 +1,7 @@
/* /*
* virutil.h: common, generic utility functions * virutil.h: common, generic utility functions
* *
* Copyright (C) 2010-2013 Red Hat, Inc. * Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright (C) 2006, 2007 Binary Karma * Copyright (C) 2006, 2007 Binary Karma
* Copyright (C) 2006 Shuveb Hussain * Copyright (C) 2006 Shuveb Hussain
* *
@ -96,20 +96,34 @@ const char *virEnumToString(const char *const*types,
const char *name ## TypeToString(int type); \ const char *name ## TypeToString(int type); \
int name ## TypeFromString(const char*type); int name ## TypeFromString(const char*type);
/* No-op workarounds for functionality missing in mingw. */
# ifndef HAVE_GETUID # ifndef HAVE_GETUID
static inline int getuid (void) { return 0; } static inline int getuid(void) { return 0; }
# endif # endif
# ifndef HAVE_GETEUID # ifndef HAVE_GETEUID
static inline int geteuid (void) { return 0; } static inline int geteuid(void) { return 0; }
# endif # endif
# ifndef HAVE_GETGID # ifndef HAVE_GETGID
static inline int getgid (void) { return 0; } static inline int getgid(void) { return 0; }
# endif # endif
# ifndef HAVE_GETEGID # ifndef HAVE_GETEGID
static inline int getegid (void) { return 0; } static inline int getegid(void) { return 0; }
# endif
# ifdef FUNC_PTHREAD_SIGMASK_BROKEN
# undef pthread_sigmask
static inline int pthread_sigmask(int how,
const void *set,
void *old)
{
(void) how;
(void) set;
(void) old;
return 0;
}
# endif # endif
char *virGetHostname(void); char *virGetHostname(void);