void init_agent (const char *app) { /* get current time (ie, the time the agent started) */ gettimeofday(&starttime, NULL); starttime.tv_sec--; starttime.tv_usec += 1000000L; /* we handle alarm signals ourselves in the select loop */ ds_set_boolean(DS_LIBRARY_ID, DS_LIB_ALARM_DONT_USE_SIG, 1); #ifdef CYGPKG_SNMPAGENT_V3_SUPPORT usm_set_reportErrorOnUnknownID(1); #endif #ifdef CAN_USE_NLIST init_kmem("/dev/kmem"); #endif setup_tree(); init_agent_read_config(app); #ifdef TESTING auto_nlist_print_tree(-2, 0); #endif /* initialize agentx subagent if necessary. */ #ifdef USING_AGENTX_SUBAGENT_MODULE if(ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE) == SUB_AGENT) subagent_pre_init(); #endif } /* end init_agent() */
/** * Initialize the agent. Calls into init_agent_read_config to set tha app's * configuration file in the appropriate default storage space, * NETSNMP_DS_LIB_APPTYPE. Need to call init_agent before calling init_snmp. * * @param app the configuration file to be read in, gets stored in default * storage * * @return Returns non-zero on failure and zero on success. * * @see init_snmp */ int init_agent(const char *app) { int r = 0; if(++done_init_agent > 1) { snmp_log(LOG_WARNING, "ignoring extra call to init_agent (%d)\n", done_init_agent); return r; } /* * get current time (ie, the time the agent started) */ gettimeofday(&starttime, NULL); starttime.tv_sec--; starttime.tv_usec += 1000000L; /* * we handle alarm signals ourselves in the select loop */ netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_ALARM_DONT_USE_SIG, 1); #ifdef CAN_USE_NLIST init_kmem("/dev/kmem"); #endif setup_tree(); init_agent_read_config(app); #ifdef TESTING auto_nlist_print_tree(-2, 0); #endif _init_agent_callback_transport(); netsnmp_init_helpers(); init_traps(); netsnmp_container_init_list(); #if defined(USING_AGENTX_SUBAGENT_MODULE) || defined(USING_AGENTX_MASTER_MODULE) /* * initialize agentx configs */ agentx_config_init(); if(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE) == SUB_AGENT) subagent_init(); #endif /* * Register configuration tokens from transport modules. */ #ifdef SNMP_TRANSPORT_UDP_DOMAIN netsnmp_udp_agent_config_tokens_register(); #endif #ifdef SNMP_TRANSPORT_UDPIPV6_DOMAIN netsnmp_udp6_agent_config_tokens_register(); #endif #ifdef SNMP_TRANSPORT_UNIX_DOMAIN netsnmp_unix_agent_config_tokens_register(); #endif #ifdef NETSNMP_EMBEDDED_PERL init_perl(); #endif #ifdef USING_AGENTX_SUBAGENT_MODULE /* * don't init agent modules for a sub-agent */ if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE) == SUB_AGENT) return r; #endif # include "agent_module_inits.h" return r; } /* end init_agent() */
/** * Initialize the agent. Calls into init_agent_read_config to set tha app's * configuration file in the appropriate default storage space, * NETSNMP_DS_LIB_APPTYPE. Need to call init_agent before calling init_snmp. * * @param app the configuration file to be read in, gets stored in default * storage * * @return Returns non-zero on failure and zero on success. * * @see init_snmp */ int init_agent(const char *app) { int r = 0; if(++done_init_agent > 1) { snmp_log(LOG_WARNING, "ignoring extra call to init_agent (%d)\n", done_init_agent); return r; } /* * get current time (ie, the time the agent started) */ gettimeofday(&starttime, NULL); starttime.tv_sec--; starttime.tv_usec += 1000000L; /* * we handle alarm signals ourselves in the select loop */ netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_ALARM_DONT_USE_SIG, 1); #ifdef NETSNMP_CAN_USE_NLIST init_kmem("/dev/kmem"); #endif setup_tree(); /* add by frank */ /*´´½¨ÓëÊý¾Ý¿âÄ£¿é»¥³âͨѶµÄÍⲿSOCKET½Ó¿Ú*/ dbsdev = dbsOpen(MID_SNMP); if( NULL != dbsdev ) { dbsWaitModule(dbsdev, MF_CMM|MF_ALARM|MF_TM); //printf("init_agent: dbsOpen\n"); } else { fprintf(stderr,"ERROR: snmpd->dbsOpen error, exited !\n"); } if( CMM_SUCCESS != snmp2cmm_init() ) { printf("module snmpd snmp2cmm_init error\n"); dbs_sys_log(dbsdev, DBS_LOG_ERR, "module snmpd snmp2cmm_init error"); } init_agent_read_config(app); #ifdef TESTING auto_nlist_print_tree(-2, 0); #endif _init_agent_callback_transport(); netsnmp_init_helpers(); init_traps(); netsnmp_container_init_list(); #if defined(USING_AGENTX_SUBAGENT_MODULE) || defined(USING_AGENTX_MASTER_MODULE) /* * initialize agentx configs */ agentx_config_init(); if(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE) == SUB_AGENT) subagent_init(); #endif /* * Register configuration tokens from transport modules. */ #ifdef NETSNMP_TRANSPORT_UDP_DOMAIN netsnmp_udp_agent_config_tokens_register(); #endif #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN netsnmp_udp6_agent_config_tokens_register(); #endif #ifdef NETSNMP_TRANSPORT_UNIX_DOMAIN netsnmp_unix_agent_config_tokens_register(); #endif #ifdef NETSNMP_EMBEDDED_PERL init_perl(); #endif #ifdef USING_AGENTX_SUBAGENT_MODULE /* * don't init agent modules for a sub-agent */ if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE) == SUB_AGENT) return r; #endif # include "agent_module_inits.h" return r; } /* end init_agent() */