| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# $Id$ |
| 4 |
# |
| 5 |
# this shell script is designed to merely dump the configuration |
| 6 |
# information about how the net-snmp package was compiled. The |
| 7 |
# information is particularly useful for applications that need to |
| 8 |
# link against the net-snmp libraries and hence must know about any |
| 9 |
# other libraries that must be linked in as well. |
| 10 |
|
| 11 |
check_build_dir() |
| 12 |
{ |
| 13 |
build_dir=$1 |
| 14 |
|
| 15 |
if test "x$build_dir" = "x" ; then |
| 16 |
echo "You must specify a build directory." |
| 17 |
exit 1 |
| 18 |
fi |
| 19 |
# is it the src dir? |
| 20 |
if test -f $build_dir/net-snmp-config.in ; then |
| 21 |
return |
| 22 |
fi |
| 23 |
# make sure we can find build dir |
| 24 |
if test ! -d $build_dir/snmplib/.libs ; then |
| 25 |
echo "$build_dir does not appear to be a build directory." |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
} |
| 29 |
|
| 30 |
# usage: index n arguments |
| 31 |
# effect: returns the (n+1)th argument |
| 32 |
index() |
| 33 |
{ |
| 34 |
[ $# -gt $1 ] || return |
| 35 |
shift $1 |
| 36 |
echo $1 |
| 37 |
} |
| 38 |
|
| 39 |
# usage: count arguments |
| 40 |
# effect: returns the number of arguments |
| 41 |
count() |
| 42 |
{ |
| 43 |
echo $# |
| 44 |
} |
| 45 |
|
| 46 |
prefix=@prefix@ |
| 47 |
exec_prefix=@exec_prefix@ |
| 48 |
includedir=@includedir@ |
| 49 |
libdir=@libdir@ |
| 50 |
# Avoid that configure complains that this script ignores @datarootdir@ |
| 51 |
echo "@datarootdir@" >/dev/null |
| 52 |
NSC_LDFLAGS="@LDFLAGS@" |
| 53 |
|
| 54 |
NSC_LIBS="@LIBS@" |
| 55 |
NSC_LNETSNMPLIBS="@LNETSNMPLIBS@" |
| 56 |
NSC_LAGENTLIBS="@LAGENTLIBS@ @PERLLDOPTS_FOR_APPS@" |
| 57 |
NSC_LMIBLIBS="@LMIBLIBS@" |
| 58 |
|
| 59 |
NSC_INCLUDEDIR=${includedir} |
| 60 |
NSC_LIBDIR=-L${libdir} |
| 61 |
|
| 62 |
NSC_SNMPLIBS="-lnetsnmp ${NSC_LNETSNMPLIBS}" |
| 63 |
NSC_SUBAGENTLIBS="-lnetsnmpagent ${NSC_LAGENTLIBS} ${NSC_SNMPLIBS}" |
| 64 |
NSC_AGENTLIBS="-lnetsnmpmibs ${NSC_LMIBLIBS} ${NSC_SUBAGENTLIBS}" |
| 65 |
|
| 66 |
NSC_PREFIX=$prefix |
| 67 |
NSC_EXEC_PREFIX=$exec_prefix |
| 68 |
NSC_SRCDIR=@srcdir@ |
| 69 |
NSC_INCDIR=${NSC_PREFIX}/include |
| 70 |
|
| 71 |
NSC_BASE_SNMP_LIBS="-lnetsnmp" |
| 72 |
NSC_BASE_SUBAGENT_LIBS="-lnetsnmpagent ${NSC_BASE_SNMP_LIBS}" |
| 73 |
NSC_BASE_AGENT_LIBS="-lnetsnmpmibs ${NSC_BASE_SUBAGENT_LIBS}" |
| 74 |
|
| 75 |
NSC_SRC_LIBDIRS="agent/.libs snmplib/.libs" |
| 76 |
NSC_SRC_LIBDEPS="agent/.libs/libnetsnmpmibs.a agent/.libs/libnetsnmpagent.a snmplib/.libs/libnetsnmp.a" |
| 77 |
|
| 78 |
if test "x$NSC_SRCDIR" = "x." ; then |
| 79 |
NSC_SRCDIR="NET-SNMP-SOURCE-DIR" |
| 80 |
elif test "x$NSC_SRCDIR" = "x" ; then |
| 81 |
NSC_SRCDIR="NET-SNMP-SOURCE-DIR" |
| 82 |
fi |
| 83 |
|
| 84 |
if test "x$1" = "x"; then |
| 85 |
usage="yes" |
| 86 |
else |
| 87 |
while test "x$done" = "x" -a "x$1" != "x" -a "x$usage" != "xyes"; do |
| 88 |
case "$1" in |
| 89 |
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; |
| 90 |
*) optarg= ;; |
| 91 |
esac |
| 92 |
|
| 93 |
unset shifted |
| 94 |
case $1 in |
| 95 |
--prefix=*) |
| 96 |
prefix=$optarg |
| 97 |
NSC_PREFIX=${prefix} |
| 98 |
NSC_INCLUDEDIR=${prefix}/include |
| 99 |
NSC_LIBDIR=-L${prefix}/lib |
| 100 |
;; |
| 101 |
|
| 102 |
--exec-prefix=*) |
| 103 |
exec_prefix=$optarg |
| 104 |
NSC_EXEC_PREFIX=${exec_prefix} |
| 105 |
NSC_LIBDIR=-L${exec_prefix}/lib |
| 106 |
;; |
| 107 |
|
| 108 |
--debug-tokens|--deb*|--dbg*) |
| 109 |
echo "find $NSC_SRCDIR -name \"*.c\" -print | xargs grep DEBUGMSGT | grep \\\" | cut -f 2 -d\\\" | sort -u" |
| 110 |
if test "x$NSC_SRCDIR" != "xNET-SNMP-SOURCE-DIR" ; then |
| 111 |
/usr/bin/find $NSC_SRCDIR -name "*.c" -print | xargs grep DEBUGMSGT | grep \" | cut -f 2 -d\" | sort -u |
| 112 |
fi |
| 113 |
;; |
| 114 |
--indent-options|--in*) |
| 115 |
echo "indent -orig -nbc -bap -nut -nfca `(cd $NSC_INCDIR/net-snmp; perl -n -e 'print "-T $1 " if (/}\s*(netsnmp_\w+)\s*;/);' */*.h)`" |
| 116 |
;; |
| 117 |
--configure-options|--con*) |
| 118 |
echo @CONFIGURE_OPTIONS@ |
| 119 |
;; |
| 120 |
--snmpd-module-list|--mod*) |
| 121 |
@MODULE_LIST@ |
| 122 |
;; |
| 123 |
--default-mibs|--mibs|--MIBS) |
| 124 |
echo @NETSNMP_DEFAULT_MIBS@ |
| 125 |
;; |
| 126 |
--default-mibdirs|--mibdirs|--MIBDIRS) |
| 127 |
echo @NETSNMP_DEFAULT_MIBDIRS@ |
| 128 |
;; |
| 129 |
--env-separator) |
| 130 |
echo "@ENV_SEPARATOR@" |
| 131 |
;; |
| 132 |
--exeext) |
| 133 |
echo "@EXEEXT@" |
| 134 |
;; |
| 135 |
--snmpconfpath|--SNMPCONFPATH) |
| 136 |
echo "@SNMPCONFPATH@@ENV_SEPARATOR@@SNMPSHAREPATH@@ENV_SEPARATOR@@SNMPLIBPATH@@ENV_SEPARATOR@$HOME/.snmp@ENV_SEPARATOR@@PERSISTENT_DIRECTORY@" |
| 137 |
;; |
| 138 |
--persistent-directory|--persistent-dir) |
| 139 |
echo @PERSISTENT_DIRECTORY@ |
| 140 |
;; |
| 141 |
--perlprog|--perl) |
| 142 |
echo @PERLPROG@ |
| 143 |
;; |
| 144 |
#################################################### compile |
| 145 |
--base-cflags) |
| 146 |
echo @CFLAGS@ @CPPFLAGS@ -I${NSC_INCLUDEDIR} |
| 147 |
;; |
| 148 |
--cflags|--cf*) |
| 149 |
echo @CFLAGS@ @DEVFLAGS@ @CPPFLAGS@ -I. -I${NSC_INCLUDEDIR} |
| 150 |
;; |
| 151 |
--srcdir) |
| 152 |
echo $NSC_SRCDIR |
| 153 |
;; |
| 154 |
#################################################### linking |
| 155 |
--libdir|--lib-dir) |
| 156 |
echo $NSC_LIBDIR |
| 157 |
;; |
| 158 |
--ldflags|--ld*) |
| 159 |
echo $NSC_LDFLAGS |
| 160 |
;; |
| 161 |
--build-lib-dirs) |
| 162 |
shift |
| 163 |
build_dir=$1 |
| 164 |
check_build_dir $build_dir |
| 165 |
for dir in $NSC_SRC_LIBDIRS; do |
| 166 |
result="$result -L$build_dir/$dir" |
| 167 |
done |
| 168 |
echo $result |
| 169 |
;; |
| 170 |
--build-lib-deps) |
| 171 |
shift |
| 172 |
build_dir=$1 |
| 173 |
check_build_dir $build_dir |
| 174 |
for dir in $NSC_SRC_LIBDEPS; do |
| 175 |
result="$result $build_dir/$dir" |
| 176 |
done |
| 177 |
echo $result |
| 178 |
;; |
| 179 |
--build-includes) |
| 180 |
shift |
| 181 |
build_dir=$1 |
| 182 |
check_build_dir $build_dir |
| 183 |
result="-I$build_dir/include" |
| 184 |
if test "$build_dir" != "$NSC_SRCDIR" -a "$NSC_SRCDIR" != "NET-SNMP-SOURCE-DIR" |
| 185 |
then |
| 186 |
result="$result -I$NSC_SRCDIR/include" |
| 187 |
fi |
| 188 |
echo $result |
| 189 |
;; |
| 190 |
--build-command) |
| 191 |
echo "@CC@ @CFLAGS@ @DEVFLAGS@ @CPPFLAGS@" |
| 192 |
;; |
| 193 |
#################################################### client lib |
| 194 |
--libs) |
| 195 |
# use this one == --netsnmp-libs + --external-libs |
| 196 |
echo $NSC_LDFLAGS $NSC_LIBDIR $NSC_SNMPLIBS $NSC_LIBS |
| 197 |
;; |
| 198 |
--netsnmp-libs) |
| 199 |
echo $NSC_LIBDIR $NSC_BASE_SNMP_LIBS |
| 200 |
;; |
| 201 |
--external-libs) |
| 202 |
echo $NSC_LDFLAGS $NSC_LNETSNMPLIBS $NSC_LIBS @PERLLDOPTS_FOR_APPS@ |
| 203 |
;; |
| 204 |
#################################################### agent lib |
| 205 |
--base-agent-libs) |
| 206 |
echo $NSC_BASE_AGENT_LIBS |
| 207 |
;; |
| 208 |
--base-subagent-libs) |
| 209 |
echo $NSC_BASE_SUBAGENT_LIBS |
| 210 |
;; |
| 211 |
--agent-libs) |
| 212 |
# use this one == --netsnmp-agent-libs + --external-libs |
| 213 |
echo $NSC_LDFLAGS $NSC_LIBDIR $NSC_AGENTLIBS $NSC_LIBS |
| 214 |
;; |
| 215 |
--netsnmp-agent-libs) |
| 216 |
echo $NSC_LIBDIR $NSC_BASE_AGENT_LIBS |
| 217 |
;; |
| 218 |
--external-agent-libs) |
| 219 |
echo $NSC_LDFLAGS $NSC_LMIBLIBS $NSC_LAGENTLIBS $NSC_LNETSNMPLIBS $NSC_LIBS |
| 220 |
;; |
| 221 |
#################################################### |
| 222 |
--version|--ver*) |
| 223 |
echo @VERSION@ |
| 224 |
;; |
| 225 |
--help) |
| 226 |
usage="yes" |
| 227 |
;; |
| 228 |
--prefix|--pre*) |
| 229 |
echo $NSC_PREFIX |
| 230 |
;; |
| 231 |
--exec-prefix) |
| 232 |
echo $NSC_EXEC_PREFIX |
| 233 |
;; |
| 234 |
#################################################### |
| 235 |
--create-snmpv3-user) |
| 236 |
done=1 |
| 237 |
shift |
| 238 |
net-snmp-create-v3-user $* |
| 239 |
exit $? |
| 240 |
;; |
| 241 |
|
| 242 |
#################################################### |
| 243 |
--compile-subagent) |
| 244 |
shift |
| 245 |
shifted=1 |
| 246 |
while test "x$done" = "x" -a "x$1" != "x" ; do |
| 247 |
case $1 in |
| 248 |
--norm) |
| 249 |
norm=1 |
| 250 |
shift |
| 251 |
;; |
| 252 |
--cflags) |
| 253 |
shift |
| 254 |
if test "x$1" = "x" ; then |
| 255 |
echo "You must specify the extra cflags" |
| 256 |
exit 1 |
| 257 |
fi |
| 258 |
cflags="$1" |
| 259 |
echo "setting extra cflags: $cflags" |
| 260 |
shift |
| 261 |
;; |
| 262 |
--ldflags) |
| 263 |
shift |
| 264 |
if test "x$1" = "x" ; then |
| 265 |
echo "You must specify the extra ldflags" |
| 266 |
exit 1 |
| 267 |
fi |
| 268 |
ldflags="$1" |
| 269 |
echo "setting extra ldflags: $ldflags" |
| 270 |
shift |
| 271 |
;; |
| 272 |
--*) |
| 273 |
echo "unknown suboption to --compile-subagent: $1" |
| 274 |
exit 1 |
| 275 |
;; |
| 276 |
*) |
| 277 |
if test "x$outname" = "x"; then |
| 278 |
outname=$1 |
| 279 |
shift |
| 280 |
else |
| 281 |
done=1 |
| 282 |
fi |
| 283 |
;; |
| 284 |
esac |
| 285 |
done |
| 286 |
tmpfile=netsnmptmp.$$.c |
| 287 |
if test -f $tmpfile; then |
| 288 |
echo "Ack. Can't create $tmpfile: already exists" |
| 289 |
exit 1 |
| 290 |
fi |
| 291 |
echo "generating the temporary code file: $tmpfile" |
| 292 |
rm -f $tmpfile |
| 293 |
cat > $tmpfile <<EOF |
| 294 |
/* generated from net-snmp-config */ |
| 295 |
#include <net-snmp/net-snmp-config.h> |
| 296 |
#ifdef HAVE_SIGNAL |
| 297 |
#include <signal.h> |
| 298 |
#endif /* HAVE_SIGNAL */ |
| 299 |
#ifdef HAVE_SYS_STAT_H |
| 300 |
#include <sys/stat.h> |
| 301 |
#endif /* HAVE_SYS_STAT_H */ |
| 302 |
#ifdef HAVE_FCNTL_H |
| 303 |
#include <fcntl.h> |
| 304 |
#endif /* HAVE_FCNTL_H */ |
| 305 |
#include <net-snmp/net-snmp-includes.h> |
| 306 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 307 |
EOF |
| 308 |
|
| 309 |
# If we were only given a single filename |
| 310 |
# (and no explicit output name) |
| 311 |
# then use that as the base of the output name |
| 312 |
# |
| 313 |
# If we weren't even given that, then bomb out |
| 314 |
if test "x$1" = "x"; then |
| 315 |
if test "x$outname" = "x"; then |
| 316 |
echo "No MIB module codefile specified" |
| 317 |
rm -f $tmpfile |
| 318 |
exit 1 |
| 319 |
else |
| 320 |
cfiles=$outname |
| 321 |
outname=`basename $cfiles | sed 's/\.[co]$//'` |
| 322 |
if test -f $outname.h; then |
| 323 |
if grep "init_$outname" $outname.h; then |
| 324 |
echo " #include \"$outname.h\"" >> $tmpfile |
| 325 |
fi |
| 326 |
fi |
| 327 |
fi |
| 328 |
fi |
| 329 |
|
| 330 |
# add include files |
| 331 |
while test "$1" != ""; do |
| 332 |
cfiles="$cfiles $1" |
| 333 |
name=`basename $1 | sed 's/\.[co]$//'` |
| 334 |
if test -f $name.h; then |
| 335 |
if grep "init_$name" $name.h; then |
| 336 |
echo " #include \"$name.h\"" >> $tmpfile |
| 337 |
fi |
| 338 |
fi |
| 339 |
shift |
| 340 |
done |
| 341 |
|
| 342 |
cat >> $tmpfile <<EOF |
| 343 |
const char *app_name = "$outname"; |
| 344 |
static int reconfig = 0; |
| 345 |
|
| 346 |
extern int netsnmp_running; |
| 347 |
|
| 348 |
RETSIGTYPE |
| 349 |
stop_server(int a) { |
| 350 |
netsnmp_running = 0; |
| 351 |
} |
| 352 |
|
| 353 |
#ifdef SIGHUP |
| 354 |
RETSIGTYPE |
| 355 |
hup_handler(int sig) |
| 356 |
{ |
| 357 |
reconfig = 1; |
| 358 |
signal(SIGHUP, hup_handler); |
| 359 |
} |
| 360 |
#endif |
| 361 |
|
| 362 |
static void |
| 363 |
usage(const char *prog) |
| 364 |
{ |
| 365 |
fprintf(stderr, |
| 366 |
"USAGE: %s [OPTIONS]\n" |
| 367 |
"\n" |
| 368 |
"OPTIONS:\n", prog); |
| 369 |
|
| 370 |
fprintf(stderr, |
| 371 |
" -c FILE[,...]\t\tread FILE(s) as configuration file(s)\n" |
| 372 |
" -C\t\t\tdo not read the default configuration files\n" |
| 373 |
" -d\t\t\tdump all traffic\n" |
| 374 |
" -D TOKEN[,...]\tturn on debugging output for the specified " |
| 375 |
"TOKENs\n" |
| 376 |
"\t\t\t (ALL gives extremely verbose debugging output)\n" |
| 377 |
" -f\t\t\tDo not fork() from the calling shell.\n" |
| 378 |
" -h\t\t\tdisplay this help message\n" |
| 379 |
" -H\t\t\tdisplay a list of configuration file directives\n" |
| 380 |
" -L LOGOPTS\t\tToggle various defaults controlling logging:\n"); |
| 381 |
snmp_log_options_usage("\t\t\t ", stderr); |
| 382 |
#ifndef DISABLE_MIB_LOADING |
| 383 |
fprintf(stderr, |
| 384 |
" -m MIB[" ENV_SEPARATOR "...]\t\tload given list of MIBs (ALL loads " |
| 385 |
"everything)\n" |
| 386 |
" -M DIR[" ENV_SEPARATOR "...]\t\tlook in given list of directories for MIBs\n"); |
| 387 |
#endif /* DISABLE_MIB_LOADING */ |
| 388 |
fprintf(stderr, |
| 389 |
" -p FILE\t\tstore process id in FILE\n"); |
| 390 |
#ifndef DISABLE_MIB_LOADING |
| 391 |
fprintf(stderr, |
| 392 |
" -P MIBOPTS\t\tToggle various defaults controlling mib " |
| 393 |
"parsing:\n"); |
| 394 |
snmp_mib_toggle_options_usage("\t\t\t ", stderr); |
| 395 |
#endif /* DISABLE_MIB_LOADING */ |
| 396 |
fprintf(stderr, |
| 397 |
" -v\t\t\tdisplay package version number\n" |
| 398 |
" -x TRANSPORT\tconnect to master agent using TRANSPORT\n"); |
| 399 |
exit(1); |
| 400 |
} |
| 401 |
|
| 402 |
static void |
| 403 |
version(void) |
| 404 |
{ |
| 405 |
fprintf(stderr, "NET-SNMP version: %s\n", netsnmp_get_version()); |
| 406 |
exit(0); |
| 407 |
} |
| 408 |
|
| 409 |
int |
| 410 |
main (int argc, char **argv) |
| 411 |
{ |
| 412 |
int arg; |
| 413 |
char* cp = NULL; |
| 414 |
int dont_fork = 0, do_help = 0; |
| 415 |
char* pid_file = NULL; |
| 416 |
|
| 417 |
while ((arg = getopt(argc, argv, "c:CdD:fhHL:" |
| 418 |
#ifndef DISABLE_MIB_LOADING |
| 419 |
"m:M:" |
| 420 |
#endif /* DISABLE_MIB_LOADING */ |
| 421 |
"n:p:" |
| 422 |
#ifndef DISABLE_MIB_LOADING |
| 423 |
"P:" |
| 424 |
#endif /* DISABLE_MIB_LOADING */ |
| 425 |
"vx:")) != EOF) { |
| 426 |
switch (arg) { |
| 427 |
case 'c': |
| 428 |
if (optarg != NULL) { |
| 429 |
netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, |
| 430 |
NETSNMP_DS_LIB_OPTIONALCONFIG, optarg); |
| 431 |
} else { |
| 432 |
usage(argv[0]); |
| 433 |
} |
| 434 |
break; |
| 435 |
|
| 436 |
case 'C': |
| 437 |
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, |
| 438 |
NETSNMP_DS_LIB_DONT_READ_CONFIGS, 1); |
| 439 |
break; |
| 440 |
|
| 441 |
case 'd': |
| 442 |
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, |
| 443 |
NETSNMP_DS_LIB_DUMP_PACKET, 1); |
| 444 |
break; |
| 445 |
|
| 446 |
case 'D': |
| 447 |
debug_register_tokens(optarg); |
| 448 |
snmp_set_do_debugging(1); |
| 449 |
break; |
| 450 |
|
| 451 |
case 'f': |
| 452 |
dont_fork = 1; |
| 453 |
break; |
| 454 |
|
| 455 |
case 'h': |
| 456 |
usage(argv[0]); |
| 457 |
break; |
| 458 |
|
| 459 |
case 'H': |
| 460 |
do_help = 1; |
| 461 |
break; |
| 462 |
|
| 463 |
case 'L': |
| 464 |
if (snmp_log_options(optarg, argc, argv) < 0) { |
| 465 |
exit(1); |
| 466 |
} |
| 467 |
break; |
| 468 |
|
| 469 |
#ifndef DISABLE_MIB_LOADING |
| 470 |
case 'm': |
| 471 |
if (optarg != NULL) { |
| 472 |
setenv("MIBS", optarg, 1); |
| 473 |
} else { |
| 474 |
usage(argv[0]); |
| 475 |
} |
| 476 |
break; |
| 477 |
|
| 478 |
case 'M': |
| 479 |
if (optarg != NULL) { |
| 480 |
setenv("MIBDIRS", optarg, 1); |
| 481 |
} else { |
| 482 |
usage(argv[0]); |
| 483 |
} |
| 484 |
break; |
| 485 |
#endif /* DISABLE_MIB_LOADING */ |
| 486 |
|
| 487 |
case 'n': |
| 488 |
if (optarg != NULL) { |
| 489 |
app_name = optarg; |
| 490 |
netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, |
| 491 |
NETSNMP_DS_LIB_APPTYPE, app_name); |
| 492 |
} else { |
| 493 |
usage(argv[0]); |
| 494 |
} |
| 495 |
break; |
| 496 |
|
| 497 |
case 'p': |
| 498 |
if (optarg != NULL) { |
| 499 |
pid_file = optarg; |
| 500 |
} else { |
| 501 |
usage(argv[0]); |
| 502 |
} |
| 503 |
break; |
| 504 |
|
| 505 |
#ifndef DISABLE_MIB_LOADING |
| 506 |
case 'P': |
| 507 |
cp = snmp_mib_toggle_options(optarg); |
| 508 |
if (cp != NULL) { |
| 509 |
fprintf(stderr, "Unknown parser option to -P: %c.\n", *cp); |
| 510 |
usage(argv[0]); |
| 511 |
} |
| 512 |
break; |
| 513 |
#endif /* DISABLE_MIB_LOADING */ |
| 514 |
|
| 515 |
case 'v': |
| 516 |
version(); |
| 517 |
break; |
| 518 |
|
| 519 |
case 'x': |
| 520 |
if (optarg != NULL) { |
| 521 |
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, |
| 522 |
NETSNMP_DS_AGENT_X_SOCKET, optarg); |
| 523 |
} else { |
| 524 |
usage(argv[0]); |
| 525 |
} |
| 526 |
break; |
| 527 |
|
| 528 |
default: |
| 529 |
fprintf(stderr, "invalid option: -%c\n", arg); |
| 530 |
usage(argv[0]); |
| 531 |
break; |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
if (do_help) { |
| 536 |
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, |
| 537 |
NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1); |
| 538 |
} else { |
| 539 |
/* we are a subagent */ |
| 540 |
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, |
| 541 |
NETSNMP_DS_AGENT_ROLE, 1); |
| 542 |
|
| 543 |
if (!dont_fork) { |
| 544 |
if (netsnmp_daemonize(1, snmp_stderrlog_status()) != 0) |
| 545 |
exit(1); |
| 546 |
} |
| 547 |
|
| 548 |
#ifdef HAVE_GETPID |
| 549 |
if (pid_file != NULL) { |
| 550 |
/* |
| 551 |
* unlink the pid_file, if it exists, prior to open. Without |
| 552 |
* doing this the open will fail if the user specified pid_file |
| 553 |
* already exists. |
| 554 |
*/ |
| 555 |
int fd; |
| 556 |
unlink(pid_file); |
| 557 |
fd = open(pid_file, O_CREAT | O_EXCL | O_WRONLY, 0600); |
| 558 |
if (fd == -1) { |
| 559 |
snmp_log_perror(pid_file); |
| 560 |
if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, |
| 561 |
NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) { |
| 562 |
exit(1); |
| 563 |
} |
| 564 |
} else { |
| 565 |
char buf[3 + sizeof(long) * 3]; |
| 566 |
int len = snprintf(buf, sizeof(buf), "%ld\n", (long int)getpid()); |
| 567 |
write(fd, buf, len); |
| 568 |
close(fd); |
| 569 |
} |
| 570 |
} |
| 571 |
#endif |
| 572 |
|
| 573 |
/* initialize tcpip, if necessary */ |
| 574 |
SOCK_STARTUP; |
| 575 |
} |
| 576 |
|
| 577 |
/* initialize the agent library */ |
| 578 |
init_agent(app_name); |
| 579 |
|
| 580 |
/* initialize your mib code here */ |
| 581 |
EOF |
| 582 |
|
| 583 |
# add init routines |
| 584 |
for i in $cfiles ; do |
| 585 |
name=`basename $i | sed 's/\.[co]$//'` |
| 586 |
echo checking for init_$name in $i |
| 587 |
if grep "init_$name" $i ; then |
| 588 |
echo " init_${name}();" >> $tmpfile |
| 589 |
fi |
| 590 |
done |
| 591 |
|
| 592 |
# handle the main loop |
| 593 |
cat >> $tmpfile <<EOF |
| 594 |
|
| 595 |
/* $outname will be used to read $outname.conf files. */ |
| 596 |
init_snmp("$outname"); |
| 597 |
|
| 598 |
if (do_help) { |
| 599 |
fprintf(stderr, "Configuration directives understood:\n"); |
| 600 |
read_config_print_usage(" "); |
| 601 |
exit(0); |
| 602 |
} |
| 603 |
|
| 604 |
/* In case we received a request to stop (kill -TERM or kill -INT) */ |
| 605 |
netsnmp_running = 1; |
| 606 |
#ifdef SIGTERM |
| 607 |
signal(SIGTERM, stop_server); |
| 608 |
#endif |
| 609 |
#ifdef SIGINT |
| 610 |
signal(SIGINT, stop_server); |
| 611 |
#endif |
| 612 |
#ifdef SIGHUP |
| 613 |
signal(SIGHUP, hup_handler); |
| 614 |
#endif |
| 615 |
|
| 616 |
/* main loop here... */ |
| 617 |
while(netsnmp_running) { |
| 618 |
if (reconfig) { |
| 619 |
free_config(); |
| 620 |
read_configs(); |
| 621 |
reconfig = 0; |
| 622 |
} |
| 623 |
agent_check_and_process(1); |
| 624 |
} |
| 625 |
|
| 626 |
/* at shutdown time */ |
| 627 |
snmp_shutdown(app_name); |
| 628 |
|
| 629 |
/* deinitialize your mib code here */ |
| 630 |
EOF |
| 631 |
|
| 632 |
# add shutdown routines |
| 633 |
|
| 634 |
i=`count $cfiles` |
| 635 |
while [ $i -gt 0 ] ; do |
| 636 |
fullname=`index $i $cfiles` |
| 637 |
name=`basename $fullname | sed 's/\.[co]$//'` |
| 638 |
echo checking for shutdown_$name in $fullname |
| 639 |
if grep "shutdown_$name" $fullname ; then |
| 640 |
echo " shutdown_${name}();" >> $tmpfile |
| 641 |
fi |
| 642 |
i=`expr $i - 1` |
| 643 |
done |
| 644 |
|
| 645 |
# finish file |
| 646 |
cat >> $tmpfile <<EOF |
| 647 |
|
| 648 |
/* shutdown the agent library */ |
| 649 |
shutdown_agent(); |
| 650 |
|
| 651 |
if (pid_file != NULL) { |
| 652 |
unlink(pid_file); |
| 653 |
} |
| 654 |
|
| 655 |
SOCK_CLEANUP; |
| 656 |
exit(0); |
| 657 |
} |
| 658 |
EOF |
| 659 |
if test "$?" != 0 -o ! -f "$tmpfile" ; then |
| 660 |
echo "Ack. Can't create $tmpfile." |
| 661 |
exit 1 |
| 662 |
fi |
| 663 |
cmd="@CC@ $cflags @CFLAGS@ @DEVFLAGS@ -I. -I${NSC_INCLUDEDIR} -o $outname $tmpfile $cfiles $NSC_LDFLAGS $NSC_LIBDIR $NSC_BASE_AGENT_LIBS $NSC_AGENTLIBS $ldflags" |
| 664 |
echo "running: $cmd" |
| 665 |
echo `$cmd` |
| 666 |
result=$? |
| 667 |
if test "x$norm" != "x1" ; then |
| 668 |
echo "removing the temporary code file: $tmpfile" |
| 669 |
rm -f $tmpfile |
| 670 |
else |
| 671 |
echo "leaving the temporary code file: $tmpfile" |
| 672 |
fi |
| 673 |
if test "$result" = "0" -a -f "$outname" ; then |
| 674 |
echo "subagent program $outname created" |
| 675 |
fi |
| 676 |
exit $result |
| 677 |
;; |
| 678 |
|
| 679 |
*) |
| 680 |
echo "unknown option $1" |
| 681 |
usage="yes" |
| 682 |
;; |
| 683 |
esac |
| 684 |
if [ "x$shifted" = "x" ] ; then |
| 685 |
shift |
| 686 |
fi |
| 687 |
done |
| 688 |
fi |
| 689 |
|
| 690 |
if test "x$usage" = "xyes"; then |
| 691 |
echo "" |
| 692 |
echo "Usage:" |
| 693 |
echo " net-snmp-config [--cflags] [--agent-libs] [--libs] [--version]" |
| 694 |
echo " ... [see below for complete flag list]" |
| 695 |
echo "" |
| 696 |
echo " --version displays the net-snmp version number" |
| 697 |
echo " --indent-options displays the indent options from the Coding Style" |
| 698 |
echo " --debug-tokens displays a example command line to search to source" |
| 699 |
echo " code for a list of available debug tokens" |
| 700 |
echo "" |
| 701 |
echo " SNMP Setup commands:" |
| 702 |
echo "" |
| 703 |
echo " --create-snmpv3-user creates a SNMPv3 user in Net-SNMP config file." |
| 704 |
echo " See net-snmp-create-v3-user --help for list of" |
| 705 |
echo " accepted options." |
| 706 |
echo "" |
| 707 |
echo " These options produce the various compilation flags needed when" |
| 708 |
echo " building external SNMP applications:" |
| 709 |
echo "" |
| 710 |
echo " --base-cflags lists additional compilation flags needed" |
| 711 |
echo " --cflags lists additional compilation flags needed" |
| 712 |
echo " (includes -I. and extra developer warning flags)" |
| 713 |
echo "" |
| 714 |
echo " These options produce the various link flags needed when" |
| 715 |
echo " building external SNMP applications:" |
| 716 |
echo "" |
| 717 |
echo " --libs lists libraries needed for building applications" |
| 718 |
echo " --agent-libs lists libraries needed for building subagents" |
| 719 |
echo "" |
| 720 |
echo " These options produce various link flags broken down into parts." |
| 721 |
echo " (Most of the time the simple options above should be used.)" |
| 722 |
echo "" |
| 723 |
echo " --libdir path to netsnmp libraries" |
| 724 |
echo "" |
| 725 |
echo " --base-agent-libs netsnmp specific agent libraries" |
| 726 |
echo "" |
| 727 |
echo " --netsnmp-libs netsnmp specific libraries (with path)" |
| 728 |
echo " --netsnmp-agent-libs netsnmp specific agent libraries (with path)" |
| 729 |
echo "" |
| 730 |
echo " --ldflags link flags for external libraries" |
| 731 |
echo " --external-libs external libraries needed by netsnmp libs" |
| 732 |
echo " --external-agent-libs external libraries needed by netsnmp agent libs" |
| 733 |
echo "" |
| 734 |
echo " These options produce various link flags used when linking an" |
| 735 |
echo " external application against an uninstalled build directory." |
| 736 |
echo "" |
| 737 |
echo " --build-includes include path to build/source includes" |
| 738 |
echo " --build-lib-dirs link path to libraries" |
| 739 |
echo " --build-lib-deps path to libraries for dependency target" |
| 740 |
echo " --build-command command to compile \$3... to \$2" |
| 741 |
echo "" |
| 742 |
echo " Automated subagent building (produces an OUTPUTNAME binary file):" |
| 743 |
echo " [this feature has not been tested very well yet. use at your risk.]" |
| 744 |
echo "" |
| 745 |
echo " --compile-subagent OUTPUTNAME [--norm] [--cflags flags]" |
| 746 |
echo " [--ldflags flags] mibmodule1.c [...]]" |
| 747 |
echo "" |
| 748 |
echo " --norm leave the generated .c file around to read." |
| 749 |
echo " --cflags flags extra cflags to use (e.g. -I...)." |
| 750 |
echo " --ldflags flags extra ld flags to use (e.g. -L... -l...)." |
| 751 |
echo "" |
| 752 |
echo " Details on how the net-snmp package was compiled:" |
| 753 |
echo "" |
| 754 |
echo " --configure-options display original configure arguments" |
| 755 |
echo " --prefix display the installation prefix" |
| 756 |
echo " --snmpd-module-list display the modules compiled into the agent" |
| 757 |
echo " --default-mibs display default list of MIBs" |
| 758 |
echo " --default-mibdirs display default list of MIB directories" |
| 759 |
echo " --snmpconfpath display default SNMPCONFPATH" |
| 760 |
echo " --persistent-directory display default persistent directory" |
| 761 |
echo " --perlprog display path to perl for the perl modules" |
| 762 |
echo "" |
| 763 |
exit |
| 764 |
fi |