On Wed, May 20, 2009 at 05:19:33PM +0200, Pritesh Kothari wrote:
Hi All,
The event-test.c example doesn't check for the return values while
registering for the callbacks, this patch just checks for them along
with a correcting a small typo. (Unpaused => Paused)
ACK, just noticed that 'Paused' typo too :-)
Daniel
commit e646e55c4167572a8b345f99d9beaac4fa5ca538
Author: pk221555 <pk221555(a)krishna.(none)>
Date: Wed May 20 17:12:50 2009 +0200
libvirt: fixed event example for checking the return values
diff --git a/examples/domain-events/events-c/event-test.c
b/examples/domain-events/events-c/event-test.c
index 5272f44..b506687 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -116,7 +116,7 @@ static const char *eventDetailToString(int event, int detail) {
break;
case VIR_DOMAIN_EVENT_SUSPENDED:
if (detail == VIR_DOMAIN_EVENT_SUSPENDED_PAUSED)
- ret = "Unpaused";
+ ret = "Paused";
else if (detail == VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED)
ret = "Migrated";
break;
@@ -291,6 +291,8 @@ static void stop(int sig)
int main(int argc, char **argv)
{
int sts;
+ int callback1ret = -1;
+ int callback2ret = -1;
struct sigaction action_stop = {
.sa_handler = stop
};
@@ -320,48 +322,51 @@ int main(int argc, char **argv)
DEBUG0("Registering domain event cbs");
/* Add 2 callbacks to prove this works with more than just one */
- virConnectDomainEventRegister(dconn, myDomainEventCallback1,
- strdup("callback 1"), myFreeFunc);
- virConnectDomainEventRegister(dconn, myDomainEventCallback2,
- strdup("callback 2"), myFreeFunc);
-
- while(run) {
- struct pollfd pfd = { .fd = h_fd,
- .events = h_event,
- .revents = 0};
-
- sts = poll(&pfd, 1, TIMEOUT_MS);
+ callback1ret = virConnectDomainEventRegister(dconn, myDomainEventCallback1,
+ strdup("callback 1"),
myFreeFunc);
+ callback2ret = virConnectDomainEventRegister(dconn, myDomainEventCallback2,
+ strdup("callback 2"),
myFreeFunc);
+
+ if ((callback1ret == 0) && (callback2ret == 0) ) {
+ while(run) {
+ struct pollfd pfd = { .fd = h_fd,
+ .events = h_event,
+ .revents = 0};
+
+ sts = poll(&pfd, 1, TIMEOUT_MS);
+
+ /* We are assuming timeout of 0 here - so execute every time */
+ if(t_cb && t_active)
+ t_cb(t_timeout,t_opaque);
+
+ if (sts == 0) {
+ /* DEBUG0("Poll timeout"); */
+ continue;
+ }
+ if (sts < 0 ) {
+ DEBUG0("Poll failed");
+ continue;
+ }
+ if ( pfd.revents & POLLHUP ) {
+ DEBUG0("Reset by peer");
+ return -1;
+ }
- /* We are assuming timeout of 0 here - so execute every time */
- if(t_cb && t_active)
- t_cb(t_timeout,t_opaque);
+ if(h_cb) {
+ h_cb(0,
+ h_fd,
+ myPollEventToEventHandleType(pfd.revents & h_event),
+ h_opaque);
+ }
- if (sts == 0) {
- /* DEBUG0("Poll timeout"); */
- continue;
- }
- if (sts < 0 ) {
- DEBUG0("Poll failed");
- continue;
- }
- if ( pfd.revents & POLLHUP ) {
- DEBUG0("Reset by peer");
- return -1;
}
- if(h_cb) {
- h_cb(0,
- h_fd,
- myPollEventToEventHandleType(pfd.revents & h_event),
- h_opaque);
- }
+ DEBUG0("Deregistering event handlers");
+ virConnectDomainEventDeregister(dconn, myDomainEventCallback1);
+ virConnectDomainEventDeregister(dconn, myDomainEventCallback2);
}
- DEBUG0("Deregistering event handlers");
- virConnectDomainEventDeregister(dconn, myDomainEventCallback1);
- virConnectDomainEventDeregister(dconn, myDomainEventCallback2);
-
DEBUG0("Closing connection");
if( dconn && virConnectClose(dconn)<0 ) {
printf("error closing\n");
--
Libvir-list mailing list
Libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|