net-snmp 5.7
mib_modules.c
00001 /*
00002  * wrapper to call all the mib module initialization functions 
00003  */
00004 
00005 #include <net-snmp/agent/mib_module_config.h>
00006 #include <net-snmp/net-snmp-config.h>
00007 #if HAVE_STRING_H
00008 #include <string.h>
00009 #else
00010 #include <strings.h>
00011 #endif
00012 #if HAVE_STDLIB_H
00013 #include <stdlib.h>
00014 #endif
00015 #if HAVE_UNISTD_H
00016 #include <unistd.h>
00017 #endif
00018 #include <sys/types.h>
00019 #if TIME_WITH_SYS_TIME
00020 # include <sys/time.h>
00021 # include <time.h>
00022 #else
00023 # if HAVE_SYS_TIME_H
00024 #  include <sys/time.h>
00025 # else
00026 #  include <time.h>
00027 # endif
00028 #endif
00029 #if HAVE_NETINET_IN_H
00030 #include <netinet/in.h>
00031 #endif
00032 
00033 #include <net-snmp/net-snmp-includes.h>
00034 #include <net-snmp/agent/net-snmp-agent-includes.h>
00035 #include "m2m.h"
00036 #ifdef USING_IF_MIB_DATA_ACCESS_INTERFACE_MODULE
00037 #include <net-snmp/data_access/interface.h>
00038 #endif
00039 
00040 #include "mibgroup/struct.h"
00041 #include <net-snmp/agent/mib_modules.h>
00042 #include <net-snmp/agent/table.h>
00043 #include <net-snmp/agent/table_iterator.h>
00044 #include "mib_module_includes.h"
00045 
00046 static int need_shutdown = 0;
00047 
00048 static int
00049 _shutdown_mib_modules(int majorID, int minorID, void *serve, void *client)
00050 {
00051     if (! need_shutdown) {
00052         netsnmp_assert(need_shutdown == 1);
00053     }
00054     else {
00055 #include "mib_module_shutdown.h"
00056 
00057         need_shutdown = 0;
00058     }
00059 
00060     return SNMPERR_SUCCESS; /* callback rc ignored */
00061 }
00062 
00063 void
00064 init_mib_modules(void)
00065 {
00066     static int once = 0;
00067 
00068 #ifdef USING_IF_MIB_DATA_ACCESS_INTERFACE_MODULE
00069     netsnmp_access_interface_init();
00070 #endif
00071 #  include "mib_module_inits.h"
00072 
00073     need_shutdown = 1;
00074 
00075     if (once == 0) {
00076         int rc;
00077         once = 1;
00078         rc = snmp_register_callback( SNMP_CALLBACK_LIBRARY,
00079                                      SNMP_CALLBACK_SHUTDOWN,
00080                                      _shutdown_mib_modules,
00081                                      NULL);
00082 
00083         if( rc != SNMP_ERR_NOERROR )
00084             snmp_log(LOG_ERR, "error registering for SHUTDOWN callback "
00085                      "for mib modules\n");
00086     }
00087 }