Blame net-snmp-config.in

Packit Service b38f0b
#!/bin/sh
Packit Service b38f0b
#
Packit Service b38f0b
# $Id$
Packit Service b38f0b
#
Packit Service b38f0b
# this shell script is designed to merely dump the configuration
Packit Service b38f0b
# information about how the net-snmp package was compiled.  The
Packit Service b38f0b
# information is particularly useful for applications that need to
Packit Service b38f0b
# link against the net-snmp libraries and hence must know about any
Packit Service b38f0b
# other libraries that must be linked in as well.
Packit Service b38f0b
Packit Service b38f0b
check_build_dir()
Packit Service b38f0b
{
Packit Service b38f0b
      build_dir=$1
Packit Service b38f0b
Packit Service b38f0b
      if test "x$build_dir" = "x" ; then
Packit Service b38f0b
         echo "You must specify a build directory."
Packit Service b38f0b
         exit 1
Packit Service b38f0b
      fi
Packit Service b38f0b
      # is it the src dir?
Packit Service b38f0b
      if test -f $build_dir/net-snmp-config.in ; then
Packit Service b38f0b
         return
Packit Service b38f0b
      fi
Packit Service b38f0b
      # make sure we can find build dir
Packit Service b38f0b
      if test ! -d $build_dir/snmplib/.libs ; then
Packit Service b38f0b
         echo "$build_dir does not appear to be a build directory."
Packit Service b38f0b
         exit 1
Packit Service b38f0b
      fi
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
# usage: index n arguments
Packit Service b38f0b
# effect: returns the (n+1)th argument
Packit Service b38f0b
index()
Packit Service b38f0b
{
Packit Service b38f0b
    eval echo \$`expr $1 + 1`
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
# usage: count arguments
Packit Service b38f0b
# effect: returns the number of arguments
Packit Service b38f0b
count()
Packit Service b38f0b
{
Packit Service b38f0b
    echo $#
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
prefix=@prefix@
Packit Service b38f0b
exec_prefix=@exec_prefix@
Packit Service b38f0b
includedir=@includedir@
Packit Service b38f0b
libdir=@libdir@
Packit Service b38f0b
datarootdir=@datarootdir@
Packit Service b38f0b
NSC_LDFLAGS="@LDFLAGS@"
Packit Service b38f0b
Packit Service b38f0b
NSC_LIBS="@LIBS@"
Packit Service b38f0b
NSC_LNETSNMPLIBS="@LNETSNMPLIBS@"
Packit Service b38f0b
NSC_LAGENTLIBS="@LAGENTLIBS@ @PERLLDOPTS_FOR_APPS@"
Packit Service b38f0b
NSC_LMIBLIBS="@LMIBLIBS@"
Packit Service b38f0b
Packit Service b38f0b
NSC_INCLUDEDIR=${includedir}
Packit Service b38f0b
NSC_LIBDIR=-L${libdir}
Packit Service b38f0b
Packit Service b38f0b
NSC_SNMPLIBS="-lnetsnmp ${NSC_LNETSNMPLIBS}"
Packit Service b38f0b
NSC_SUBAGENTLIBS="-lnetsnmpagent ${NSC_LAGENTLIBS} ${NSC_SNMPLIBS}"
Packit Service b38f0b
NSC_AGENTLIBS="-lnetsnmpmibs ${NSC_LMIBLIBS} ${NSC_SUBAGENTLIBS}"
Packit Service b38f0b
Packit Service b38f0b
NSC_PREFIX=$prefix
Packit Service b38f0b
NSC_EXEC_PREFIX=$exec_prefix
Packit Service b38f0b
NSC_SRCDIR=@srcdir@
Packit Service b38f0b
NSC_INCDIR=${NSC_PREFIX}/include
Packit Service b38f0b
Packit Service b38f0b
NSC_BASE_SNMP_LIBS="-lnetsnmp"
Packit Service b38f0b
NSC_BASE_SUBAGENT_LIBS="-lnetsnmpagent ${NSC_BASE_SNMP_LIBS}"
Packit Service b38f0b
NSC_BASE_AGENT_LIBS="-lnetsnmpmibs ${NSC_BASE_SUBAGENT_LIBS}"
Packit Service b38f0b
Packit Service b38f0b
NSC_SRC_LIBDIRS="agent/.libs snmplib/.libs"
Packit Service b38f0b
NSC_SRC_LIBDEPS="agent/.libs/libnetsnmpmibs.a agent/.libs/libnetsnmpagent.a snmplib/.libs/libnetsnmp.a"
Packit Service b38f0b
Packit Service b38f0b
if test "x$NSC_SRCDIR" = "x." ; then
Packit Service b38f0b
   NSC_SRCDIR="NET-SNMP-SOURCE-DIR"
Packit Service b38f0b
elif test "x$NSC_SRCDIR" = "x" ; then
Packit Service b38f0b
   NSC_SRCDIR="NET-SNMP-SOURCE-DIR"
Packit Service b38f0b
fi
Packit Service b38f0b
Packit Service b38f0b
if test "x$1" = "x"; then
Packit Service b38f0b
  usage="yes"
Packit Service b38f0b
else
Packit Service b38f0b
  while test "x$done" = "x" -a "x$1" != "x" -a "x$usage" != "xyes"; do
Packit Service b38f0b
  case "$1" in
Packit Service b38f0b
    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
Packit Service b38f0b
    *) optarg= ;;
Packit Service b38f0b
  esac
Packit Service b38f0b
Packit Service b38f0b
  unset shifted
Packit Service b38f0b
  case $1 in
Packit Service b38f0b
    --prefix=*)
Packit Service b38f0b
      prefix=$optarg
Packit Service b38f0b
      NSC_PREFIX=${prefix}
Packit Service b38f0b
      NSC_INCLUDEDIR=${prefix}/include
Packit Service b38f0b
      NSC_LIBDIR=-L${prefix}/lib
Packit Service b38f0b
      ;;
Packit Service b38f0b
Packit Service b38f0b
    --exec-prefix=*)
