提交 7233dc17 编写于 作者: M Matthias Bolte

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.
上级 2f80b2a0
......@@ -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);
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册