mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: Switch to close callback
Since we've introduced close callbacks we can drop this SIGINT magic (which doesn't work now neither) and fully utilize the new feature.
This commit is contained in:
parent
e94c0a09ee
commit
54b6334714
@ -568,31 +568,16 @@ static int disconnected = 0; /* we may have been disconnected */
|
|||||||
/*
|
/*
|
||||||
* vshCatchDisconnect:
|
* vshCatchDisconnect:
|
||||||
*
|
*
|
||||||
* We get here when a SIGPIPE is being raised, we can't do much in the
|
* We get here when the connection was closed. We can't do much in the
|
||||||
* handler, just save the fact it was raised
|
* handler, just save the fact it was raised.
|
||||||
*/
|
|
||||||
static void vshCatchDisconnect(int sig, siginfo_t *siginfo,
|
|
||||||
void *context ATTRIBUTE_UNUSED) {
|
|
||||||
if (sig == SIGPIPE ||
|
|
||||||
(SA_SIGINFO && siginfo->si_signo == SIGPIPE))
|
|
||||||
disconnected++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vshSetupSignals:
|
|
||||||
*
|
|
||||||
* Catch SIGPIPE signals which may arise when disconnection
|
|
||||||
* from libvirtd occurs
|
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
vshSetupSignals(void) {
|
vshCatchDisconnect(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
struct sigaction sig_action;
|
int reason,
|
||||||
|
void *opaque ATTRIBUTE_UNUSED)
|
||||||
sig_action.sa_sigaction = vshCatchDisconnect;
|
{
|
||||||
sig_action.sa_flags = SA_SIGINFO;
|
if (reason != VIR_CONNECT_CLOSE_REASON_CLIENT)
|
||||||
sigemptyset(&sig_action.sa_mask);
|
disconnected++;
|
||||||
|
|
||||||
sigaction(SIGPIPE, &sig_action, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -614,10 +599,15 @@ vshReconnect(vshControl *ctl)
|
|||||||
ctl->conn = virConnectOpenAuth(ctl->name,
|
ctl->conn = virConnectOpenAuth(ctl->name,
|
||||||
virConnectAuthPtrDefault,
|
virConnectAuthPtrDefault,
|
||||||
ctl->readonly ? VIR_CONNECT_RO : 0);
|
ctl->readonly ? VIR_CONNECT_RO : 0);
|
||||||
if (!ctl->conn)
|
if (!ctl->conn) {
|
||||||
vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
|
vshError(ctl, "%s", _("Failed to reconnect to the hypervisor"));
|
||||||
else if (connected)
|
} else {
|
||||||
vshError(ctl, "%s", _("Reconnected to the hypervisor"));
|
if (virConnectRegisterCloseCallback(ctl->conn, vshCatchDisconnect,
|
||||||
|
NULL, NULL) < 0)
|
||||||
|
vshError(ctl, "%s", _("Unable to register disconnect callback"));
|
||||||
|
if (connected)
|
||||||
|
vshError(ctl, "%s", _("Reconnected to the hypervisor"));
|
||||||
|
}
|
||||||
disconnected = 0;
|
disconnected = 0;
|
||||||
ctl->useGetInfo = false;
|
ctl->useGetInfo = false;
|
||||||
ctl->useSnapshotOld = false;
|
ctl->useSnapshotOld = false;
|
||||||
@ -2458,9 +2448,6 @@ vshInit(vshControl *ctl)
|
|||||||
/* set up the library error handler */
|
/* set up the library error handler */
|
||||||
virSetErrorFunc(NULL, virshErrorHandler);
|
virSetErrorFunc(NULL, virshErrorHandler);
|
||||||
|
|
||||||
/* set up the signals handlers to catch disconnections */
|
|
||||||
vshSetupSignals();
|
|
||||||
|
|
||||||
if (virEventRegisterDefaultImpl() < 0)
|
if (virEventRegisterDefaultImpl() < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user