Packit Service b38f0b
      exec_prefix=$optarg
Packit Service b38f0b
      NSC_EXEC_PREFIX=${exec_prefix}
Packit Service b38f0b
      NSC_LIBDIR=-L${exec_prefix}/lib
Packit Service b38f0b
      ;;
Packit Service b38f0b
Packit Service b38f0b
    --debug-tokens|--deb*|--dbg*)
Packit Service b38f0b
      echo "find $NSC_SRCDIR -name \"*.c\" -print | xargs grep DEBUGMSGT | grep \\\" | cut -f 2 -d\\\" | sort -u"
Packit Service b38f0b
      if test "x$NSC_SRCDIR" != "xNET-SNMP-SOURCE-DIR" ; then
Packit Service b38f0b
        /usr/bin/find $NSC_SRCDIR -name "*.c" -print | xargs grep DEBUGMSGT | grep \" | cut -f 2 -d\" | sort -u
Packit Service b38f0b
      fi
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --indent-options|--in*)
Packit Service b38f0b
      echo "indent -orig -nbc -bap -nut -nfca `(cd $NSC_INCDIR/net-snmp; perl -n -e 'print "-T $1 " if (/}\s*(netsnmp_\w+)\s*;/);' */*.h)`"
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --configure-options|--con*)
Packit Service b38f0b
      echo @CONFIGURE_OPTIONS@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --snmpd-module-list|--mod*)
Packit Service b38f0b
      @MODULE_LIST@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --default-mibs|--mibs|--MIBS)
Packit Service b38f0b
      echo @NETSNMP_DEFAULT_MIBS@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --default-mibdirs|--mibdirs|--MIBDIRS)
Packit Service b38f0b
      echo @NETSNMP_DEFAULT_MIBDIRS@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --env-separator)
Packit Service b38f0b
      echo "@ENV_SEPARATOR@"
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --exeext)
Packit Service b38f0b
      echo "@EXEEXT@"
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --snmpconfpath|--SNMPCONFPATH)
Packit Service b38f0b
      echo "@SNMPCONFPATH@@ENV_SEPARATOR@@SNMPSHAREPATH@@ENV_SEPARATOR@@SNMPLIBPATH@@ENV_SEPARATOR@$HOME/.snmp@ENV_SEPARATOR@@PERSISTENT_DIRECTORY@"
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --persistent-directory|--persistent-dir)
Packit Service b38f0b
      echo @PERSISTENT_DIRECTORY@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --perlprog|--perl)
Packit Service b38f0b
      echo @PERLPROG@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    #################################################### compile
Packit Service b38f0b
    --base-cflags)
Packit Service fae6c4
      echo -I${NSC_INCLUDEDIR}
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --cflags|--cf*)
Packit Service fae6c4
      echo @DEVFLAGS@ -I. -I${NSC_INCLUDEDIR}
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --srcdir)
Packit Service b38f0b
      echo $NSC_SRCDIR
Packit Service b38f0b
      ;;
Packit Service b38f0b
    #################################################### linking
Packit Service b38f0b
    --libdir|--lib-dir)
Packit Service b38f0b
      echo $NSC_LIBDIR
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --ldflags|--ld*)
Packit Service b38f0b
      echo $NSC_LDFLAGS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --build-lib-dirs)
Packit Service b38f0b
      shift
Packit Service b38f0b
      build_dir=$1
Packit Service b38f0b
      check_build_dir $build_dir
Packit Service b38f0b
      for dir in $NSC_SRC_LIBDIRS; do
Packit Service b38f0b
          result="$result -L$build_dir/$dir"
Packit Service b38f0b
      done
Packit Service b38f0b
      echo $result
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --build-lib-deps)
Packit Service b38f0b
      shift
Packit Service b38f0b
      build_dir=$1
Packit Service b38f0b
      check_build_dir $build_dir
Packit Service b38f0b
      for dir in $NSC_SRC_LIBDEPS; do
Packit Service b38f0b
          result="$result $build_dir/$dir"
