Implement a net-snmp subagent (linux/C)
i have look how to implement a snmp sub-agent with the net-snmp library (http://net-snmp.sourceforge.net/tutorial/tutorial-5/toolkit/demon/index.html)
The exemple works well, but i am asking a question about the variable passed in reference in "netsnmp_register_int_instance(&variable)"
This variable is read when a snmp request is recevieved by the snmp deamon wich ask the "agentx" to ask to the subagent to give the value of the variable.
But how about Locks? i am going to link the subagent with my ownbinary to permit him giving informations about it开发者_运维问答s states each seconds.
Sometimes it will be possible that the variable is being read by snmp library code while being writen by my own code?
i must modify the code of the snmp library blocks which read the variable to set a lock?
Thank you.
If your binary is multi-threaded, then you need locks. If not, don't worry about it.
The simplest thing to do would be to set the lock before calling the agent x processing routine (e.g. agent_check_and_process). If you need finer-grained locking, then you'll have to implement your own handler instead of using net_snmp_register_int_instance.
精彩评论