Dear Coders:
I have implemented an AgentX subagent which connects snmpd on CentOS 5.3
Linux to a C++ application. To keep the maintenance for a
frequently-changing MIB low, I have written a mib2c .conf file based on
mib2c.scalar.conf and mib2c.iterate.conf. The scalar portion of the
subagent works fine for both snmpget and snmpwalk. The table portion,
however, only works for snmpget. Attempts to walk the MIB with snmpwalk
cause the subagent to die with a segmentation fault.
The autogenerated C++ code has its handlers declared "friend" in the classes
containing the variables to be included in the MIB. I use the linked-list
method suggested in mib2c.iterate.conf, with the private data in a list cell
containing only a pointer to the serving class instance, with one instance
associated with one table row. The code associated with data fetching and
setting via this mechanism works fine. The crash I see when I attempt to
run snmpwalk is as follows:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb7f22b90 (LWP 5590)]
0x00beeb7c in free () from /lib/libc.so.6
(gdb) bt
#0 0x00beeb7c in free () from /lib/libc.so.6
#1 0x0064100d in build_oid_segment () from /usr/lib/libnetsnmp.so.10
#2 0x0064f90c in build_oid_noalloc () from /usr/lib/libnetsnmp.so.10
#3 0x00b6f0c9 in netsnmp_check_getnext_reply () from
/usr/lib/libnetsnmphelpers.so.10
#4 0x00b78c1d in netsnmp_table_iterator_helper_handler () from
/usr/lib/libnetsnmphelpers.so.10
#5 0x00a8ebbb in netsnmp_call_handler () from
/usr/lib/libnetsnmpagent.so.10
#6 0x00a8ef83 in netsnmp_call_next_handler () from
/usr/lib/libnetsnmpagent.so.10
#7 0x00b70192 in table_helper_handler () from
/usr/lib/libnetsnmphelpers.so.10
#8 0x00a8ebbb in netsnmp_call_handler () from
/usr/lib/libnetsnmpagent.so.10
#9 0x00a8f240 in netsnmp_call_handlers () from
/usr/lib/libnetsnmpagent.so.10
#10 0x00a7fc6a in handle_var_requests () from /usr/lib/libnetsnmpagent.so.10
#11 0x00a81aa6 in handle_pdu () from /usr/lib/libnetsnmpagent.so.10
#12 0x00a82888 in netsnmp_handle_request () from
/usr/lib/libnetsnmpagent.so.10
#13 0x00a836bb in handle_snmp_packet () from /usr/lib/libnetsnmpagent.so.10
#14 0x0066b572 in ?? () from /usr/lib/libnetsnmp.so.10
#15 0x0066c8d0 in _sess_read () from /usr/lib/libnetsnmp.so.10
#16 0x0066d7c9 in snmp_sess_read () from /usr/lib/libnetsnmp.so.10
#17 0x0066d81f in snmp_read () from /usr/lib/libnetsnmp.so.10
#18 0x00a84008 in agent_check_and_process () from
/usr/lib/libnetsnmpagent.so.10
#19 0x08052a37 in snmp::MIBService (this=0x97798b8) at snmp.cpp:100
#20 0x08052a4b in SNMPMIBService (snmp=0x97798b8) at snmp.cpp:121
#21 0x005b049b in start_thread () from /lib/libpthread.so.0
#22 0x00c5342e in clone () from /lib/libc.so.6
One of the two table column elements is successfully fetched and printed by
snmpwalk prior to the crash. I add table elements between
init_<agentname>() and init_snmp("agentname"), and the code does not run in
more than one thread at one time. Startup code is in a main thread, after
which a service thread is spawned to loop on agent_check_and_process(). The
failure is solidly reproducible, too.
Build_oid_segment() is apparently seeing a non-null, yet invalid, var->name.
I have reviewed the code I'm generating, and it follows closely the form of
the existing "iterate" code. I suspect the problem may have to do with some
failure to properly set index values in the *get_next_data_point(), although
they seem to be the same as the original ones.
I tried a libtool-based compile from the source to see if I could get the
whole thing under the debugger, but that looks like a lot of work. At the
moment, that is my only alternative, so I will pursue that.
In the meantime, do you have any suggestions as to what I might be doing
wrong?
Many thanks for your help,
Leo Bredehoft
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders