Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00041 #include <sys/types.h>
00042 #include <stdlib.h>
00043 #include <unistd.h>
00044 #include <signal.h>
00045
00046 #include "sub_agent.h"
00047
00048
00049 #include <net-snmp/net-snmp-config.h>
00050 #include <net-snmp/net-snmp-includes.h>
00051 #include <net-snmp/agent/net-snmp-agent-includes.h>
00052
00053
00054 #include "snmpSIPCommonObjects.h"
00055 #include "snmpSIPServerObjects.h"
00056 #include "snmpObjects.h"
00057
00058
00059 #include "snmpSIPPortTable.h"
00060 #include "snmpSIPMethodSupportedTable.h"
00061 #include "snmpSIPStatusCodesTable.h"
00062 #include "snmpSIPRegUserTable.h"
00063 #include "snmpSIPContactTable.h"
00064 #include "snmpSIPRegUserLookupTable.h"
00065 #include "snmpMIBNotifications.h"
00066
00067 #include "../../dprint.h"
00068 #include "../../cfg/cfg_struct.h"
00069
00070 static int keep_running;
00071
00073 static void sigterm_handler(int signal)
00074 {
00075
00076 exit(0);
00077 }
00078
00090 static int initialize_agentx(void)
00091 {
00092
00093 register_with_master_agent(AGENT_PROCESS_NAME);
00094
00095
00096
00097 init_openserSIPCommonObjects();
00098 init_openserSIPServerObjects();
00099 init_openserObjects();
00100
00101
00102
00103 init_openserSIPPortTable();
00104 init_openserSIPMethodSupportedTable();
00105 init_openserSIPStatusCodesTable();
00106 init_openserSIPRegUserTable();
00107 init_openserSIPContactTable();
00108 init_openserSIPRegUserLookupTable();
00109
00110
00111 keep_running = 1;
00112
00113 while(keep_running) {
00114
00115 cfg_update();
00116
00117 agent_check_and_process(1);
00118 }
00119
00120 snmp_shutdown(AGENT_PROCESS_NAME);
00121 SOCK_CLEANUP;
00122 exit (0);
00123
00124 return 0;
00125 }
00126
00130 void agentx_child(int rank)
00131 {
00132 struct sigaction new_sigterm_handler;
00133 struct sigaction default_handlers;
00134 struct sigaction sigpipe_handler;
00135
00136
00137 sigfillset(&new_sigterm_handler.sa_mask);
00138 new_sigterm_handler.sa_flags = 0;
00139 new_sigterm_handler.sa_handler = sigterm_handler;
00140 sigaction(SIGTERM, &new_sigterm_handler, NULL);
00141
00142
00143
00144
00145 sigemptyset(&default_handlers.sa_mask);
00146 default_handlers.sa_flags = 0;
00147 default_handlers.sa_handler = SIG_DFL;
00148
00149 sigaction(SIGCHLD, &default_handlers, NULL);
00150 sigaction(SIGINT, &default_handlers, NULL);
00151 sigaction(SIGHUP, &default_handlers, NULL);
00152 sigaction(SIGUSR1, &default_handlers, NULL);
00153 sigaction(SIGUSR2, &default_handlers, NULL);
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 sigpipe_handler.sa_flags = SA_RESTART;
00165 sigpipe_handler.sa_handler = SIG_IGN;
00166
00167 sigaction(SIGPIPE, &sigpipe_handler, NULL);
00168
00169 initialize_agentx();
00170 }
00171
00172
00173
00176 void register_with_master_agent(char *name_to_register_under)
00177 {
00178
00179 netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
00180
00181
00182 SOCK_STARTUP;
00183
00184
00185
00186 init_agent("snmpstats");
00187
00188
00189 init_snmp(name_to_register_under);
00190 }