mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 04:31:33 +00:00
build: use gnulib pthread_sigmask
Gnulib finally learned how to do pthread_sigmask on mingw. * .gnulib: Update to latest, for pthread_sigmask. * bootstrap.conf (gnulib_modules): Add pthread_sigmask. * configure.ac (AC_CHECK_FUNCS): Drop redundant check. * src/rpc/virnetclient.c (virNetClientSetTLSSession) (virNetClientIOEventLoop): Make code unconditional. * src/util/command.c (virFork): Likewise. * tools/virsh.c (doMigrate, cmdMigrate): Likewise.
This commit is contained in:
parent
c2dda6ebb3
commit
8437e738fa
2
.gnulib
2
.gnulib
@ -1 +1 @@
|
|||||||
Subproject commit c3153d2c0cf5f675ae13ae2bd1dee0f463b9c86a
|
Subproject commit 56005a21e8f9f434212a19dcb628c6d3b179fd08
|
@ -68,6 +68,7 @@ pipe2
|
|||||||
poll
|
poll
|
||||||
posix-shell
|
posix-shell
|
||||||
pthread
|
pthread
|
||||||
|
pthread_sigmask
|
||||||
recv
|
recv
|
||||||
random_r
|
random_r
|
||||||
sched
|
sched
|
||||||
|
@ -130,7 +130,7 @@ dnl assumed). Because of $LIB_PTHREAD, we cannot use AC_CHECK_FUNCS_ONCE.
|
|||||||
dnl LIB_PTHREAD was set during gl_INIT by gnulib.
|
dnl LIB_PTHREAD was set during gl_INIT by gnulib.
|
||||||
old_LIBS=$LIBS
|
old_LIBS=$LIBS
|
||||||
LIBS="$LIBS $LIB_PTHREAD"
|
LIBS="$LIBS $LIB_PTHREAD"
|
||||||
AC_CHECK_FUNCS([pthread_sigmask pthread_mutexattr_init])
|
AC_CHECK_FUNCS([pthread_mutexattr_init])
|
||||||
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).
|
||||||
|
@ -273,14 +273,16 @@ int virNetClientSetTLSSession(virNetClientPtr client,
|
|||||||
char buf[1];
|
char buf[1];
|
||||||
int len;
|
int len;
|
||||||
struct pollfd fds[1];
|
struct pollfd fds[1];
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
sigset_t oldmask, blockedsigs;
|
sigset_t oldmask, blockedsigs;
|
||||||
|
|
||||||
sigemptyset (&blockedsigs);
|
sigemptyset (&blockedsigs);
|
||||||
|
#ifdef SIGWINCH
|
||||||
sigaddset (&blockedsigs, SIGWINCH);
|
sigaddset (&blockedsigs, SIGWINCH);
|
||||||
sigaddset (&blockedsigs, SIGCHLD);
|
|
||||||
sigaddset (&blockedsigs, SIGPIPE);
|
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SIGCHLD
|
||||||
|
sigaddset (&blockedsigs, SIGCHLD);
|
||||||
|
#endif
|
||||||
|
sigaddset (&blockedsigs, SIGPIPE);
|
||||||
|
|
||||||
virNetClientLock(client);
|
virNetClientLock(client);
|
||||||
|
|
||||||
@ -311,18 +313,14 @@ int virNetClientSetTLSSession(virNetClientPtr client,
|
|||||||
* after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE
|
* after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE
|
||||||
* at the suggestion of Paolo Bonzini and Daniel Berrange.
|
* at the suggestion of Paolo Bonzini and Daniel Berrange.
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
|
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
|
||||||
#endif
|
|
||||||
|
|
||||||
repoll:
|
repoll:
|
||||||
ret = poll(fds, ARRAY_CARDINALITY(fds), -1);
|
ret = poll(fds, ARRAY_CARDINALITY(fds), -1);
|
||||||
if (ret < 0 && errno == EAGAIN)
|
if (ret < 0 && errno == EAGAIN)
|
||||||
goto repoll;
|
goto repoll;
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
ignore_value(pthread_sigmask(SIG_BLOCK, &oldmask, NULL));
|
ignore_value(pthread_sigmask(SIG_BLOCK, &oldmask, NULL));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virNetTLSContextCheckCertificate(tls, client->tls);
|
ret = virNetTLSContextCheckCertificate(tls, client->tls);
|
||||||
@ -338,19 +336,15 @@ int virNetClientSetTLSSession(virNetClientPtr client,
|
|||||||
fds[0].revents = 0;
|
fds[0].revents = 0;
|
||||||
fds[0].events = POLLIN;
|
fds[0].events = POLLIN;
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
/* Block SIGWINCH from interrupting poll in curses programs */
|
/* Block SIGWINCH from interrupting poll in curses programs */
|
||||||
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
|
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
|
||||||
#endif
|
|
||||||
|
|
||||||
repoll2:
|
repoll2:
|
||||||
ret = poll(fds, ARRAY_CARDINALITY(fds), -1);
|
ret = poll(fds, ARRAY_CARDINALITY(fds), -1);
|
||||||
if (ret < 0 && errno == EAGAIN)
|
if (ret < 0 && errno == EAGAIN)
|
||||||
goto repoll2;
|
goto repoll2;
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
ignore_value(pthread_sigmask(SIG_BLOCK, &oldmask, NULL));
|
ignore_value(pthread_sigmask(SIG_BLOCK, &oldmask, NULL));
|
||||||
#endif
|
|
||||||
|
|
||||||
len = virNetTLSSessionRead(client->tls, buf, 1);
|
len = virNetTLSSessionRead(client->tls, buf, 1);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
@ -800,9 +794,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
|
|||||||
virNetClientCallPtr tmp = client->waitDispatch;
|
virNetClientCallPtr tmp = client->waitDispatch;
|
||||||
virNetClientCallPtr prev;
|
virNetClientCallPtr prev;
|
||||||
char ignore;
|
char ignore;
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
sigset_t oldmask, blockedsigs;
|
sigset_t oldmask, blockedsigs;
|
||||||
#endif
|
|
||||||
int timeout = -1;
|
int timeout = -1;
|
||||||
|
|
||||||
/* If we have existing SASL decoded data we
|
/* If we have existing SASL decoded data we
|
||||||
@ -841,22 +833,22 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
|
|||||||
* after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE
|
* after the call (RHBZ#567931). Same for SIGCHLD and SIGPIPE
|
||||||
* at the suggestion of Paolo Bonzini and Daniel Berrange.
|
* at the suggestion of Paolo Bonzini and Daniel Berrange.
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
sigemptyset (&blockedsigs);
|
sigemptyset (&blockedsigs);
|
||||||
|
#ifdef SIGWINCH
|
||||||
sigaddset (&blockedsigs, SIGWINCH);
|
sigaddset (&blockedsigs, SIGWINCH);
|
||||||
|
#endif
|
||||||
|
#ifdef SIGCHLD
|
||||||
sigaddset (&blockedsigs, SIGCHLD);
|
sigaddset (&blockedsigs, SIGCHLD);
|
||||||
|
#endif
|
||||||
sigaddset (&blockedsigs, SIGPIPE);
|
sigaddset (&blockedsigs, SIGPIPE);
|
||||||
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
|
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
|
||||||
#endif
|
|
||||||
|
|
||||||
repoll:
|
repoll:
|
||||||
ret = poll(fds, ARRAY_CARDINALITY(fds), timeout);
|
ret = poll(fds, ARRAY_CARDINALITY(fds), timeout);
|
||||||
if (ret < 0 && errno == EAGAIN)
|
if (ret < 0 && errno == EAGAIN)
|
||||||
goto repoll;
|
goto repoll;
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
|
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
|
||||||
#endif
|
|
||||||
|
|
||||||
virNetClientLock(client);
|
virNetClientLock(client);
|
||||||
|
|
||||||
|
@ -145,9 +145,7 @@ static int virClearCapabilities(void)
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
int virFork(pid_t *pid) {
|
int virFork(pid_t *pid) {
|
||||||
# ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
sigset_t oldmask, newmask;
|
sigset_t oldmask, newmask;
|
||||||
# endif
|
|
||||||
struct sigaction sig_action;
|
struct sigaction sig_action;
|
||||||
int saved_errno, ret = -1;
|
int saved_errno, ret = -1;
|
||||||
|
|
||||||
@ -157,7 +155,6 @@ int virFork(pid_t *pid) {
|
|||||||
* Need to block signals now, so that child process can safely
|
* Need to block signals now, so that child process can safely
|
||||||
* kill off caller's signal handlers without a race.
|
* kill off caller's signal handlers without a race.
|
||||||
*/
|
*/
|
||||||
# ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
sigfillset(&newmask);
|
sigfillset(&newmask);
|
||||||
if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
|
if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
|
||||||
saved_errno = errno;
|
saved_errno = errno;
|
||||||
@ -165,7 +162,6 @@ int virFork(pid_t *pid) {
|
|||||||
"%s", _("cannot block signals"));
|
"%s", _("cannot block signals"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
|
|
||||||
/* Ensure we hold the logging lock, to protect child processes
|
/* Ensure we hold the logging lock, to protect child processes
|
||||||
* from deadlocking on another thread's inherited mutex state */
|
* from deadlocking on another thread's inherited mutex state */
|
||||||
@ -178,11 +174,9 @@ int virFork(pid_t *pid) {
|
|||||||
virLogUnlock();
|
virLogUnlock();
|
||||||
|
|
||||||
if (*pid < 0) {
|
if (*pid < 0) {
|
||||||
# ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
/* attempt to restore signal mask, but ignore failure, to
|
/* attempt to restore signal mask, but ignore failure, to
|
||||||
avoid obscuring the fork failure */
|
avoid obscuring the fork failure */
|
||||||
ignore_value (pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
|
ignore_value (pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
|
||||||
# endif
|
|
||||||
virReportSystemError(saved_errno,
|
virReportSystemError(saved_errno,
|
||||||
"%s", _("cannot fork child process"));
|
"%s", _("cannot fork child process"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -192,7 +186,6 @@ int virFork(pid_t *pid) {
|
|||||||
|
|
||||||
/* parent process */
|
/* parent process */
|
||||||
|
|
||||||
# ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
/* Restore our original signal mask now that the child is
|
/* Restore our original signal mask now that the child is
|
||||||
safely running */
|
safely running */
|
||||||
if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
|
if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
|
||||||
@ -200,7 +193,6 @@ int virFork(pid_t *pid) {
|
|||||||
virReportSystemError(errno, "%s", _("cannot unblock signals"));
|
virReportSystemError(errno, "%s", _("cannot unblock signals"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -237,7 +229,6 @@ int virFork(pid_t *pid) {
|
|||||||
sigaction(i, &sig_action, NULL);
|
sigaction(i, &sig_action, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef HAVE_PTHREAD_SIGMASK
|
|
||||||
/* Unmask all signals in child, since we've no idea
|
/* Unmask all signals in child, since we've no idea
|
||||||
what the caller's done with their signal mask
|
what the caller's done with their signal mask
|
||||||
and don't want to propagate that to children */
|
and don't want to propagate that to children */
|
||||||
@ -247,7 +238,6 @@ int virFork(pid_t *pid) {
|
|||||||
virReportSystemError(errno, "%s", _("cannot unblock signals"));
|
virReportSystemError(errno, "%s", _("cannot unblock signals"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4400,14 +4400,12 @@ doMigrate (void *opaque)
|
|||||||
const vshCmd *cmd = data->cmd;
|
const vshCmd *cmd = data->cmd;
|
||||||
const char *xmlfile = NULL;
|
const char *xmlfile = NULL;
|
||||||
char *xml = NULL;
|
char *xml = NULL;
|
||||||
#if HAVE_PTHREAD_SIGMASK
|
|
||||||
sigset_t sigmask, oldsigmask;
|
sigset_t sigmask, oldsigmask;
|
||||||
|
|
||||||
sigemptyset(&sigmask);
|
sigemptyset(&sigmask);
|
||||||
sigaddset(&sigmask, SIGINT);
|
sigaddset(&sigmask, SIGINT);
|
||||||
if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0)
|
if (pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask) < 0)
|
||||||
goto out_sig;
|
goto out_sig;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!vshConnectionUsability (ctl, ctl->conn))
|
if (!vshConnectionUsability (ctl, ctl->conn))
|
||||||
goto out;
|
goto out;
|
||||||
@ -4483,10 +4481,8 @@ doMigrate (void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
#if HAVE_PTHREAD_SIGMASK
|
|
||||||
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
||||||
out_sig:
|
out_sig:
|
||||||
#endif
|
|
||||||
if (dom) virDomainFree (dom);
|
if (dom) virDomainFree (dom);
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
|
||||||
@ -4534,12 +4530,10 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
|
|||||||
struct timeval start, curr;
|
struct timeval start, curr;
|
||||||
bool live_flag = false;
|
bool live_flag = false;
|
||||||
vshCtrlData data;
|
vshCtrlData data;
|
||||||
#if HAVE_PTHREAD_SIGMASK
|
|
||||||
sigset_t sigmask, oldsigmask;
|
sigset_t sigmask, oldsigmask;
|
||||||
|
|
||||||
sigemptyset(&sigmask);
|
sigemptyset(&sigmask);
|
||||||
sigaddset(&sigmask, SIGINT);
|
sigaddset(&sigmask, SIGINT);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
@ -4631,13 +4625,9 @@ repoll:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
#if HAVE_PTHREAD_SIGMASK
|
|
||||||
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
|
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
|
||||||
#endif
|
|
||||||
ret = virDomainGetJobInfo(dom, &jobinfo);
|
ret = virDomainGetJobInfo(dom, &jobinfo);
|
||||||
#if HAVE_PTHREAD_SIGMASK
|
|
||||||
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
|
||||||
#endif
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
print_job_progress(jobinfo.dataRemaining, jobinfo.dataTotal);
|
print_job_progress(jobinfo.dataRemaining, jobinfo.dataTotal);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user