lib: AgentX: use threads instead of eventloop hack

AgentX fd/timeout handling is rather hackishly monkeyed into thread.c.
Replace with code that uses plain thread_* functions.

NB: Net-SNMP's API rivals Quagga's in terms of age and absence of
documentation.  netsnmp_check_outstanding_agent_requests() in particular
seems to be unused and is therefore untested.

The most useful documentation on this is actually the blog post Vincent
Bernat wrote when he originally integrated this into lldpd and Quagga:
https://vincent.bernat.im/en/blog/2012-snmp-event-loop.html

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/lib/thread.c b/lib/thread.c
index 39e79ad..b65078c 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -32,15 +32,6 @@
 #include "command.h"
 #include "sigevent.h"
 
-#if defined HAVE_SNMP && defined SNMP_AGENTX
-#include <net-snmp/net-snmp-config.h>
-#include <net-snmp/net-snmp-includes.h>
-#include <net-snmp/agent/net-snmp-agent-includes.h>
-#include <net-snmp/agent/snmp_vars.h>
-
-extern int agentx_enabled;
-#endif
-
 #if defined(__APPLE__)
 #include <mach/mach.h>
 #include <mach/mach_time.h>
@@ -1174,12 +1165,7 @@
   while (1)
     {
       int num = 0;
-#if defined HAVE_SNMP && defined SNMP_AGENTX
-      struct timeval snmp_timer_wait;
-      int snmpblock = 0;
-      int fdsetsize;
-#endif
-      
+
       /* Signals pre-empt everything */
       quagga_sigevent_process ();
        
@@ -1214,26 +1200,6 @@
             timer_wait = timer_wait_bg;
         }
       
-#if defined HAVE_SNMP && defined SNMP_AGENTX
-      /* When SNMP is enabled, we may have to select() on additional
-	 FD. snmp_select_info() will add them to `readfd'. The trick
-	 with this function is its last argument. We need to set it to
-	 0 if timer_wait is not NULL and we need to use the provided
-	 new timer only if it is still set to 0. */
-      if (agentx_enabled)
-        {
-          fdsetsize = FD_SETSIZE;
-          snmpblock = 1;
-          if (timer_wait)
-            {
-              snmpblock = 0;
-              memcpy(&snmp_timer_wait, timer_wait, sizeof(struct timeval));
-            }
-          snmp_select_info(&fdsetsize, &readfd, &snmp_timer_wait, &snmpblock);
-          if (snmpblock == 0)
-            timer_wait = &snmp_timer_wait;
-        }
-#endif
       num = fd_select (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait);
       
       /* Signals should get quick treatment */
@@ -1245,20 +1211,6 @@
           return NULL;
         }
 
-#if defined HAVE_SNMP && defined SNMP_AGENTX
-      if (agentx_enabled)
-        {
-          if (num > 0)
-            snmp_read(&readfd);
-          else if (num == 0)
-            {
-              snmp_timeout();
-              run_alarms();
-            }
-          netsnmp_check_outstanding_agent_requests();
-        }
-#endif
-
       /* Check foreground timers.  Historically, they have had higher
          priority than I/O threads, so let's push them onto the ready
 	 list in front of the I/O threads. */