Packit Service b38f0b
      done
Packit Service b38f0b
      echo $result
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --build-includes)
Packit Service b38f0b
      shift
Packit Service b38f0b
      build_dir=$1
Packit Service b38f0b
      check_build_dir $build_dir
Packit Service b38f0b
      result="-I$build_dir/include"
Packit Service b38f0b
      if test "$build_dir" != "$NSC_SRCDIR" -a "$NSC_SRCDIR" != "NET-SNMP-SOURCE-DIR"
Packit Service b38f0b
      then
Packit Service b38f0b
          result="$result -I$NSC_SRCDIR/include"
Packit Service b38f0b
      fi
Packit Service b38f0b
      echo $result
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --build-command)
Packit Service b38f0b
      echo "@CC@ @CFLAGS@ @DEVFLAGS@ @CPPFLAGS@"
Packit Service b38f0b
      ;;
Packit Service b38f0b
    #################################################### client lib
Packit Service b38f0b
    --libs)
Packit Service b38f0b
      # use this one == --netsnmp-libs + --external-libs
Packit Service b38f0b
      echo $NSC_LDFLAGS $NSC_LIBDIR $NSC_SNMPLIBS $NSC_LIBS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --netsnmp-libs)
Packit Service b38f0b
      echo $NSC_LIBDIR $NSC_BASE_SNMP_LIBS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --external-libs)
Packit Service b38f0b
      echo $NSC_LDFLAGS $NSC_LNETSNMPLIBS $NSC_LIBS @PERLLDOPTS_FOR_APPS@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    #################################################### agent lib
Packit Service b38f0b
    --base-agent-libs)
Packit Service b38f0b
      echo $NSC_BASE_AGENT_LIBS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --base-subagent-libs)
Packit Service b38f0b
      echo $NSC_BASE_SUBAGENT_LIBS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --agent-libs)
Packit Service b38f0b
      # use this one == --netsnmp-agent-libs + --external-libs
Packit Service b38f0b
      echo $NSC_LDFLAGS $NSC_LIBDIR $NSC_AGENTLIBS $NSC_LIBS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --netsnmp-agent-libs)
Packit Service b38f0b
      echo $NSC_LIBDIR $NSC_BASE_AGENT_LIBS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --external-agent-libs)
Packit Service b38f0b
      echo $NSC_LDFLAGS $NSC_LMIBLIBS $NSC_LAGENTLIBS $NSC_LNETSNMPLIBS $NSC_LIBS
Packit Service b38f0b
      ;;
Packit Service b38f0b
    ####################################################
Packit Service b38f0b
    --version|--ver*)
Packit Service b38f0b
      echo @VERSION@
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --help)
Packit Service b38f0b
      usage="yes"
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --prefix|--pre*)
Packit Service b38f0b
      echo $NSC_PREFIX
Packit Service b38f0b
      ;;
Packit Service b38f0b
    --exec-prefix)
Packit Service b38f0b
      echo $NSC_EXEC_PREFIX
Packit Service b38f0b
      ;;
Packit Service b38f0b
    ####################################################
Packit Service b38f0b
    --create-snmpv3-user)
Packit Service b38f0b
      done=1
Packit Service b38f0b
      shift
Packit Service b38f0b
      net-snmp-create-v3-user $*
Packit Service b38f0b
      exit $?
Packit Service b38f0b
      ;;
Packit Service b38f0b
Packit Service b38f0b
    ####################################################
Packit Service b38f0b
    --compile-subagent)
Packit Service b38f0b
      shift
Packit Service b38f0b
      shifted=1
Packit Service b38f0b
      while test "x$done" = "x" -a "x$1" != "x" ; do
Packit Service b38f0b
	case $1 in
Packit Service b38f0b
            --norm)
Packit Service b38f0b
	        norm=1
Packit Service b38f0b
	        shift
Packit Service b38f0b
		;;
Packit Service b38f0b
            --cflags)
Packit Service b38f0b
	        shift
Packit Service b38f0b
	        if test "x$1" = "x" ; then
Packit Service b38f0b
	            echo "You must specify the extra cflags"
Packit Service b38f0b
	            exit 1
Packit Service b38f0b
	        fi
Packit Service b38f0b
	        cflags="$1"
Packit Service b38f0b
	        echo "setting extra cflags: $cflags"
Packit Service b38f0b
	        shift
Packit Service b38f0b
		;;
Packit Service b38f0b
            --ldflags)
Packit Service b38f0b
	        shift
Packit Service b38f0b
	        if test "x$1" = "x" ; then
Packit Service b38f0b
	            echo "You must specify the extra ldflags"
Packit Service b38f0b
	            exit 1
Packit Service b38f0b
	        fi
Packit Service b38f0b
	        ldflags="$1"
Packit Service b38f0b
	        echo "setting extra ldflags: $ldflags"
Packit Service b38f0b
	        shift
Packit Service b38f0b
		;;
Packit Service b38f0b
 	    --*)
Packit Service b38f0b
		echo "unknown suboption to --compile-subagent: $1"
