提交 ff627b47 编写于 作者: D Daniel P. Berrangé

rpc: conditionalize signal handling

The Windows platform does not have the signal handling
support we need, so it must be disabled in several parts
of the codebase.
Reviewed-by: NPavel Hrdina <phrdina@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 17460825
...@@ -838,16 +838,19 @@ int virNetClientSetTLSSession(virNetClientPtr client, ...@@ -838,16 +838,19 @@ int virNetClientSetTLSSession(virNetClientPtr client,
char buf[1]; char buf[1];
int len; int len;
struct pollfd fds[1]; struct pollfd fds[1];
#ifndef WIN32
sigset_t oldmask, blockedsigs; sigset_t oldmask, blockedsigs;
sigemptyset(&blockedsigs); sigemptyset(&blockedsigs);
#ifdef SIGWINCH # ifdef SIGWINCH
sigaddset(&blockedsigs, SIGWINCH); sigaddset(&blockedsigs, SIGWINCH);
#endif # endif
#ifdef SIGCHLD # ifdef SIGCHLD
sigaddset(&blockedsigs, SIGCHLD); sigaddset(&blockedsigs, SIGCHLD);
#endif # endif
sigaddset(&blockedsigs, SIGPIPE); sigaddset(&blockedsigs, SIGPIPE);
#endif /* !WIN32 */
virObjectLock(client); virObjectLock(client);
...@@ -873,19 +876,23 @@ int virNetClientSetTLSSession(virNetClientPtr client, ...@@ -873,19 +876,23 @@ int virNetClientSetTLSSession(virNetClientPtr client,
else else
fds[0].events = POLLOUT; fds[0].events = POLLOUT;
#ifndef WIN32
/* Block SIGWINCH from interrupting poll in curses programs, /* Block SIGWINCH from interrupting poll in curses programs,
* then restore the original signal mask again immediately * then restore the original signal mask again immediately
* 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.
*/ */
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
#endif /* !WIN32 */
repoll: repoll:
ret = poll(fds, G_N_ELEMENTS(fds), -1); ret = poll(fds, G_N_ELEMENTS(fds), -1);
if (ret < 0 && (errno == EAGAIN || errno == EINTR)) if (ret < 0 && (errno == EAGAIN || errno == EINTR))
goto repoll; goto repoll;
#ifndef WIN32
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
#endif /* !WIN32 */
} }
ret = virNetTLSContextCheckCertificate(tls, client->tls); ret = virNetTLSContextCheckCertificate(tls, client->tls);
...@@ -901,15 +908,19 @@ int virNetClientSetTLSSession(virNetClientPtr client, ...@@ -901,15 +908,19 @@ int virNetClientSetTLSSession(virNetClientPtr client,
fds[0].revents = 0; fds[0].revents = 0;
fds[0].events = POLLIN; fds[0].events = POLLIN;
#ifndef WIN32
/* 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 /* !WIN32 */
repoll2: repoll2:
ret = poll(fds, G_N_ELEMENTS(fds), -1); ret = poll(fds, G_N_ELEMENTS(fds), -1);
if (ret < 0 && (errno == EAGAIN || errno == EINTR)) if (ret < 0 && (errno == EAGAIN || errno == EINTR))
goto repoll2; goto repoll2;
#ifndef WIN32
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
#endif /* !WIN32 */
len = virNetTLSSessionRead(client->tls, buf, 1); len = virNetTLSSessionRead(client->tls, buf, 1);
if (len < 0 && errno != ENOMSG) { if (len < 0 && errno != ENOMSG) {
...@@ -1562,7 +1573,9 @@ static int virNetClientIOEventLoop(virNetClientPtr client, ...@@ -1562,7 +1573,9 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
for (;;) { for (;;) {
char ignore; char ignore;
#ifndef WIN32
sigset_t oldmask, blockedsigs; sigset_t oldmask, blockedsigs;
#endif /* !WIN32 */
int timeout = -1; int timeout = -1;
virNetMessagePtr msg = NULL; virNetMessagePtr msg = NULL;
...@@ -1603,27 +1616,31 @@ static int virNetClientIOEventLoop(virNetClientPtr client, ...@@ -1603,27 +1616,31 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
* can stuff themselves on the queue */ * can stuff themselves on the queue */
virObjectUnlock(client); virObjectUnlock(client);
#ifndef WIN32
/* Block SIGWINCH from interrupting poll in curses programs, /* Block SIGWINCH from interrupting poll in curses programs,
* then restore the original signal mask again immediately * then restore the original signal mask again immediately
* 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.
*/ */
sigemptyset(&blockedsigs); sigemptyset(&blockedsigs);
#ifdef SIGWINCH # ifdef SIGWINCH
sigaddset(&blockedsigs, SIGWINCH); sigaddset(&blockedsigs, SIGWINCH);
#endif # endif
#ifdef SIGCHLD # ifdef SIGCHLD
sigaddset(&blockedsigs, SIGCHLD); sigaddset(&blockedsigs, SIGCHLD);
#endif # endif
sigaddset(&blockedsigs, SIGPIPE); sigaddset(&blockedsigs, SIGPIPE);
ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask)); ignore_value(pthread_sigmask(SIG_BLOCK, &blockedsigs, &oldmask));
#endif /* !WIN32 */
repoll: repoll:
ret = poll(fds, G_N_ELEMENTS(fds), timeout); ret = poll(fds, G_N_ELEMENTS(fds), timeout);
if (ret < 0 && (errno == EAGAIN || errno == EINTR)) if (ret < 0 && (errno == EAGAIN || errno == EINTR))
goto repoll; goto repoll;
#ifndef WIN32
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL)); ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
#endif /* !WIN32 */
virObjectLock(client); virObjectLock(client);
......
...@@ -37,14 +37,11 @@ ...@@ -37,14 +37,11 @@
#include "virstring.h" #include "virstring.h"
#include "virsystemd.h" #include "virsystemd.h"
#ifndef SA_SIGINFO
# define SA_SIGINFO 0
#endif
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
VIR_LOG_INIT("rpc.netdaemon"); VIR_LOG_INIT("rpc.netdaemon");
#ifndef WIN32
typedef struct _virNetDaemonSignal virNetDaemonSignal; typedef struct _virNetDaemonSignal virNetDaemonSignal;
typedef virNetDaemonSignal *virNetDaemonSignalPtr; typedef virNetDaemonSignal *virNetDaemonSignalPtr;
...@@ -54,17 +51,20 @@ struct _virNetDaemonSignal { ...@@ -54,17 +51,20 @@ struct _virNetDaemonSignal {
virNetDaemonSignalFunc func; virNetDaemonSignalFunc func;
void *opaque; void *opaque;
}; };
#endif /* !WIN32 */
struct _virNetDaemon { struct _virNetDaemon {
virObjectLockable parent; virObjectLockable parent;
bool privileged; bool privileged;
#ifndef WIN32
size_t nsignals; size_t nsignals;
virNetDaemonSignalPtr *signals; virNetDaemonSignalPtr *signals;
int sigread; int sigread;
int sigwrite; int sigwrite;
int sigwatch; int sigwatch;
#endif /* !WIN32 */
virHashTablePtr servers; virHashTablePtr servers;
virJSONValuePtr srvObject; virJSONValuePtr srvObject;
...@@ -84,10 +84,9 @@ static void ...@@ -84,10 +84,9 @@ static void
virNetDaemonDispose(void *obj) virNetDaemonDispose(void *obj)
{ {
virNetDaemonPtr dmn = obj; virNetDaemonPtr dmn = obj;
#ifndef WIN32
size_t i; size_t i;
VIR_FORCE_CLOSE(dmn->autoShutdownInhibitFd);
for (i = 0; i < dmn->nsignals; i++) { for (i = 0; i < dmn->nsignals; i++) {
sigaction(dmn->signals[i]->signum, &dmn->signals[i]->oldaction, NULL); sigaction(dmn->signals[i]->signum, &dmn->signals[i]->oldaction, NULL);
VIR_FREE(dmn->signals[i]); VIR_FREE(dmn->signals[i]);
...@@ -97,6 +96,9 @@ virNetDaemonDispose(void *obj) ...@@ -97,6 +96,9 @@ virNetDaemonDispose(void *obj)
VIR_FORCE_CLOSE(dmn->sigwrite); VIR_FORCE_CLOSE(dmn->sigwrite);
if (dmn->sigwatch > 0) if (dmn->sigwatch > 0)
virEventRemoveHandle(dmn->sigwatch); virEventRemoveHandle(dmn->sigwatch);
#endif /* !WIN32 */
VIR_FORCE_CLOSE(dmn->autoShutdownInhibitFd);
virHashFree(dmn->servers); virHashFree(dmn->servers);
...@@ -119,7 +121,9 @@ virNetDaemonPtr ...@@ -119,7 +121,9 @@ virNetDaemonPtr
virNetDaemonNew(void) virNetDaemonNew(void)
{ {
virNetDaemonPtr dmn; virNetDaemonPtr dmn;
#ifndef WIN32
struct sigaction sig_action; struct sigaction sig_action;
#endif /* !WIN32 */
if (virNetDaemonInitialize() < 0) if (virNetDaemonInitialize() < 0)
return NULL; return NULL;
...@@ -130,16 +134,21 @@ virNetDaemonNew(void) ...@@ -130,16 +134,21 @@ virNetDaemonNew(void)
if (!(dmn->servers = virHashCreate(5, virObjectFreeHashData))) if (!(dmn->servers = virHashCreate(5, virObjectFreeHashData)))
goto error; goto error;
#ifndef WIN32
dmn->sigwrite = dmn->sigread = -1; dmn->sigwrite = dmn->sigread = -1;
#endif /* !WIN32 */
dmn->privileged = geteuid() == 0; dmn->privileged = geteuid() == 0;
dmn->autoShutdownInhibitFd = -1; dmn->autoShutdownInhibitFd = -1;
if (virEventRegisterDefaultImpl() < 0) if (virEventRegisterDefaultImpl() < 0)
goto error; goto error;
#ifndef WIN32
memset(&sig_action, 0, sizeof(sig_action)); memset(&sig_action, 0, sizeof(sig_action));
sig_action.sa_handler = SIG_IGN; sig_action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sig_action, NULL); sigaction(SIGPIPE, &sig_action, NULL);
#endif /* !WIN32 */
return dmn; return dmn;
...@@ -587,7 +596,7 @@ virNetDaemonRemoveShutdownInhibition(virNetDaemonPtr dmn) ...@@ -587,7 +596,7 @@ virNetDaemonRemoveShutdownInhibition(virNetDaemonPtr dmn)
} }
#ifndef WIN32
static sig_atomic_t sigErrors; static sig_atomic_t sigErrors;
static int sigLastErrno; static int sigLastErrno;
static int sigWrite = -1; static int sigWrite = -1;
...@@ -689,6 +698,7 @@ virNetDaemonSignalSetup(virNetDaemonPtr dmn) ...@@ -689,6 +698,7 @@ virNetDaemonSignalSetup(virNetDaemonPtr dmn)
return -1; return -1;
} }
int int
virNetDaemonAddSignalHandler(virNetDaemonPtr dmn, virNetDaemonAddSignalHandler(virNetDaemonPtr dmn,
int signum, int signum,
...@@ -731,6 +741,21 @@ virNetDaemonAddSignalHandler(virNetDaemonPtr dmn, ...@@ -731,6 +741,21 @@ virNetDaemonAddSignalHandler(virNetDaemonPtr dmn,
return -1; return -1;
} }
#else /* WIN32 */
int
virNetDaemonAddSignalHandler(virNetDaemonPtr dmn G_GNUC_UNUSED,
int signum G_GNUC_UNUSED,
virNetDaemonSignalFunc func G_GNUC_UNUSED,
void *opaque G_GNUC_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Signal handling not available on this platform"));
return -1;
}
#endif /* WIN32 */
static void static void
virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSED, virNetDaemonAutoShutdownTimer(int timerid G_GNUC_UNUSED,
......
...@@ -55,6 +55,10 @@ void virNetDaemonAutoShutdown(virNetDaemonPtr dmn, ...@@ -55,6 +55,10 @@ void virNetDaemonAutoShutdown(virNetDaemonPtr dmn,
void virNetDaemonAddShutdownInhibition(virNetDaemonPtr dmn); void virNetDaemonAddShutdownInhibition(virNetDaemonPtr dmn);
void virNetDaemonRemoveShutdownInhibition(virNetDaemonPtr dmn); void virNetDaemonRemoveShutdownInhibition(virNetDaemonPtr dmn);
#ifdef WIN32
# define siginfo_t void
#endif
typedef void (*virNetDaemonSignalFunc)(virNetDaemonPtr dmn, siginfo_t *info, void *opaque); typedef void (*virNetDaemonSignalFunc)(virNetDaemonPtr dmn, siginfo_t *info, void *opaque);
int virNetDaemonAddSignalHandler(virNetDaemonPtr dmn, int virNetDaemonAddSignalHandler(virNetDaemonPtr dmn,
......
...@@ -56,11 +56,6 @@ ...@@ -56,11 +56,6 @@
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h" #include "virenum.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
# define SA_SIGINFO 0
#endif
#define VIRSH_COMMON_OPT_DOMAIN_PERSISTENT \ #define VIRSH_COMMON_OPT_DOMAIN_PERSISTENT \
{.name = "persistent", \ {.name = "persistent", \
.type = VSH_OT_BOOL, \ .type = VSH_OT_BOOL, \
...@@ -1697,12 +1692,14 @@ virshPrintJobProgress(const char *label, unsigned long long remaining, ...@@ -1697,12 +1692,14 @@ virshPrintJobProgress(const char *label, unsigned long long remaining,
static volatile sig_atomic_t intCaught; static volatile sig_atomic_t intCaught;
#ifndef WIN32
static void virshCatchInt(int sig G_GNUC_UNUSED, static void virshCatchInt(int sig G_GNUC_UNUSED,
siginfo_t *siginfo G_GNUC_UNUSED, siginfo_t *siginfo G_GNUC_UNUSED,
void *context G_GNUC_UNUSED) void *context G_GNUC_UNUSED)
{ {
intCaught = 1; intCaught = 1;
} }
#endif /* !WIN32 */
typedef struct _virshBlockJobWaitData virshBlockJobWaitData; typedef struct _virshBlockJobWaitData virshBlockJobWaitData;
...@@ -1842,11 +1839,11 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) ...@@ -1842,11 +1839,11 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
* the event to the given block job we will wait for the number of retries * the event to the given block job we will wait for the number of retries
* before claiming that we entered synchronised phase */ * before claiming that we entered synchronised phase */
unsigned int retries = 5; unsigned int retries = 5;
#ifndef WIN32
struct sigaction sig_action; struct sigaction sig_action;
struct sigaction old_sig_action; struct sigaction old_sig_action;
sigset_t sigmask, oldsigmask; sigset_t sigmask, oldsigmask;
#endif /* !WIN32 */
unsigned long long start = 0; unsigned long long start = 0;
unsigned long long curr = 0; unsigned long long curr = 0;
...@@ -1861,6 +1858,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) ...@@ -1861,6 +1858,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
if (data->async_abort) if (data->async_abort)
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC; abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC;
#ifndef WIN32
sigemptyset(&sigmask); sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT); sigaddset(&sigmask, SIGINT);
...@@ -1869,6 +1867,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) ...@@ -1869,6 +1867,7 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
sig_action.sa_flags = SA_SIGINFO; sig_action.sa_flags = SA_SIGINFO;
sigemptyset(&sig_action.sa_mask); sigemptyset(&sig_action.sa_mask);
sigaction(SIGINT, &sig_action, &old_sig_action); sigaction(SIGINT, &sig_action, &old_sig_action);
#endif /* !WIN32 */
if (data->timeout && virTimeMillisNow(&start) < 0) { if (data->timeout && virTimeMillisNow(&start) < 0) {
vshSaveLibvirtError(); vshSaveLibvirtError();
...@@ -1878,9 +1877,13 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) ...@@ -1878,9 +1877,13 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
last.cur = last.end = 0; last.cur = last.end = 0;
while (true) { while (true) {
#ifndef WIN32
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
#endif /* !WIN32 */
result = virDomainGetBlockJobInfo(data->dom, data->dev, &info, 0); result = virDomainGetBlockJobInfo(data->dom, data->dev, &info, 0);
#ifndef WIN32
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
#endif /* !WIN32 */
if (result < 0) { if (result < 0) {
vshError(data->ctl, _("failed to query job for disk %s"), data->dev); vshError(data->ctl, _("failed to query job for disk %s"), data->dev);
...@@ -1944,7 +1947,9 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data) ...@@ -1944,7 +1947,9 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
virshPrintJobProgress(data->job_name, 0, 1); virshPrintJobProgress(data->job_name, 0, 1);
cleanup: cleanup:
#ifndef WIN32
sigaction(SIGINT, &old_sig_action, NULL); sigaction(SIGINT, &old_sig_action, NULL);
#endif /* !WIN32 */
return ret; return ret;
} }
...@@ -4226,12 +4231,14 @@ doSave(void *opaque) ...@@ -4226,12 +4231,14 @@ doSave(void *opaque)
unsigned int flags = 0; unsigned int flags = 0;
const char *xmlfile = NULL; const char *xmlfile = NULL;
char *xml = NULL; char *xml = NULL;
#ifndef WIN32
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 /* !WIN32 */
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
goto out; goto out;
...@@ -4265,8 +4272,10 @@ doSave(void *opaque) ...@@ -4265,8 +4272,10 @@ doSave(void *opaque)
ret = '0'; ret = '0';
out: out:
#ifndef WIN32
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
out_sig: out_sig:
#endif /* !WIN32 */
virshDomainFree(dom); virshDomainFree(dom);
VIR_FREE(xml); VIR_FREE(xml);
ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
...@@ -4285,8 +4294,11 @@ virshWatchJob(vshControl *ctl, ...@@ -4285,8 +4294,11 @@ virshWatchJob(vshControl *ctl,
void *opaque, void *opaque,
const char *label) const char *label)
{ {
#ifndef WIN32
struct sigaction sig_action; struct sigaction sig_action;
struct sigaction old_sig_action; struct sigaction old_sig_action;
sigset_t sigmask, oldsigmask;
#endif /* !WIN32 */
struct pollfd pollfd[2] = {{.fd = pipe_fd, .events = POLLIN, .revents = 0}, struct pollfd pollfd[2] = {{.fd = pipe_fd, .events = POLLIN, .revents = 0},
{.fd = STDIN_FILENO, .events = POLLIN, .revents = 0}}; {.fd = STDIN_FILENO, .events = POLLIN, .revents = 0}};
unsigned long long start_us, curr_us; unsigned long long start_us, curr_us;
...@@ -4294,10 +4306,10 @@ virshWatchJob(vshControl *ctl, ...@@ -4294,10 +4306,10 @@ virshWatchJob(vshControl *ctl,
int ret = -1; int ret = -1;
char retchar; char retchar;
bool functionReturn = false; bool functionReturn = false;
sigset_t sigmask, oldsigmask;
bool jobStarted = false; bool jobStarted = false;
nfds_t npollfd = 2; nfds_t npollfd = 2;
#ifndef WIN32
sigemptyset(&sigmask); sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT); sigaddset(&sigmask, SIGINT);
...@@ -4306,6 +4318,7 @@ virshWatchJob(vshControl *ctl, ...@@ -4306,6 +4318,7 @@ virshWatchJob(vshControl *ctl,
sig_action.sa_flags = SA_SIGINFO; sig_action.sa_flags = SA_SIGINFO;
sigemptyset(&sig_action.sa_mask); sigemptyset(&sig_action.sa_mask);
sigaction(SIGINT, &sig_action, &old_sig_action); sigaction(SIGINT, &sig_action, &old_sig_action);
#endif /* !WIN32 */
/* don't poll on STDIN if we are not using a terminal */ /* don't poll on STDIN if we are not using a terminal */
if (!vshTTYAvailable(ctl)) if (!vshTTYAvailable(ctl))
...@@ -4355,9 +4368,13 @@ virshWatchJob(vshControl *ctl, ...@@ -4355,9 +4368,13 @@ virshWatchJob(vshControl *ctl,
} }
if (verbose || !jobStarted) { if (verbose || !jobStarted) {
#ifndef WIN32
pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask); pthread_sigmask(SIG_BLOCK, &sigmask, &oldsigmask);
#endif /* !WIN32 */
ret = virDomainGetJobInfo(dom, &jobinfo); ret = virDomainGetJobInfo(dom, &jobinfo);
#ifndef WIN32
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
#endif /* !WIN32 */
if (ret == 0) { if (ret == 0) {
if (verbose && jobinfo.dataTotal > 0) if (verbose && jobinfo.dataTotal > 0)
virshPrintJobProgress(label, jobinfo.dataRemaining, virshPrintJobProgress(label, jobinfo.dataRemaining,
...@@ -4378,7 +4395,9 @@ virshWatchJob(vshControl *ctl, ...@@ -4378,7 +4395,9 @@ virshWatchJob(vshControl *ctl,
functionReturn = true; functionReturn = true;
cleanup: cleanup:
#ifndef WIN32
sigaction(SIGINT, &old_sig_action, NULL); sigaction(SIGINT, &old_sig_action, NULL);
#endif /* !WIN32 */
vshTTYRestore(ctl); vshTTYRestore(ctl);
return functionReturn; return functionReturn;
} }
...@@ -4662,12 +4681,14 @@ doManagedsave(void *opaque) ...@@ -4662,12 +4681,14 @@ doManagedsave(void *opaque)
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
const char *name; const char *name;
unsigned int flags = 0; unsigned int flags = 0;
#ifndef WIN32
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 /* !WIN32 */
if (vshCommandOptBool(cmd, "bypass-cache")) if (vshCommandOptBool(cmd, "bypass-cache"))
flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE; flags |= VIR_DOMAIN_SAVE_BYPASS_CACHE;
...@@ -4686,8 +4707,10 @@ doManagedsave(void *opaque) ...@@ -4686,8 +4707,10 @@ doManagedsave(void *opaque)
ret = '0'; ret = '0';
out: out:
#ifndef WIN32
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
out_sig: out_sig:
#endif /* !WIN32 */
virshDomainFree(dom); virshDomainFree(dom);
ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
} }
...@@ -5340,17 +5363,19 @@ doDump(void *opaque) ...@@ -5340,17 +5363,19 @@ doDump(void *opaque)
vshControl *ctl = data->ctl; vshControl *ctl = data->ctl;
const vshCmd *cmd = data->cmd; const vshCmd *cmd = data->cmd;
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
sigset_t sigmask, oldsigmask;
const char *name = NULL; const char *name = NULL;
const char *to = NULL; const char *to = NULL;
unsigned int flags = 0; unsigned int flags = 0;
const char *format = NULL; const char *format = NULL;
unsigned int dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_RAW; unsigned int dumpformat = VIR_DOMAIN_CORE_DUMP_FORMAT_RAW;
#ifndef WIN32
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 /* !WIN32 */
if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &to) < 0)
goto out; goto out;
...@@ -5407,8 +5432,10 @@ doDump(void *opaque) ...@@ -5407,8 +5432,10 @@ doDump(void *opaque)
ret = '0'; ret = '0';
out: out:
#ifndef WIN32
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
out_sig: out_sig:
#endif /* !WIN32 */
if (dom) if (dom)
virshDomainFree(dom); virshDomainFree(dom);
ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
...@@ -10601,7 +10628,6 @@ doMigrate(void *opaque) ...@@ -10601,7 +10628,6 @@ doMigrate(void *opaque)
virshCtrlData *data = opaque; virshCtrlData *data = opaque;
vshControl *ctl = data->ctl; vshControl *ctl = data->ctl;
const vshCmd *cmd = data->cmd; const vshCmd *cmd = data->cmd;
sigset_t sigmask, oldsigmask;
virTypedParameterPtr params = NULL; virTypedParameterPtr params = NULL;
int nparams = 0; int nparams = 0;
int maxparams = 0; int maxparams = 0;
...@@ -10609,11 +10635,14 @@ doMigrate(void *opaque) ...@@ -10609,11 +10635,14 @@ doMigrate(void *opaque)
unsigned long long ullOpt = 0; unsigned long long ullOpt = 0;
int rv; int rv;
virConnectPtr dconn = data->dconn; virConnectPtr dconn = data->dconn;
#ifndef WIN32
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 /* !WIN32 */
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
goto out; goto out;
...@@ -10881,8 +10910,10 @@ doMigrate(void *opaque) ...@@ -10881,8 +10910,10 @@ doMigrate(void *opaque)
} }
out: out:
#ifndef WIN32
pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL); pthread_sigmask(SIG_SETMASK, &oldsigmask, NULL);
out_sig: out_sig:
#endif /* !WIN32 */
virTypedParamsFree(params, nparams); virTypedParamsFree(params, nparams);
virshDomainFree(dom); virshDomainFree(dom);
ignore_value(safewrite(data->writefd, &ret, sizeof(ret))); ignore_value(safewrite(data->writefd, &ret, sizeof(ret)));
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include <time.h> #include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <inttypes.h> #include <inttypes.h>
#include <signal.h>
#if WITH_READLINE #if WITH_READLINE
# include <readline/readline.h> # include <readline/readline.h>
...@@ -62,11 +61,6 @@ ...@@ -62,11 +61,6 @@
#include "virsh-snapshot.h" #include "virsh-snapshot.h"
#include "virsh-volume.h" #include "virsh-volume.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
# define SA_SIGINFO 0
#endif
static char *progname; static char *progname;
static const vshCmdGrp cmdGroups[]; static const vshCmdGrp cmdGroups[];
......
...@@ -40,11 +40,6 @@ ...@@ -40,11 +40,6 @@
#include "vsh-table.h" #include "vsh-table.h"
#include "virenum.h" #include "virenum.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
# define SA_SIGINFO 0
#endif
#define VIRT_ADMIN_PROMPT "virt-admin # " #define VIRT_ADMIN_PROMPT "virt-admin # "
/* we don't need precision to milliseconds in this module */ /* we don't need precision to milliseconds in this module */
......
...@@ -46,11 +46,6 @@ ...@@ -46,11 +46,6 @@
#include "virtypedparam.h" #include "virtypedparam.h"
#include "virstring.h" #include "virstring.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
# define SA_SIGINFO 0
#endif
#ifdef WITH_READLINE #ifdef WITH_READLINE
/* For autocompletion */ /* For autocompletion */
vshControl *autoCompleteOpaque; vshControl *autoCompleteOpaque;
...@@ -2013,6 +2008,7 @@ vshEventLoop(void *opaque) ...@@ -2013,6 +2008,7 @@ vshEventLoop(void *opaque)
/* We want to use SIGINT to cancel a wait; but as signal handlers /* We want to use SIGINT to cancel a wait; but as signal handlers
* don't have an opaque argument, we have to use static storage. */ * don't have an opaque argument, we have to use static storage. */
#ifndef WIN32
static int vshEventFd = -1; static int vshEventFd = -1;
static struct sigaction vshEventOldAction; static struct sigaction vshEventOldAction;
...@@ -2027,6 +2023,7 @@ vshEventInt(int sig G_GNUC_UNUSED, ...@@ -2027,6 +2023,7 @@ vshEventInt(int sig G_GNUC_UNUSED,
if (vshEventFd >= 0) if (vshEventFd >= 0)
ignore_value(safewrite(vshEventFd, &reason, 1)); ignore_value(safewrite(vshEventFd, &reason, 1));
} }
#endif /* !WIN32 */
/* Event loop handler used to limit length of waiting for any other event. */ /* Event loop handler used to limit length of waiting for any other event. */
...@@ -2057,10 +2054,13 @@ vshEventTimeout(int timer G_GNUC_UNUSED, ...@@ -2057,10 +2054,13 @@ vshEventTimeout(int timer G_GNUC_UNUSED,
int int
vshEventStart(vshControl *ctl, int timeout_ms) vshEventStart(vshControl *ctl, int timeout_ms)
{ {
#ifndef WIN32
struct sigaction action; struct sigaction action;
assert(vshEventFd == -1);
#endif /* !WIN32 */
assert(ctl->eventPipe[0] == -1 && ctl->eventPipe[1] == -1 && assert(ctl->eventPipe[0] == -1 && ctl->eventPipe[1] == -1 &&
vshEventFd == -1 && ctl->eventTimerId >= 0); ctl->eventTimerId >= 0);
if (pipe2(ctl->eventPipe, O_CLOEXEC) < 0) { if (pipe2(ctl->eventPipe, O_CLOEXEC) < 0) {
char ebuf[1024]; char ebuf[1024];
...@@ -2068,12 +2068,15 @@ vshEventStart(vshControl *ctl, int timeout_ms) ...@@ -2068,12 +2068,15 @@ vshEventStart(vshControl *ctl, int timeout_ms)
virStrerror(errno, ebuf, sizeof(ebuf))); virStrerror(errno, ebuf, sizeof(ebuf)));
return -1; return -1;
} }
#ifndef WIN32
vshEventFd = ctl->eventPipe[1]; vshEventFd = ctl->eventPipe[1];
action.sa_sigaction = vshEventInt; action.sa_sigaction = vshEventInt;
action.sa_flags = SA_SIGINFO; action.sa_flags = SA_SIGINFO;
sigemptyset(&action.sa_mask); sigemptyset(&action.sa_mask);
sigaction(SIGINT, &action, &vshEventOldAction); sigaction(SIGINT, &action, &vshEventOldAction);
#endif /* !WIN32 */
if (timeout_ms) if (timeout_ms)
virEventUpdateTimeout(ctl->eventTimerId, timeout_ms); virEventUpdateTimeout(ctl->eventTimerId, timeout_ms);
...@@ -2140,10 +2143,12 @@ vshEventWait(vshControl *ctl) ...@@ -2140,10 +2143,12 @@ vshEventWait(vshControl *ctl)
void void
vshEventCleanup(vshControl *ctl) vshEventCleanup(vshControl *ctl)
{ {
#ifndef WIN32
if (vshEventFd >= 0) { if (vshEventFd >= 0) {
sigaction(SIGINT, &vshEventOldAction, NULL); sigaction(SIGINT, &vshEventOldAction, NULL);
vshEventFd = -1; vshEventFd = -1;
} }
#endif /* !WIN32 */
VIR_FORCE_CLOSE(ctl->eventPipe[0]); VIR_FORCE_CLOSE(ctl->eventPipe[0]);
VIR_FORCE_CLOSE(ctl->eventPipe[1]); VIR_FORCE_CLOSE(ctl->eventPipe[1]);
virEventUpdateTimeout(ctl->eventTimerId, -1); virEventUpdateTimeout(ctl->eventTimerId, -1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册