5aa672f
diff -rup xen-3.1.0-testing.hg-rc7.orig/tools/ioemu/vl.c xen-3.1.0-testing.hg-rc7.new/tools/ioemu/vl.c
5aa672f
--- xen-3.1.0-testing.hg-rc7.orig/tools/ioemu/vl.c	2007-05-03 12:49:28.000000000 -0400
5aa672f
+++ xen-3.1.0-testing.hg-rc7.new/tools/ioemu/vl.c	2007-05-25 10:31:28.000000000 -0400
5aa672f
@@ -4124,6 +4124,7 @@ typedef struct IOHandlerRecord {
5aa672f
     IOCanRWHandler *fd_read_poll;
5aa672f
     IOHandler *fd_read;
5aa672f
     IOHandler *fd_write;
5aa672f
+    int deleted;
5aa672f
     void *opaque;
5aa672f
     /* temporary data */
5aa672f
     struct pollfd *ufd;
5aa672f
@@ -4149,8 +4150,7 @@ int qemu_set_fd_handler2(int fd, 
5aa672f
             if (ioh == NULL)
5aa672f
                 break;
5aa672f
             if (ioh->fd == fd) {
5aa672f
-                *pioh = ioh->next;
5aa672f
-                qemu_free(ioh);
5aa672f
+                ioh->deleted = 1;
5aa672f
                 break;
5aa672f
             }
5aa672f
             pioh = &ioh->next;
5aa672f
@@ -4171,6 +4171,7 @@ int qemu_set_fd_handler2(int fd, 
5aa672f
         ioh->fd_read = fd_read;
5aa672f
         ioh->fd_write = fd_write;
5aa672f
         ioh->opaque = opaque;
5aa672f
+        ioh->deleted = 0;
5aa672f
     }
5aa672f
     return 0;
5aa672f
 }
5aa672f
@@ -5153,7 +5154,7 @@ void qemu_system_powerdown_request(void)
5aa672f
 
5aa672f
 void main_loop_wait(int timeout)
5aa672f
 {
5aa672f
-    IOHandlerRecord *ioh, *ioh_next;
5aa672f
+    IOHandlerRecord *ioh;
5aa672f
     fd_set rfds, wfds, xfds;
5aa672f
     int ret, nfds;
5aa672f
     struct timeval tv;
5aa672f
@@ -5188,6 +5189,8 @@ void main_loop_wait(int timeout)
5aa672f
     FD_ZERO(&wfds);
5aa672f
     FD_ZERO(&xfds);
5aa672f
     for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
5aa672f
+        if (ioh->deleted)
5aa672f
+            continue;
5aa672f
         if (ioh->fd_read &&
5aa672f
             (!ioh->fd_read_poll ||
5aa672f
              ioh->fd_read_poll(ioh->opaque) != 0)) {
5aa672f
@@ -5215,9 +5218,11 @@ void main_loop_wait(int timeout)
5aa672f
 #endif
5aa672f
     ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv;;
5aa672f
     if (ret > 0) {
5aa672f
-        /* XXX: better handling of removal */
5aa672f
-        for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
5aa672f
-            ioh_next = ioh->next;
5aa672f
+        IOHandlerRecord **pioh;
5aa672f
+
5aa672f
+        for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) {
5aa672f
+            if (ioh->deleted)
5aa672f
+                continue;
5aa672f
             if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
5aa672f
                 ioh->fd_read(ioh->opaque);
5aa672f
             }
5aa672f
@@ -5225,6 +5230,17 @@ void main_loop_wait(int timeout)
5aa672f
                 ioh->fd_write(ioh->opaque);
5aa672f
             }
5aa672f
         }
5aa672f
+
5aa672f
+	/* remove deleted IO handlers */
5aa672f
+	pioh = &first_io_handler;
5aa672f
+	while (*pioh) {
5aa672f
+            ioh = *pioh;
5aa672f
+            if (ioh->deleted) {
5aa672f
+                *pioh = ioh->next;
5aa672f
+                qemu_free(ioh);
5aa672f
+            } else 
5aa672f
+                pioh = &ioh->next;
5aa672f
+        }
5aa672f
     }
5aa672f
 #if defined(CONFIG_SLIRP)
5aa672f
     if (slirp_inited) {
5aa672f
Only in xen-3.1.0-testing.hg-rc7.new/tools/ioemu: vl.c~
5aa672f
Only in xen-3.1.0-testing.hg-rc7.new/tools/ioemu: vl.c.orig
5aa672f
Only in xen-3.1.0-testing.hg-rc7.new/tools/ioemu: vl.c.rej