Packit Service b38f0b
		exit 1
Packit Service b38f0b
		;;
Packit Service b38f0b
	    *)
Packit Service b38f0b
                if test "x$outname" = "x"; then
Packit Service b38f0b
                  outname=$1
Packit Service b38f0b
                  shift
Packit Service b38f0b
                else
Packit Service b38f0b
	          done=1
Packit Service b38f0b
                fi
Packit Service b38f0b
		;;
Packit Service b38f0b
	esac
Packit Service b38f0b
      done
Packit Service b38f0b
      tmpfile=netsnmptmp.$$.c
Packit Service b38f0b
      if test -f $tmpfile; then
Packit Service b38f0b
	echo "Ack.  Can't create $tmpfile: already exists"
Packit Service b38f0b
	exit 1
Packit Service b38f0b
      fi
Packit Service b38f0b
      echo "generating the temporary code file: $tmpfile"
Packit Service b38f0b
      rm -f $tmpfile
Packit Service b38f0b
      cat > $tmpfile <
Packit Service b38f0b
/* generated from net-snmp-config */
Packit Service b38f0b
#include <net-snmp/net-snmp-config.h>
Packit Service b38f0b
#ifdef HAVE_SIGNAL
Packit Service b38f0b
#include <signal.h>
Packit Service b38f0b
#endif /* HAVE_SIGNAL */
Packit Service b38f0b
#ifdef HAVE_SYS_STAT_H
Packit Service b38f0b
#include <sys/stat.h>
Packit Service b38f0b
#endif /*  HAVE_SYS_STAT_H */
Packit Service b38f0b
#ifdef HAVE_FCNTL_H
Packit Service b38f0b
#include <fcntl.h>
Packit Service b38f0b
#endif /* HAVE_FCNTL_H */
Packit Service b38f0b
#include <net-snmp/net-snmp-includes.h>
Packit Service b38f0b
#include <net-snmp/agent/net-snmp-agent-includes.h>
Packit Service b38f0b
EOF
Packit Service b38f0b
Packit Service b38f0b
    # If we were only given a single filename
Packit Service b38f0b
    # (and no explicit output name)
Packit Service b38f0b
    # then use that as the base of the output name
Packit Service b38f0b
    #
Packit Service b38f0b
    # If we weren't even given that, then bomb out
Packit Service b38f0b
    if test "x$1" = "x"; then
Packit Service b38f0b
      if test "x$outname" = "x"; then
Packit Service b38f0b
        echo "No MIB module codefile specified"
Packit Service b38f0b
        rm -f $tmpfile
Packit Service b38f0b
        exit 1
Packit Service b38f0b
      else
Packit Service b38f0b
        cfiles=$outname
Packit Service b38f0b
        outname=`basename $cfiles | sed 's/\.[co]$//'`
Packit Service b38f0b
        if test -f $outname.h; then
Packit Service b38f0b
          if grep "init_$outname" $outname.h; then
Packit Service b38f0b
            echo "  #include \"$outname.h\"" >> $tmpfile
Packit Service b38f0b
          fi
Packit Service b38f0b
        fi
Packit Service b38f0b
      fi
Packit Service b38f0b
    fi
Packit Service b38f0b
Packit Service b38f0b
    # add include files
Packit Service b38f0b
    while test "$1" != ""; do
Packit Service b38f0b
      cfiles="$cfiles $1"
Packit Service b38f0b
      name=`basename $1 | sed 's/\.[co]$//'`
Packit Service b38f0b
      if test -f $name.h; then
Packit Service b38f0b
        if grep "init_$name" $name.h; then
Packit Service b38f0b
          echo "  #include \"$name.h\"" >> $tmpfile
Packit Service b38f0b
        fi
Packit Service b38f0b
      fi
Packit Service b38f0b
      shift
Packit Service b38f0b
    done
Packit Service b38f0b
Packit Service b38f0b
      cat >> $tmpfile <
