Add HAVE_PTHREAD_H guard for pthread_sigmask

Correctly disable pthread related code if pthread is not avialable,
in order to get it compile with MinGW on Windows.
This commit is contained in:
Matthias Bolte 2010-03-19 21:09:30 +01:00
parent 2f80b2a013
commit 7233dc170f
2 changed files with 16 additions and 0 deletions

View File

@ -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);

View File

@ -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;
}