]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix python domain events example & binding
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 28 May 2009 11:02:11 +0000 (11:02 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 28 May 2009 11:02:11 +0000 (11:02 +0000)
ChangeLog
examples/domain-events/events-python/event-test.py
python/libvir.c

index 359a03c9ff4f1f3c9c3b325ef2e2a8c1e5f7fb68..dc76ccf9148ae705df575c037e194be41e213b33 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu May 28 12:00:30 BST 2009 Daniel P. Berrange <berrange@redhat.com>
+
+       Fix python domain events example & binding.
+       * examples/domain-events/events-python/event-test.py: Fix
+       broken handling of timers
+       * python/libvir.c: Take reference on virDomainPtr object
+       before wrapping it to avoid double-free.
+
 Tue May 26 13:09:30 BST 2009 Daniel P. Berrange <berrange@redhat.com>
 
        Fix error location logging
index 7bea606e9c3712eb6cb2ee459e6b36a862761b40..c50b1770ac7baebf6a8e4aa8e8a18270927d6103 100644 (file)
@@ -6,6 +6,8 @@ import select
 mypoll = select.poll()
 TIMEOUT_MS = 1000
 
+debug = False
+
 # handle globals
 h_fd       = 0
 h_events   = 0
@@ -66,8 +68,9 @@ def myPollEventToEventHandleType(events):
     return ret;
 
 def myAddHandle(fd, events, cb, opaque):
-    global h_fd, h_events, h_cb, h_opaque
-    #print "Adding Handle %s %s %s %s" % (str(fd), str(events), str(cb), str(opaque))
+    global h_fd, h_events, h_cb, h_opaque, debug
+    if debug:
+        print "Adding Handle %s %s %s %s" % (str(fd), str(events), str(cb), str(opaque))
     h_fd = fd
     h_events = events
     h_cb = cb
@@ -76,36 +79,48 @@ def myAddHandle(fd, events, cb, opaque):
     return 0
 
 def myUpdateHandle(watch, event):
-    global h_fd, h_events
-    #print "Updating Handle %s %s" % (str(h_fd), str(event))
+    global h_fd, h_events, debug
+    if debug:
+        print "Updating Handle %s %s" % (str(h_fd), str(event))
     h_events = event
     mypoll.unregister(h_fd)
     mypoll.register(h_fd, myEventHandleTypeToPollEvent(event))
 
 def myRemoveHandle(watch):
-    global h_fd
-    #print "Removing Handle %s" % str(h_fd)
+    global h_fd, debug
+    if debug:
+        print "Removing Handle %s" % str(h_fd)
     mypoll.unregister(h_fd)
     h_fd = 0
     return h_opaque
 
 def myAddTimeout(timeout, cb, opaque):
-    global t_active, t_timeout, t_cb, t_opaque
-    #print "Adding Timeout %s %s %s" % (str(timeout), str(cb), str(opaque))
-    t_active = 1;
+    global t_active, t_timeout, t_cb, t_opaque, debug
+    if debug:
+        print "Adding Timeout %s %s %s" % (str(timeout), str(cb), str(opaque))
+    if timeout == -1:
+        t_active = 0
+    else:
+        t_active = 1
     t_timeout = timeout;
     t_cb = cb;
     t_opaque = opaque;
     return 0
 
 def myUpdateTimeout(timer, timeout):
-    global t_timeout
-    #print "Updating Timeout %s %s" % (str(timer), str(timeout))
+    global t_timeout, t_active, debug
+    if debug:
+        print "Updating Timeout %s %s" % (str(timer), str(timeout))
+    if timeout == -1:
+        t_active = 0
+    else:
+        t_active = 1
     t_timeout = timeout;
 
 def myRemoveTimeout(timer):
-    global t_active
-    #print "Removing Timeout %s" % str(timer)
+    global t_active, debug
+    if debug:
+        print "Removing Timeout %s" % str(timer)
     t_active = 0;
     return t_opaque
 
@@ -159,6 +174,8 @@ def main():
 
     while 1:
         try:
+            if debug:
+                print "Poll sleep %d" % t_active
             sts = mypoll.poll(TIMEOUT_MS)
         except select.error, err:
             if err[0] == errno.EINTR:
@@ -168,17 +185,19 @@ def main():
             print "Keyboard Interrupt caught - exiting cleanly"
             break
 
+        if t_cb and t_active == 1:
+            if debug:
+                print "Invoking Timeout CB"
+            t_cb(t_timeout, t_opaque[0], t_opaque[1])
+
         if not sts:
-            #print "Timed out"
+            if debug:
+                print "Timed out"
             continue
 
         rfd = sts[0][0]
         revents = sts[0][1]
 
-        if t_active:
-            #print "Invoking Timeout CB"
-            t_cb(t_timeout, t_opaque[0], t_opaque[1])
-
         if revents & select.POLLHUP:
             print "Reset by peer";
             return -1;
index cdc5b51486a0d8d864ab44a07c0bdf23c0d4f15a..e2105979ab2962e2f9828ebd66052a1df689976b 100644 (file)
@@ -1653,6 +1653,7 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
     LIBVIRT_ENSURE_THREAD_STATE;
 
     /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
     pyobj_dom = libvirt_virDomainPtrWrap(dom);
     pyobj_dom_args = PyTuple_New(2);
     if(PyTuple_SetItem(pyobj_dom_args, 0, pyobj_conn_inst)!=0) {