Packit Service b38f0b
const char *app_name = "$outname";
Packit Service b38f0b
static int reconfig = 0;
Packit Service b38f0b
Packit Service b38f0b
extern int netsnmp_running;
Packit Service b38f0b
Packit Service b38f0b
RETSIGTYPE
Packit Service b38f0b
stop_server(int a) {
Packit Service b38f0b
    netsnmp_running = 0;
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
#ifdef SIGHUP
Packit Service b38f0b
RETSIGTYPE
Packit Service b38f0b
hup_handler(int sig)
Packit Service b38f0b
{
Packit Service b38f0b
    reconfig = 1;
Packit Service b38f0b
    signal(SIGHUP, hup_handler);
Packit Service b38f0b
}
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
static void
Packit Service b38f0b
usage(const char *prog)
Packit Service b38f0b
{
Packit Service b38f0b
    fprintf(stderr,
Packit Service b38f0b
            "USAGE: %s [OPTIONS]\n"
Packit Service b38f0b
            "\n"
Packit Service b38f0b
            "OPTIONS:\n", prog);
Packit Service b38f0b
Packit Service b38f0b
    fprintf(stderr,
Packit Service b38f0b
            "  -c FILE[,...]\t\tread FILE(s) as configuration file(s)\n"
Packit Service b38f0b
            "  -C\t\t\tdo not read the default configuration files\n"
Packit Service b38f0b
            "  -d\t\t\tdump all traffic\n"
Packit Service b38f0b
            "  -D TOKEN[,...]\tturn on debugging output for the specified "
Packit Service b38f0b
            "TOKENs\n"
Packit Service b38f0b
            "\t\t\t   (ALL gives extremely verbose debugging output)\n"
Packit Service b38f0b
            "  -f\t\t\tDo not fork() from the calling shell.\n"
Packit Service b38f0b
            "  -h\t\t\tdisplay this help message\n"
Packit Service b38f0b
            "  -H\t\t\tdisplay a list of configuration file directives\n"
Packit Service b38f0b
            "  -L LOGOPTS\t\tToggle various defaults controlling logging:\n");
Packit Service b38f0b
    snmp_log_options_usage("\t\t\t  ", stderr);
Packit Service b38f0b
#ifndef DISABLE_MIB_LOADING
Packit Service b38f0b
    fprintf(stderr,
Packit Service b38f0b
            "  -m MIB[" ENV_SEPARATOR "...]\t\tload given list of MIBs (ALL loads "
Packit Service b38f0b
            "everything)\n"
Packit Service b38f0b
            "  -M DIR[" ENV_SEPARATOR "...]\t\tlook in given list of directories for MIBs\n");
Packit Service b38f0b
#endif /* DISABLE_MIB_LOADING */
Packit Service b38f0b
    fprintf(stderr,
Packit Service b38f0b
            "  -p FILE\t\tstore process id in FILE\n");
Packit Service b38f0b
#ifndef DISABLE_MIB_LOADING
Packit Service b38f0b
    fprintf(stderr,
Packit Service b38f0b
            "  -P MIBOPTS\t\tToggle various defaults controlling mib "
Packit Service b38f0b
            "parsing:\n");
Packit Service b38f0b
    snmp_mib_toggle_options_usage("\t\t\t  ", stderr);
Packit Service b38f0b
#endif /* DISABLE_MIB_LOADING */
Packit Service b38f0b
    fprintf(stderr,
Packit Service b38f0b
            "  -v\t\t\tdisplay package version number\n"
Packit Service b38f0b
            "  -x TRANSPORT\tconnect to master agent using TRANSPORT\n");
Packit Service b38f0b
    exit(1);
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
static void
Packit Service b38f0b
version(void)
Packit Service b38f0b
{
Packit Service b38f0b
    fprintf(stderr, "NET-SNMP version: %s\n", netsnmp_get_version());
Packit Service b38f0b
    exit(0);
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
int
Packit Service b38f0b
main (int argc, char **argv)
Packit Service b38f0b
{
Packit Service b38f0b
  int arg;
Packit Service b38f0b
  char* cp = NULL;
Packit Service b38f0b
  int dont_fork = 0, do_help = 0;
Packit Service b38f0b
  char* pid_file = NULL;
Packit Service b38f0b
Packit Service b38f0b
  while ((arg = getopt(argc, argv, "c:CdD:fhHL:"
Packit Service b38f0b
#ifndef DISABLE_MIB_LOADING
Packit Service b38f0b
                       "m:M:"
Packit Service b38f0b
#endif /* DISABLE_MIB_LOADING */
Packit Service b38f0b
                       "n:p:"
Packit Service b38f0b
#ifndef DISABLE_MIB_LOADING
Packit Service b38f0b
                       "P:"
Packit Service b38f0b
#endif /* DISABLE_MIB_LOADING */
Packit Service b38f0b
                       "vx:")) != EOF) {
Packit Service b38f0b
    switch (arg) {
Packit Service b38f0b
      case 'c':
Packit Service b38f0b
        if (optarg != NULL) {
Packit Service b38f0b
          netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                                NETSNMP_DS_LIB_OPTIONALCONFIG, optarg);
Packit Service b38f0b
        } else {
Packit Service b38f0b
          usage(argv[0]);
Packit Service b38f0b
        }
Packit Service b38f0b
        break;
Packit Service b38f0b
Packit Service b38f0b
      case 'C':
Packit Service b38f0b
        netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                               NETSNMP_DS_LIB_DONT_READ_CONFIGS, 1);
Packit Service b38f0b
        break;
Packit Service b38f0b
Packit Service b38f0b
    case 'd':
Packit Service b38f0b
      netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                             NETSNMP_DS_LIB_DUMP_PACKET, 1);
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'D':
Packit Service b38f0b
      debug_register_tokens(optarg);
Packit Service b38f0b
      snmp_set_do_debugging(1);
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'f':
Packit Service b38f0b
      dont_fork = 1;
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'h':
Packit Service b38f0b
      usage(argv[0]);
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'H':
Packit Service b38f0b
      do_help = 1;
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'L':
Packit Service b38f0b
      if (snmp_log_options(optarg, argc, argv) < 0) {
Packit Service b38f0b
        exit(1);
Packit Service b38f0b
      }
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
#ifndef DISABLE_MIB_LOADING
Packit Service b38f0b
    case 'm':
Packit Service b38f0b
      if (optarg != NULL) {
Packit Service b38f0b
        setenv("MIBS", optarg, 1);
Packit Service b38f0b
      } else {
Packit Service b38f0b
        usage(argv[0]);
Packit Service b38f0b
      }
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'M':
Packit Service b38f0b
      if (optarg != NULL) {
Packit Service b38f0b
        setenv("MIBDIRS", optarg, 1);
Packit Service b38f0b
      } else {
Packit Service b38f0b
        usage(argv[0]);
Packit Service b38f0b
      }
Packit Service b38f0b
      break;
Packit Service b38f0b
#endif /* DISABLE_MIB_LOADING */
Packit Service b38f0b
Packit Service b38f0b
    case 'n':
Packit Service b38f0b
      if (optarg != NULL) {
Packit Service b38f0b
        app_name = optarg;
Packit Service b38f0b
        netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                              NETSNMP_DS_LIB_APPTYPE, app_name);
Packit Service b38f0b
      } else {
Packit Service b38f0b
        usage(argv[0]);
Packit Service b38f0b
      }
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'p':
Packit Service b38f0b
      if (optarg != NULL) {
Packit Service b38f0b
        pid_file = optarg;
Packit Service b38f0b
      } else {
Packit Service b38f0b
        usage(argv[0]);
Packit Service b38f0b
      }
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
#ifndef DISABLE_MIB_LOADING
Packit Service b38f0b
    case 'P':
Packit Service b38f0b
      cp = snmp_mib_toggle_options(optarg);
Packit Service b38f0b
      if (cp != NULL) {
Packit Service b38f0b
        fprintf(stderr, "Unknown parser option to -P: %c.\n", *cp);
Packit Service b38f0b
        usage(argv[0]);
Packit Service b38f0b
      }
Packit Service b38f0b
      break;
Packit Service b38f0b
#endif /* DISABLE_MIB_LOADING */
Packit Service b38f0b
Packit Service b38f0b
    case 'v':
Packit Service b38f0b
      version();
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    case 'x':
Packit Service b38f0b
      if (optarg != NULL) {
Packit Service b38f0b
        netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                              NETSNMP_DS_AGENT_X_SOCKET, optarg);
Packit Service b38f0b
      } else {
Packit Service b38f0b
        usage(argv[0]);
Packit Service b38f0b
      }
Packit Service b38f0b
      break;
Packit Service b38f0b
Packit Service b38f0b
    default:
Packit Service b38f0b
      fprintf(stderr, "invalid option: -%c\n", arg);
Packit Service b38f0b
      usage(argv[0]);
Packit Service b38f0b
      break;
Packit Service b38f0b
    }
