With thanks and Regards,
D.SenthilNathan





-----Original Message-----
From: Senthil Nathan
Sent: Wed 10/10/2007 3:21 PM
To: [email protected]
Subject: 
 
Hi All,

We are using net-snmp5.1.2 in timesys distribution on powerpc target.


 Here with i have attached my file,we are using the SNMP agent ,external to the 
system.
We created the thread , which calls the master agent.
We observed that, when ever we restart the application.we need to restart the 
snmpd also.
like "etc/init.d/snmpd" restart command.

Is there any solution for that,to avoid the snmpd restart.
For your reference, i have attached my snmp agent module to you.

Inthis attached file, i felt that i have properly shut down the thread.
looking for your reply.


With thanks and Regards,
D.SenthilNathan





/*
**============================================================================
** SnmpAgent.cpp
**============================================================================
*/

/* includes for snmp agent */
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <signal.h>


#include "SnmpAgent.hpp"


using namespace std;



/* snmp additions */
static int keep_running;

RETSIGTYPE
stop_server(int a) {
    keep_running = 0;
}

/*
**============================================================================
** Static Data Member Allocation
**============================================================================
*/
CSnmpAgent   * CSnmpAgent::_instance   = NULL;

/*
**==============================================================================
**  static void* runThread(void* a_ptr)
**------------------------------------------------------------------------------
** DESCRIPTION:
**  The Thread function
**
** PARAMETERS:  
** > void* a_ptr
**      The thread argument i.e pointer to the MsgHandler object        
** RETURN:              NONE
**
** NOTES:
**    
**==============================================================================
*/
static void* runThread(void* a_ptr)
{
        CSnmpAgent *oSnmpAgent =(CSnmpAgent*)a_ptr;
        /*
        ** DESCRIPTION: This thread handles running of CLI Agent
        ** PARAMETERS:  NONE (ignored)
        ** RETURN: NONE (ignored)
        ** NOTES: 
        */
        
        oSnmpAgent->SnmpAgent_Thread();         
        
        return NULL;    
}



CSnmpAgent *CSnmpAgent::getInstance ()
{
        // If singleton already created, return pointer to it
        if (_instance == 0)
        {
                // Ensure serialization (singleGuard) semaphore guarantees a 
single instance
                if (_instance == 0)
                {
                        _instance = new CSnmpAgent();// Create the singleton
                        //nCLIPrtNum = nCLiPort ;
                }
        }
        return _instance;
}

CSnmpAgent::CSnmpAgent()
{
        startThread(runThread,  (void*)this );          
}


void * CSnmpAgent::SnmpAgent_Thread()
{
        /*snmp specific */
        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 */

        /* start snmp sub agent here */

          /* 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 tcpip, if necessary */
          SOCK_STARTUP;

          /* initialize the agent library */
          init_agent("example-demon");

          /* mib code: init_nstAgentSubagentObject from 
nstAgentSubagentObject.C */

          /* add all init functions here */
          
          init_aoltSystemGroup();  
          init_cardInfoTable();
          init_cardStateTable();
          init_cardResetTable();
          init_glcPortTable();
         init_ontActivationTable();
                        

        
        
        
          

          /* initialize vacm/usm access control  */
          if (!agentx_subagent)
         {
              //init_vacm_vars();
              //init_usmUser();
          }

          /* example-demon will be used to read example-demon.conf files. */
          init_snmp("example-demon");

          /* 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;

          snmp_log(LOG_INFO,"SNMP AgentX is up and running\n");

          /* your main loop here... */
          while(keep_running) 
          {
            /* if you use select(), see snmp_select_info() in snmp_api(3) */
            /*     --- OR ---  */
            agent_check_and_process(1); /* 0 == don't block */
          }

          /* at shutdown time */
          snmp_shutdown("example-demon");
          SOCK_CLEANUP;
    return 0;
}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to