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