[Xorp-hackers] fix assert in selector.cc

Ben Greear greearb at candelatech.com
Mon Apr 20 23:14:36 PDT 2009


It's possible this is caused by some of my own patches, but I think it's 
a logic
bug:  If the only fd ISSET has infinite priority, it will not be chosen and
will hit the assert at the bottom of the method.

For me, simply calling:  xorpsh
when no rtr-mgrs are running causes the crash.

The patch below fixes it for me.

Thanks,
Ben


--- a/libxorp/selector.cc
+++ b/libxorp/selector.cc
@@ -400,13 +400,15 @@ SelectorList::get_ready_priority(bool force)
     // Test the priority of remaining events for the last served file
     // descriptor.
     //
+    bool found_one = false;
     if ((_last_served_fd >= 0) && (_last_served_fd <= _maxfd)) {
     for (int sel_idx = _last_served_sel + 1;
          sel_idx < SEL_MAX_IDX;
          sel_idx++) {
         if (FD_ISSET(_last_served_fd, &_testfds[sel_idx])) {
         int p = _selector_entries[_last_served_fd]._priority[sel_idx];
-        if (p < max_priority) {
+        if ((p < max_priority) || (!found_one)) {
+            found_one = true;
             max_priority = p;
             _maxpri_fd   = _last_served_fd;
             _maxpri_sel  = sel_idx;
@@ -424,7 +426,8 @@ SelectorList::get_ready_priority(bool force)
     for (int sel_idx = 0; sel_idx < SEL_MAX_IDX; sel_idx++) {
         if (FD_ISSET(fd, &_testfds[sel_idx])) {
         int p = _selector_entries[fd]._priority[sel_idx];
-        if (p < max_priority) {
+        if ((p < max_priority) || (!found_one)) {
+            found_one = true;
             max_priority = p;
             _maxpri_fd   = fd;
             _maxpri_sel  = sel_idx;

-- 
Ben Greear <greearb at candelatech.com> 
Candela Technologies Inc  http://www.candelatech.com




More information about the Xorp-hackers mailing list