snmpd.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2002, 2003 by Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <syslog.h>
#include "impl.h"
#include "error.h"
#include "trace.h"
#include "signals.h"
#include "snmp.h"
#include "pdu.h"
#include "agent_msg.h"
#include "agent.h"
#include "config.h"
/***** DEFINES *****/
#define DEFAULT_POLL_INTERVAL 30
/***** IMPORTED VARIABLES *****/
/* user defined data */
extern char default_config_file[];
extern char default_sec_config_file[];
extern char default_error_file[];
/***** IMPORTED FUNCTIONS *****/
/* user defined functions */
extern void agent_init();
extern void agent_end();
extern void agent_loop();
/***** STATIC VARIABLES *****/
char *config_file = NULL;
char *sec_config_file = NULL;
int agent_port_number = -1;
int dont_read_config_file = FALSE;
static int poll_interval = DEFAULT_POLL_INTERVAL;
int max_agent_reg_retry = 10;
/***** LOCAL FUNCTIONS *****/
static void signals_sighup(int siq);
static void signals_exit(int siq);
static int snmpd_init(int port);
static void print_usage(char *command_name);
static void snmpd_loop(int sd);
static void sap_main(int, char **);
/********************************************************************/
static void
{
agent_end();
}
/********************************************************************/
static void
signals_sighup(int sig)
{
if(trace_level > 0)
}
/********************************************************************/
static void
signals_exit(int sig)
{
if (trace_level > 0)
exit(1);
}
/********************************************************************/
static int
snmpd_init(int port)
{
int sd;
struct sockaddr_in me;
/* init the config_file pointer and then parse the configuration file */
if (port > 0)
if (dont_read_config_file == FALSE) {
if (config_file == NULL)
}
if (sec_config_file == NULL)
(void)sec_config_init(sec_config_file);
/* successfully register the subagent, then set the operation status of
* subagent to run.
*/
if(sd < 0)
/* evaluate the port to be used, the port priority is :
command port > config. file port > def. port */
if(port == 0 && agent_port_number != 0){
}
if(trace_level > 0)
return sd;
}
static void
snmpd_loop(int sd)
{
int numfds;
int count;
long long timer;
/* CONSTCOND */
while (1) {
if (sighup) {
(void) sec_config_init(sec_config_file);
}
numfds = 0;
if (timer >= 0) {
/* now > timeval + poll_interval */
} else {
}
if (count > 0) {
error_label)) == NULL) {
continue;
}
continue;
}
if (pdu->error_status ==
continue;
}
}
error_label) == -1) {
continue;
}
}
} else {
switch (count) {
case 0:
(void) gettimeofday(&expire,
(struct timezone *) 0);
agent_loop();
break;
case -1:
continue;
errno_string());
continue;
} else {
errno_string());
}
}
}
}
}
static void print_usage(char *command_name)
{
\t[-k (don't read config file)]\n\
\t[-p port ]\n\
\t[-c config-file (default %s)]\n\
\t[-a sec-config-file (default %s)]\n\
\t[-i poll-interval (default %d seconds)]\n\
\t[-d trace-level (range 0..%d, default %d)]\n\n",
exit(1);
}
static void
int argc;
char *argv[];
{
int arg;
int port = 0;
int sd;
char *str;
int level;
char *error_file = NULL;
/* parse arguments */
{
{
{
case 'k':
break;
case 'h':
case '?':
print_usage(argv[0]);
/* never reached */
return;
case 'p':
arg++;
{
print_usage(argv[0]);
}
/* LINTED */
{
print_usage(argv[0]);
}
break;
case 'c':
arg++;
{
print_usage(argv[0]);
}
if(config_file == NULL)
{
exit(1);
}
break;
case 'a':
arg++;
{
print_usage(argv[0]);
}
if(sec_config_file == NULL)
{
exit(1);
}
break;
case 'i':
arg++;
{
print_usage(argv[0]);
}
/* LINTED */
{
print_usage(argv[0]);
}
if(poll_interval <= 0)
{
print_usage(argv[0]);
}
break;
case 'd':
arg++;
{
print_usage(argv[0]);
}
/* LINTED */
{
print_usage(argv[0]);
}
{
print_usage(argv[0]);
}
break;
default:
print_usage(argv[0]);
}
continue;
}
}
if(error_file == NULL)
{
}
if(trace_level == 0)
{
/* run the daemon in backgound */
switch(pid)
{
case -1:
/* never reached */
return;
case 0: /* child process */
break;
default: /* parent process */
exit(0);
}
}
{
}
{
}
if(trace_level == 0)
{
{
}
}
if(trace_level == 0)
{
/* backgound */
{
}
/* set process group ID */
(void)setpgrp();
}
/* have to be called after error_open() and error_close_stderr() */
agent_init();
snmpd_loop(sd);
/* never reached */
}
void
{
}