Packit Service b38f0b
  }
Packit Service b38f0b
Packit Service b38f0b
  if (do_help) {
Packit Service b38f0b
    netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                           NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1);
Packit Service b38f0b
  } else {
Packit Service b38f0b
    /* we are a subagent */
Packit Service b38f0b
    netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                           NETSNMP_DS_AGENT_ROLE, 1);
Packit Service b38f0b
Packit Service b38f0b
    if (!dont_fork) {
Packit Service b38f0b
      if (netsnmp_daemonize(1, snmp_stderrlog_status()) != 0)
Packit Service b38f0b
        exit(1);
Packit Service b38f0b
    }
Packit Service b38f0b
Packit Service b38f0b
#if HAVE_GETPID
Packit Service b38f0b
    if (pid_file != NULL) {
Packit Service b38f0b
      /*
Packit Service b38f0b
       * unlink the pid_file, if it exists, prior to open.  Without
Packit Service b38f0b
       * doing this the open will fail if the user specified pid_file
Packit Service b38f0b
       * already exists.
Packit Service b38f0b
       */
Packit Service b38f0b
      int fd;
Packit Service b38f0b
      unlink(pid_file);
Packit Service b38f0b
      fd = open(pid_file, O_CREAT | O_EXCL | O_WRONLY, 0600);
Packit Service b38f0b
      if (fd == -1) {
Packit Service b38f0b
        snmp_log_perror(pid_file);
Packit Service b38f0b
        if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                                    NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) {
Packit Service b38f0b
          exit(1);
Packit Service b38f0b
        }
Packit Service b38f0b
      } else {
Packit Service b38f0b
        char buf[3 + sizeof(long) * 3];
Packit Service b38f0b
        int len = snprintf(buf, sizeof(buf), "%ld\n", (long int)getpid());
Packit Service b38f0b
        write(fd, buf, len);
Packit Service b38f0b
        close(fd);
Packit Service b38f0b
      }
Packit Service b38f0b
    }
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
    /* initialize tcpip, if necessary */
Packit Service b38f0b
    SOCK_STARTUP;
Packit Service b38f0b
  }
