Dear Robert, Dave, Thomas and Other Coders,
I really appreciate the help you all have provided so far.
My repsonse to Mr. Robert Story's email is as follows:
1. I have not tried the subagent running on the 32 bit system.
2. I have read the README.thread and implemented as per the example given
there. My implementation in each thread (one thread handles snmp get/set
interface and the other handles sending snmp traps.).
The code for the snmp get/set interface is as follows:
=======================================
int SubagentMainloop (int argc, char **argv)
{
int agentx_subagent=1; /* change this if you want to be a SNMP master agent
*/
int background = 0; /* change this if you want to run in the background */
int syslog = 0; /* change this if you want to use syslog */
int liberr, syserr;
char *errstr;
void *sessp; /* <-- an opaque pointer, not a struct pointer */
struct snmp_session Session, *sptr;
snmp_sess_init(&Session);
Session.peername = "nme"; /* nme is the host name of the manager */
sessp = snmp_sess_open(&Session);
if (sessp == NULL)
{
/* Error codes found in open calling argument */
snmp_error(&Session, &liberr, &syserr, &errstr);
printf("SNMP create error %s.\n", errstr);
free(errstr);
return 0;
}
sptr = snmp_sess_session(sessp); /* <-- get the snmp_session pointer */
/* print log errors to syslog or stderr */
if (syslog)
snmp_enable_calllog();
else
snmp_enable_stderrlog();
/* we're an agentx subagent? */
if (agentx_subagent)
{
/* make us a agentx client. */
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE,
1);
}
/* run in background, if requested */
if (background && netsnmp_daemonize(1, !syslog))
exit(1);
/* initialize the agent library */
init_agent("netman");
/* initialize mib code here */
/// register with the net-snmp
init_scalar_of_myAgent();
init_tables_of_myAgent();
/* example-demon will be used to read example-demon.conf files. */
init_snmp("netman");
/* If we're going to be a snmp master agent, initial the ports */
if (!agentx_subagent)
init_master_agent(); /* open the port to listen on (defaults to udp:161)
*/
/* In case we recevie a request to stop (kill -TERM or kill -INT) */
keep_running = 1;
signal(SIGTERM, stop_server);
signal(SIGINT, stop_server);
snmp_log(LOG_INFO,"SNMP SubAgent Netman is up and running.\n");
int retVal = 0;
while(keep_running)
{
/* if you use select(), see snmp_select_info() in snmp_api(3) */
/* --- OR --- */
retVal = agent_check_and_process(1); /* 0 == don't block */
}
snmp_sess_close(sessp);
/* at shutdown time */
snmp_shutdown("netman");
return 0;
}
------------------------------------------------------
The code for sending traps is as follows:
=============================
void HandleNormalMsgThread(void)
{
int liberr, syserr;
char *errstr;
void *sessp; /* <-- an opaque pointer, not a struct pointer */
struct snmp_session Session, *sptr;
snmp_sess_init(&Session);
Session.peername = "nme";
sessp = snmp_sess_open(&Session);
if (sessp == NULL)
{
/* Error codes found in open calling argument */
snmp_error(&Session, &liberr, &syserr, &errstr);
printf("SNMP create error %s.\n", errstr);
free(errstr);
return ;
}
sptr = snmp_sess_session(sessp); /* <-- get the snmp_session pointer */
/* This following function receive internal message from another exe and
generates a trap accordingly */
g_AgentQueue->ProcessMessage();
snmp_sess_close(sessp);
return;
}
Now coming to the crashes, I have seen crashes in two locations:
1. One agent_check_and_process() function.
2. The other is in sending the trap.
The stack trace for the crash 1) is as follows:
#0 snmp_sess_select_info (sessp=0x0, numfds=0x409fff18, fdset=0x409fff30,
timeout=0x409fff20, block=0x409fff1c) at snmp_api.c:5917
#1 0x0000000000436af8 in agent_check_and_process (block=1) at snmp_agent.c:576
#2 0x0000000000406368 in SubagentMainloop (argc=0, argv=0x409fff18)
at netman.cpp:309
#3 0x00000000004061f8 in HandleSNMPThread (args=0x0) at netman.cpp:221
#4 0x0000003460b0613a in start_thread () from /lib64/tls/libpthread.so.0
#5 0x000000345fec52b3 in clone () from /lib64/tls/libc.so.6
-------------------------------
The stack trace for the crash 2) is still coming same as if the whole thing is
not thread safe. (one more thing is that I do not see send_v2trap call in the
trace, even though I am calling that to send the trap in the
ConstructAndSendV2Trap())
#0 0x000000000047c9ea in snmp_sess_async_send (sessp=0x825d70,
pdu=0x2a97e07ae0, callback=0,
cb_data=0x0) at snmp_api.c:4948
#1 0x000000000043caca in send_trap_to_sess (sess=0x7b0f90,
template_pdu=0x2a97e0b690)
at agent_trap.c:890
#2 0x000000000043ccdd in netsnmp_send_traps (trap=8567152,
specific=-1746880880,
enterprise=0x5eb6c0, enterprise_length=10, vars=0x2a97e047d0,
context=0x9f1682f8 <Address 0x9f1682f8 out of bounds>, flags=0) at
agent_trap.c:790
#3 0x000000000043d053 in send_enterprise_trap_vars (trap=1712909,
specific=1167878935,
enterprise=0xf4240, enterprise_length=0, vars=0xae0cd) at agent_trap.c:811
#4 0x000000000041d22b in ConstructAndSendV2Trap (var_list=0x2a97e083b0,
newAlarmEvent=0x7fbfffacc8)
at notify_pnu.c:170
#5 0x000000000041de53 in send_pnuBadPBSStdUCurrent_trap
(newAlarmEvent=0x7fbfffacc8)
at notify_pnu.c:579
#6 0x000000000042d3dd in CAlarmAgent::SendTrap (this=0x5edd80,
pAlarmMessage=0x7fbfffacc8)
at CAlarmAgent.cpp:230
#7 0x000000000042ccf0 in CAlarmAgent::GenerateAlarm (this=0x5f0620,
pAlarmMessage=0x7fbfffacc8)
at CAlarmAgent.cpp:87
#8 0x000000000040e200 in CNetmanTask::HandleLocalMsg (this=0x772a30,
p_msg=0x7fbfffacc8)
at CNetmanTask.cpp:83
#9 0x000000000043173c in CLocalTask::DispatchMessage (this=0x772a30) at
CLocalTask.cpp:184
#10 0x0000000000406182 in HandleNormalMsgThread () at netman.cpp:193
#11 0x0000000000406719 in main (argc=1712909, argv=0x6) at netman.cpp:462
Any help is greatly appreciated.
Thank you very much,
Reddy
Robert Story <[EMAIL PROTECTED]> wrote: On Tue, 2 Jan 2007 07:55:27 -0800 (PST)
Venkata wrote:
VG> I am running net-snmp 5.4 on RHEL 4.0 64 bit OS. I have been seeing the
subagent crashing sometimes while sending traps.
Have you tested on RHEL 32 bit? Does it crash as well?
VG> #11 0x0000000000406142 in HandleNormalMsgThread () at netman.cpp:173
Have you read README.threads? You have to be very careful using the library
with threads, because a good deal of the library is not thread-safe.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders