[libvirt] [PATCH 14/15] Add HAVE_PTHREAD_H guard for pthread_sigmask

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Correctly disable pthread related code if pthread is not avialable,
in order to get it compile with MinGW on Windows.
---
 src/remote/remote_driver.c |    6 ++++++
 src/util/util.c            |   10 ++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index b7e1c03..1476f19 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8507,7 +8507,9 @@ remoteIOEventLoop(virConnectPtr conn,
         struct remote_thread_call *tmp = priv->waitDispatch;
         struct remote_thread_call *prev;
         char ignore;
+#ifdef HAVE_PTHREAD_H
         sigset_t oldmask, blockedsigs;
+#endif
 
         fds[0].events = fds[0].revents = 0;
         fds[1].events = fds[1].revents = 0;
@@ -8534,18 +8536,22 @@ remoteIOEventLoop(virConnectPtr conn,
          * after the call (RHBZ#567931).  Same for SIGCHLD and SIGPIPE
          * at the suggestion of Paolo Bonzini and Daniel Berrange.
          */
+#ifdef HAVE_PTHREAD_H
         sigemptyset (&blockedsigs);
         sigaddset (&blockedsigs, SIGWINCH);
         sigaddset (&blockedsigs, SIGCHLD);
         sigaddset (&blockedsigs, SIGPIPE);
         ignore_value (pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
+#endif
 
     repoll:
         ret = poll(fds, ARRAY_CARDINALITY(fds), -1);
         if (ret < 0 && errno == EAGAIN)
             goto repoll;
 
+#ifdef HAVE_PTHREAD_H
         ignore_value (pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
+#endif
 
         remoteDriverLock(priv);
 
diff --git a/src/util/util.c b/src/util/util.c
index c312719..0d5e0a8 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -316,7 +316,9 @@ static int virClearCapabilities(void)
 
  */
 int virFork(pid_t *pid) {
+#  ifdef HAVE_PTHREAD_H
     sigset_t oldmask, newmask;
+#  endif
     struct sigaction sig_action;
     int saved_errno, ret = -1;
 
@@ -326,6 +328,7 @@ int virFork(pid_t *pid) {
      * Need to block signals now, so that child process can safely
      * kill off caller's signal handlers without a race.
      */
+#  ifdef HAVE_PTHREAD_H
     sigfillset(&newmask);
     if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
         saved_errno = errno;
@@ -333,6 +336,7 @@ int virFork(pid_t *pid) {
                              "%s", _("cannot block signals"));
         goto cleanup;
     }
+#  endif
 
     /* Ensure we hold the logging lock, to protect child processes
      * from deadlocking on another thread's inherited mutex state */
@@ -345,9 +349,11 @@ int virFork(pid_t *pid) {
     virLogUnlock();
 
     if (*pid < 0) {
+#  ifdef HAVE_PTHREAD_H
         /* attempt to restore signal mask, but ignore failure, to
            avoid obscuring the fork failure */
         ignore_value (pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
+#  endif
         virReportSystemError(saved_errno,
                              "%s", _("cannot fork child process"));
         goto cleanup;
@@ -357,6 +363,7 @@ int virFork(pid_t *pid) {
 
         /* parent process */
 
+#  ifdef HAVE_PTHREAD_H
         /* Restore our original signal mask now that the child is
            safely running */
         if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
@@ -364,6 +371,7 @@ int virFork(pid_t *pid) {
             virReportSystemError(errno, "%s", _("cannot unblock signals"));
             goto cleanup;
         }
+#  endif
         ret = 0;
 
     } else {
@@ -399,6 +407,7 @@ int virFork(pid_t *pid) {
             sigaction(i, &sig_action, NULL);
         }
 
+#  ifdef HAVE_PTHREAD_H
         /* Unmask all signals in child, since we've no idea
            what the caller's done with their signal mask
            and don't want to propagate that to children */
@@ -408,6 +417,7 @@ int virFork(pid_t *pid) {
             virReportSystemError(errno, "%s", _("cannot unblock signals"));
             goto cleanup;
         }
+#  endif
         ret = 0;
     }
 
-- 
1.6.3.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]