Packit Service b38f0b
Packit Service b38f0b
  /* initialize the agent library */
Packit Service b38f0b
  init_agent(app_name);
Packit Service b38f0b
Packit Service b38f0b
  /* initialize your mib code here */
Packit Service b38f0b
EOF
Packit Service b38f0b
Packit Service b38f0b
    # add init routines
Packit Service b38f0b
    for i in $cfiles ; do
Packit Service b38f0b
      name=`basename $i | sed 's/\.[co]$//'`
Packit Service b38f0b
      echo checking for init_$name in $i
Packit Service b38f0b
      if grep "init_$name" $i ; then
Packit Service b38f0b
        echo "  init_${name}();" >> $tmpfile
Packit Service b38f0b
      fi
Packit Service b38f0b
    done
Packit Service b38f0b
Packit Service b38f0b
    # handle the main loop
Packit Service b38f0b
    cat >> $tmpfile <
Packit Service b38f0b
Packit Service b38f0b
  /* $outname will be used to read $outname.conf files. */
Packit Service b38f0b
  init_snmp("$outname");
Packit Service b38f0b
Packit Service b38f0b
  if (do_help) {
Packit Service b38f0b
    fprintf(stderr, "Configuration directives understood:\n");
Packit Service b38f0b
    read_config_print_usage("  ");
Packit Service b38f0b
    exit(0);
Packit Service b38f0b
  }
Packit Service b38f0b
Packit Service b38f0b
  /* In case we received a request to stop (kill -TERM or kill -INT) */
Packit Service b38f0b
  netsnmp_running = 1;
Packit Service b38f0b
#ifdef SIGTERM
Packit Service b38f0b
  signal(SIGTERM, stop_server);
Packit Service b38f0b
#endif
Packit Service b38f0b
#ifdef SIGINT
Packit Service b38f0b
  signal(SIGINT, stop_server);
Packit Service b38f0b
#endif
Packit Service b38f0b
#ifdef SIGHUP
Packit Service b38f0b
  signal(SIGHUP, hup_handler);
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
  /* main loop here... */
Packit Service b38f0b
  while(netsnmp_running) {
Packit Service b38f0b
    if (reconfig) {
Packit Service b38f0b
      free_config();
Packit Service b38f0b
      read_configs();
Packit Service b38f0b
      reconfig = 0;
Packit Service b38f0b
    }
Packit Service b38f0b
    agent_check_and_process(1);
Packit Service b38f0b
  }
Packit Service b38f0b
Packit Service b38f0b
  /* at shutdown time */
Packit Service b38f0b
  snmp_shutdown(app_name);
Packit Service b38f0b
Packit Service b38f0b
  /* deinitialize your mib code here */
Packit Service b38f0b
EOF
Packit Service b38f0b
Packit Service b38f0b
    # add shutdown routines
Packit Service b38f0b
Packit Service b38f0b
    i=`count $cfiles`
Packit Service b38f0b
    while [ $i -gt 0 ] ; do
Packit Service b38f0b
      fullname=`index $i $cfiles`
Packit Service b38f0b
      name=`basename $fullname | sed 's/\.[co]$//'`
Packit Service b38f0b
      echo checking for shutdown_$name in $fullname
Packit Service b38f0b
      if grep "shutdown_$name" $fullname ; then
Packit Service b38f0b
        echo "  shutdown_${name}();" >> $tmpfile
Packit Service b38f0b
      fi
Packit Service b38f0b
      i=`expr $i - 1`
Packit Service b38f0b
    done
Packit Service b38f0b
Packit Service b38f0b
    # finish file
Packit Service b38f0b
    cat >> $tmpfile <
Packit Service b38f0b
Packit Service b38f0b
  /* shutdown the agent library */
Packit Service b38f0b
  shutdown_agent();
Packit Service b38f0b
Packit Service b38f0b
  if (pid_file != NULL) {
Packit Service b38f0b
    unlink(pid_file);
Packit Service b38f0b
  }
Packit Service b38f0b
Packit Service b38f0b
  SOCK_CLEANUP;
Packit Service b38f0b
  exit(0);
Packit Service b38f0b
}
Packit Service b38f0b
EOF
Packit Service b38f0b
      if test "$?" != 0 -o ! -f "$tmpfile" ; then
Packit Service b38f0b
        echo "Ack.  Can't create $tmpfile."
Packit Service b38f0b
	exit 1
Packit Service b38f0b
      fi
Packit Service b38f0b
      cmd="@CC@ $cflags @CFLAGS@ @DEVFLAGS@ -I. -I${NSC_INCLUDEDIR} -o $outname $tmpfile $cfiles $NSC_LDFLAGS $NSC_LIBDIR $NSC_BASE_AGENT_LIBS $NSC_AGENTLIBS $ldflags"
Packit Service b38f0b
      echo "running: $cmd"
Packit Service b38f0b
      `$cmd`
Packit Service b38f0b
      result=$?
Packit Service b38f0b
      if test "x$norm" != "x1" ; then
