[libvirt] [PATCH] build: fix build on mingw with winpthreads

Eric Blake eblake at redhat.com
Fri Jan 10 21:09:11 UTC 2014

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 passeed 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

* 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 at redhat.com>

Tested for both mingw and Linux; I'll probably push this under
the build-breaker rule on Monday if I don't have a review first.

 configure.ac | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index d02b9d2..f5dccf1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
 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 This library is free software; you can redistribute it and/or
 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.
+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],
+    #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
+    [Define to 1 if pthread_sigmask is not a real function])

 dnl Availability of various common headers (non-fatal if missing).

More information about the libvir-list mailing list