Packit Service b38f0b
        echo "removing the temporary code file: $tmpfile"
Packit Service b38f0b
        rm -f $tmpfile
Packit Service b38f0b
      else
Packit Service b38f0b
        echo "leaving the temporary code file: $tmpfile"
Packit Service b38f0b
      fi
Packit Service b38f0b
      if test "$result" = "0" -a -f "$outname" ; then
Packit Service b38f0b
        echo "subagent program $outname created"
Packit Service b38f0b
      fi
Packit Service b38f0b
      exit $result
Packit Service b38f0b
      ;;
Packit Service b38f0b
Packit Service b38f0b
    *)
Packit Service b38f0b
      echo "unknown option $1"
Packit Service b38f0b
      usage="yes"
Packit Service b38f0b
      ;;
Packit Service b38f0b
  esac
Packit Service b38f0b
  if [ "x$shifted" = "x" ] ; then
Packit Service b38f0b
      shift
Packit Service b38f0b
  fi
Packit Service b38f0b
  done
Packit Service b38f0b
fi
Packit Service b38f0b
Packit Service b38f0b
if test "x$usage" = "xyes"; then
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "Usage:"
Packit Service b38f0b
  echo "  net-snmp-config [--cflags] [--agent-libs] [--libs] [--version]"
Packit Service b38f0b
  echo "                  ... [see below for complete flag list]"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --version         displays the net-snmp version number"
Packit Service b38f0b
  echo "    --indent-options  displays the indent options from the Coding Style"
Packit Service b38f0b
  echo "    --debug-tokens    displays a example command line to search to source"
Packit Service b38f0b
  echo "                      code for a list of available debug tokens"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "  SNMP Setup commands:"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --create-snmpv3-user creates a SNMPv3 user in Net-SNMP config file."
Packit Service b38f0b
  echo "                         See net-snmp-create-v3-user --help for list of"
Packit Service b38f0b
  echo "                         accepted options."
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "  These options produce the various compilation flags needed when"
Packit Service b38f0b
  echo "  building external SNMP applications:"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --base-cflags     lists additional compilation flags needed"
Packit Service b38f0b
  echo "    --cflags          lists additional compilation flags needed"
Packit Service b38f0b
  echo "                      (includes -I. and extra developer warning flags)"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "  These options produce the various link flags needed when"
Packit Service b38f0b
  echo "  building external SNMP applications:"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --libs            lists libraries needed for building applications"
Packit Service b38f0b
  echo "    --agent-libs      lists libraries needed for building subagents"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "  These options produce various link flags broken down into parts."
Packit Service b38f0b
  echo "  (Most of the time the simple options above should be used.)"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --libdir              path to netsnmp libraries"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --base-agent-libs     netsnmp specific agent libraries"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --netsnmp-libs        netsnmp specific libraries (with path)"
Packit Service b38f0b
  echo "    --netsnmp-agent-libs  netsnmp specific agent libraries (with path)"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --ldflags             link flags for external libraries"
Packit Service b38f0b
  echo "    --external-libs       external libraries needed by netsnmp libs"
Packit Service b38f0b
  echo "    --external-agent-libs external libraries needed by netsnmp agent libs"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "  These options produce various link flags used when linking an"
Packit Service b38f0b
  echo "  external application against an uninstalled build directory."
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --build-includes      include path to build/source includes"
Packit Service b38f0b
  echo "    --build-lib-dirs      link path to libraries"
Packit Service b38f0b
  echo "    --build-lib-deps      path to libraries for dependency target"
Packit Service b38f0b
  echo "    --build-command       command to compile \$3... to \$2"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "  Automated subagent building (produces an OUTPUTNAME binary file):"
Packit Service b38f0b
  echo "  [this feature has not been tested very well yet.  use at your risk.]"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --compile-subagent OUTPUTNAME [--norm] [--cflags flags]"
Packit Service b38f0b
  echo "                                  [--ldflags flags] mibmodule1.c [...]]"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "         --norm           leave the generated .c file around to read."
Packit Service b38f0b
  echo "         --cflags flags   extra cflags to use (e.g. -I...)."
Packit Service b38f0b
  echo "         --ldflags flags  extra ld flags to use (e.g. -L... -l...)."
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "  Details on how the net-snmp package was compiled:"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  echo "    --configure-options   display original configure arguments"
Packit Service b38f0b
  echo "    --prefix              display the installation prefix"
Packit Service b38f0b
  echo "    --snmpd-module-list   display the modules compiled into the agent"
Packit Service b38f0b
  echo "    --default-mibs        display default list of MIBs"
Packit Service b38f0b
  echo "    --default-mibdirs     display default list of MIB directories"
Packit Service b38f0b
  echo "    --snmpconfpath        display default SNMPCONFPATH"
Packit Service b38f0b
  echo "    --persistent-directory display default persistent directory"
Packit Service b38f0b
  echo "    --perlprog            display path to perl for the perl modules"
Packit Service b38f0b
  echo ""
Packit Service b38f0b
  exit
Packit Service b38f0b
fi