Explorar el Código

Name and version change

Ethan Galstad hace 24 años
padre
commit
abfff2e241
Se han modificado 17 ficheros con 642 adiciones y 365 borrados
  1. 17 4
      Changelog
  2. 6 7
      Makefile.in
  3. 46 12
      README
  4. 5 2
      common/common.h
  5. 2 2
      common/config.h.in
  6. 182 97
      configure
  7. 5 1
      configure.in
  8. 31 0
      contrib/README.nrpe_check_control
  9. 121 0
      contrib/nrpe_check_control.c
  10. 63 0
      init-script
  11. 1 1
      nrpe.cfg
  12. 5 6
      src/Makefile.in
  13. 22 60
      src/check_nrpe.c
  14. 78 101
      src/netutils.c
  15. 12 13
      src/netutils.h
  16. 44 57
      src/nrpe.c
  17. 2 2
      src/nrpe.h

+ 17 - 4
Changelog

@@ -2,10 +2,23 @@
 NRPE Changelog
 NRPE Changelog
 **************
 **************
 
 
-1.3 - 06/23/2001
+
+1.3 - 02/21/2002
 ----------------
 ----------------
-- Name change
-- Version number change
+- Name and version change
+- Ignore SIGHUP, minor cleanup (Jon Andrews)
+
+
+1.2.5 - 12/22/2001
+------------------
+- Implemented Beej's sendall() to handle partial send()s
+- Added instructions on running under xinetd to README
+- Removed some old crud
+
+
+1.2.4 - 02/22/2001
+------------------
+- I forgot what changes I made.  Go figure...
 
 
 
 
 1.2.3 - 12/21/2000
 1.2.3 - 12/21/2000
@@ -85,7 +98,7 @@ NRPE Changelog
 1.0b6 - 02/01/2000
 1.0b6 - 02/01/2000
 ------------------
 ------------------
 - Added configure script
 - Added configure script
-- Netutils functions from the plugins is now used
+- Netutils functions from the NetSaint plugins is now used
 - Reset SIGCHLD to default behavior before calling popen() to
 - Reset SIGCHLD to default behavior before calling popen() to
   prevent race condition with pclose() (Reported by Rene Klootwijk)
   prevent race condition with pclose() (Reported by Rene Klootwijk)
 - Cleaned up code
 - Cleaned up code

+ 6 - 7
Makefile.in

@@ -1,7 +1,7 @@
 ###############################
 ###############################
 # Makefile for NRPE
 # Makefile for NRPE
 #
 #
-# Last Modified: 01/21/2000
+# Last Modified: 12-23-2001
 ###############################
 ###############################
 
 
 
 
@@ -9,7 +9,8 @@
 SRC_BASE=./src/
 SRC_BASE=./src/
 SRC_COMMON=./common/
 SRC_COMMON=./common/
 
 
-all:	nrpe check_nrpe	
+all:
+	cd $(SRC_BASE); $(MAKE) ; cd ..
 
 
 nrpe:
 nrpe:
 	cd $(SRC_BASE); $(MAKE) ; cd ..
 	cd $(SRC_BASE); $(MAKE) ; cd ..
@@ -21,12 +22,10 @@ check_nrpe:
 clean:
 clean:
 	cd $(SRC_BASE); $(MAKE) $@ ; cd ..
 	cd $(SRC_BASE); $(MAKE) $@ ; cd ..
 	rm -f core
 	rm -f core
+	rm -f *~ */*~
+	rm -f config.log config.status config.cache Makefile $(SRC_COMMON)/config.h
 
 
 distclean: clean
 distclean: clean
-	cd $(SRC_BASE); $(MAKE) $@ ; cd ..
-	rm -f config.log config.status config.cache Makefile \
-	$(SRC_COMMON)/config.h \
 
 
-devclean: distclean
-	rm -f *~ */*~
+devclean: clean
 
 

+ 46 - 12
README

@@ -5,7 +5,7 @@ NRPE README
 
 
 Purpose
 Purpose
 -------
 -------
-The purpose of this addon is to allow you to execute Nagios
+The purpose of this addon is to allow you to execute Nagios 
 plugins on a remote host in as transparent a manner as possible.
 plugins on a remote host in as transparent a manner as possible.
 
 
 
 
@@ -70,39 +70,73 @@ make much use of this addon.
 
 
 
 
 
 
-Running Under INETD
--------------------
+Running Under INETD or XINETD
+-----------------------------
 
 
-If you plan on running nrpe under inetd and making use of TCP
-wrappers, you need to do two things:
+If you plan on running nrpe under inetd or xinetd and making use
+of TCP wrappers, you need to do the following things:
 
 
 1) Add a line to your /etc/services file as follows (modify the port
 1) Add a line to your /etc/services file as follows (modify the port
    number as you see fit)
    number as you see fit)
 
 
 	nrpe            5666/tcp	# NRPE
 	nrpe            5666/tcp	# NRPE
 
 
-2) Add an entry to /etc/inetd.conf as follows
+2) If your system uses the inetd superserver, add an entry to 
+   /etc/inetd.conf as follows:
+
 
 
 	nrpe 	stream 	tcp 	nowait 	<user> /usr/sbin/tcpd <nrpebin> -i <nrpecfg>
 	nrpe 	stream 	tcp 	nowait 	<user> /usr/sbin/tcpd <nrpebin> -i <nrpecfg>
 
 
-   - Replace <user> with the name of the user that nrpe should run as
-	Example: nagios
+
+   - Replace <user> with the name of the user that the nrpe server should run as.
+     	Example: nagios
    - Replace <nrpebin> with the path to the nrpe binary on your system.
    - Replace <nrpebin> with the path to the nrpe binary on your system.
 	Example: /usr/local/nagios/nrpe
 	Example: /usr/local/nagios/nrpe
    - Replace <nrpecfg> with the path to the nrpe config file on your system.
    - Replace <nrpecfg> with the path to the nrpe config file on your system.
 	Example: /usr/local/nagios/nrpe.cfg
 	Example: /usr/local/nagios/nrpe.cfg
 
 
-3) Restart inetd will the following command
+3) If your system uses xinetd instead of inetd, you'll probably
+   want to create a file called 'nrpe' in your /etc/xinetd.d
+   directory that contains the following entries:
+
+
+	# default: on
+	# description: NRPE
+	service nrpe
+	{
+        	flags           = REUSE
+	        socket_type     = stream        
+        	wait            = no
+	        user            = <user>
+        	server          = <nrpebin>
+	        server_args     = -i <nrpecfg>
+        	log_on_failure  += USERID
+	        disable         = no
+		only_from       = <ipaddress1> <ipaddress2> ...
+	}
+
+
+   - Replace <user> with the name of the user that the nrpe server should run as.
+   - Replace <nrpebin> with the path to the nrpe binary on your system.
+   - Replace <nrpecfg> with the path to the nrpe config file on your system.
+   - Replace the <ipaddress> fields with the IP addresses of hosts which
+     are allowed to connect to the NRPE daemon.  This only works if xinetd was
+     compiled with support for wrappers.
+
+4) Restart inetd or xinetd will the following command (pick the
+   on that is appropriate for your system:
 
 
 	/etc/rc.d/init.d/inet restart
 	/etc/rc.d/init.d/inet restart
 
 
-4) Add entries to your /etc/hosts.allow and /etc/hosts.deny
+	/etc/rc.d/init.d/xinetd restart
+
+5) Add entries to your /etc/hosts.allow and /etc/hosts.deny
    file to enable TCP wrapper protection for the nrpe service.
    file to enable TCP wrapper protection for the nrpe service.
    This is optional, although highly recommended.
    This is optional, although highly recommended.
 
 
 
 
-Note: If you run nrpe under inetd, the server_port and 
-      allowed_hosts variables in the nrpe.cfg configuration 
+Note: If you run nrpe under inetd or xinetd, the server_port
+      and allowed_hosts variables in the nrpe configuration 
       file are ignored.
       file are ignored.
 
 
 
 

+ 5 - 2
common/common.h

@@ -1,8 +1,8 @@
 /************************************************************************
 /************************************************************************
  *
  *
  * COMMON.H - NRPE Common Include File
  * COMMON.H - NRPE Common Include File
- * Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)
- * Last Modified: 06-23-2001
+ * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
+ * Last Modified: 02-21-2002
  *
  *
  * License:
  * License:
  *
  *
@@ -22,6 +22,9 @@
  ************************************************************************/
  ************************************************************************/
 
 
 
 
+#define PROGRAM_VERSION "1.3"
+#define MODIFICATION_DATE "02-21-2002"
+
 #define OK		0
 #define OK		0
 #define ERROR		-1
 #define ERROR		-1
 
 

+ 2 - 2
common/config.h.in

@@ -1,8 +1,8 @@
 /************************************************************************
 /************************************************************************
  *
  *
  * NRPE Common Header File
  * NRPE Common Header File
- * Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)
- * Last Modified: 06-23-2001
+ * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
+ * Last Modified: 02-21-2002
  *
  *
  * License:
  * License:
  *
  *

+ 182 - 97
configure

@@ -1,7 +1,7 @@
 #! /bin/sh
 #! /bin/sh
 
 
 # Guess values for system-dependent variables and create Makefiles.
 # Guess values for system-dependent variables and create Makefiles.
-# Generated automatically using autoconf version 2.12 
+# Generated automatically using autoconf version 2.13 
 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
 #
 #
 # This configure script is free software; the Free Software Foundation
 # This configure script is free software; the Free Software Foundation
@@ -50,6 +50,7 @@ mandir='${prefix}/man'
 # Initialize some other variables.
 # Initialize some other variables.
 subdirs=
 subdirs=
 MFLAGS= MAKEFLAGS=
 MFLAGS= MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
 # Maximum number of lines to put in a shell here document.
 # Maximum number of lines to put in a shell here document.
 ac_max_here_lines=12
 ac_max_here_lines=12
 
 
@@ -333,7 +334,7 @@ EOF
     verbose=yes ;;
     verbose=yes ;;
 
 
   -version | --version | --versio | --versi | --vers)
   -version | --version | --versio | --versi | --vers)
-    echo "configure generated by autoconf version 2.12"
+    echo "configure generated by autoconf version 2.13"
     exit 0 ;;
     exit 0 ;;
 
 
   -with-* | --with-*)
   -with-* | --with-*)
@@ -503,9 +504,11 @@ ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CPP $CPPFLAGS'
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 cross_compiling=$ac_cv_prog_cc_cross
 
 
+ac_exeext=
+ac_objext=o
 if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
 if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
   # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
   # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
   if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
   if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
@@ -549,28 +552,30 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
 # SunOS /usr/etc/install
 # SunOS /usr/etc/install
 # IRIX /sbin/install
 # IRIX /sbin/install
 # AIX /bin/install
 # AIX /bin/install
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
 # AFS /usr/afsws/bin/install, which mishandles nonexistent args
 # AFS /usr/afsws/bin/install, which mishandles nonexistent args
 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
 # ./install, which can be erroneously created by make from ./install.sh.
 # ./install, which can be erroneously created by make from ./install.sh.
 echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
 echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:557: checking for a BSD compatible install" >&5
+echo "configure:561: checking for a BSD compatible install" >&5
 if test -z "$INSTALL"; then
 if test -z "$INSTALL"; then
 if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
-    IFS="${IFS= 	}"; ac_save_IFS="$IFS"; IFS="${IFS}:"
+    IFS="${IFS= 	}"; ac_save_IFS="$IFS"; IFS=":"
   for ac_dir in $PATH; do
   for ac_dir in $PATH; do
     # Account for people who put trailing slashes in PATH elements.
     # Account for people who put trailing slashes in PATH elements.
     case "$ac_dir/" in
     case "$ac_dir/" in
     /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
     /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;;
     *)
     *)
       # OSF1 and SCO ODT 3.0 have their own names for install.
       # OSF1 and SCO ODT 3.0 have their own names for install.
-      for ac_prog in ginstall installbsd scoinst install; do
+      # Don't use installbsd from OSF since it installs stuff as root
+      # by default.
+      for ac_prog in ginstall scoinst install; do
         if test -f $ac_dir/$ac_prog; then
         if test -f $ac_dir/$ac_prog; then
 	  if test $ac_prog = install &&
 	  if test $ac_prog = install &&
             grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
             grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
 	    # AIX install.  It has an incompatible calling convention.
 	    # AIX install.  It has an incompatible calling convention.
-	    # OSF/1 installbsd also uses dspmsg, but is usable.
 	    :
 	    :
 	  else
 	  else
 	    ac_cv_path_install="$ac_dir/$ac_prog -c"
 	    ac_cv_path_install="$ac_dir/$ac_prog -c"
@@ -600,6 +605,8 @@ echo "$ac_t""$INSTALL" 1>&6
 # It thinks the first close brace ends the variable substitution.
 # It thinks the first close brace ends the variable substitution.
 test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
 test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
 
 
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
+
 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 
 
 
 
@@ -607,15 +614,16 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 # Extract the first word of "gcc", so it can be a program name with args.
 # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:611: checking for $ac_word" >&5
+echo "configure:618: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   if test -n "$CC"; then
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
 else
-  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
-  for ac_dir in $PATH; do
+  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do
     test -z "$ac_dir" && ac_dir=.
     test -z "$ac_dir" && ac_dir=.
     if test -f $ac_dir/$ac_word; then
     if test -f $ac_dir/$ac_word; then
       ac_cv_prog_CC="gcc"
       ac_cv_prog_CC="gcc"
@@ -636,16 +644,17 @@ if test -z "$CC"; then
   # Extract the first word of "cc", so it can be a program name with args.
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:640: checking for $ac_word" >&5
+echo "configure:648: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   if test -n "$CC"; then
   if test -n "$CC"; then
   ac_cv_prog_CC="$CC" # Let the user override the test.
   ac_cv_prog_CC="$CC" # Let the user override the test.
 else
 else
-  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS="${IFS}:"
+  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
   ac_prog_rejected=no
   ac_prog_rejected=no
-  for ac_dir in $PATH; do
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do
     test -z "$ac_dir" && ac_dir=.
     test -z "$ac_dir" && ac_dir=.
     if test -f $ac_dir/$ac_word; then
     if test -f $ac_dir/$ac_word; then
       if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
       if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then
@@ -680,25 +689,61 @@ else
   echo "$ac_t""no" 1>&6
   echo "$ac_t""no" 1>&6
 fi
 fi
 
 
+  if test -z "$CC"; then
+    case "`uname -s`" in
+    *win32* | *WIN32*)
+      # Extract the first word of "cl", so it can be a program name with args.
+set dummy cl; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:699: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  if test -n "$CC"; then
+  ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$ac_word; then
+      ac_cv_prog_CC="cl"
+      break
+    fi
+  done
+  IFS="$ac_save_ifs"
+fi
+fi
+CC="$ac_cv_prog_CC"
+if test -n "$CC"; then
+  echo "$ac_t""$CC" 1>&6
+else
+  echo "$ac_t""no" 1>&6
+fi
+ ;;
+    esac
+  fi
   test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
   test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; }
 fi
 fi
 
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:688: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:731: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 
 ac_ext=c
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
 ac_cpp='$CPP $CPPFLAGS'
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 cross_compiling=$ac_cv_prog_cc_cross
 
 
-cat > conftest.$ac_ext <<EOF
-#line 698 "configure"
+cat > conftest.$ac_ext << EOF
+
+#line 742 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
+
 main(){return(0);}
 main(){return(0);}
 EOF
 EOF
-if { (eval echo configure:702: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:747: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
   if (./conftest; exit) 2>/dev/null; then
@@ -712,18 +757,24 @@ else
   ac_cv_prog_cc_works=no
   ac_cv_prog_cc_works=no
 fi
 fi
 rm -fr conftest*
 rm -fr conftest*
+ac_ext=c
+# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
+ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
+cross_compiling=$ac_cv_prog_cc_cross
 
 
 echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
 echo "$ac_t""$ac_cv_prog_cc_works" 1>&6
 if test $ac_cv_prog_cc_works = no; then
 if test $ac_cv_prog_cc_works = no; then
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:722: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:773: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 cross_compiling=$ac_cv_prog_cc_cross
 
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:727: checking whether we are using GNU C" >&5
+echo "configure:778: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
@@ -732,7 +783,7 @@ else
   yes;
   yes;
 #endif
 #endif
 EOF
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:736: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:787: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
   ac_cv_prog_gcc=yes
 else
 else
   ac_cv_prog_gcc=no
   ac_cv_prog_gcc=no
@@ -743,11 +794,15 @@ echo "$ac_t""$ac_cv_prog_gcc" 1>&6
 
 
 if test $ac_cv_prog_gcc = yes; then
 if test $ac_cv_prog_gcc = yes; then
   GCC=yes
   GCC=yes
-  ac_test_CFLAGS="${CFLAGS+set}"
-  ac_save_CFLAGS="$CFLAGS"
-  CFLAGS=
-  echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:751: checking whether ${CC-cc} accepts -g" >&5
+else
+  GCC=
+fi
+
+ac_test_CFLAGS="${CFLAGS+set}"
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS=
+echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
+echo "configure:806: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
@@ -762,20 +817,24 @@ rm -f conftest*
 fi
 fi
 
 
 echo "$ac_t""$ac_cv_prog_cc_g" 1>&6
 echo "$ac_t""$ac_cv_prog_cc_g" 1>&6
-  if test "$ac_test_CFLAGS" = set; then
-    CFLAGS="$ac_save_CFLAGS"
-  elif test $ac_cv_prog_cc_g = yes; then
+if test "$ac_test_CFLAGS" = set; then
+  CFLAGS="$ac_save_CFLAGS"
+elif test $ac_cv_prog_cc_g = yes; then
+  if test "$GCC" = yes; then
     CFLAGS="-g -O2"
     CFLAGS="-g -O2"
   else
   else
-    CFLAGS="-O2"
+    CFLAGS="-g"
   fi
   fi
 else
 else
-  GCC=
-  test "${CFLAGS+set}" = set || CFLAGS="-g"
+  if test "$GCC" = yes; then
+    CFLAGS="-O2"
+  else
+    CFLAGS=
+  fi
 fi
 fi
 
 
 echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
 echo $ac_n "checking whether ${MAKE-make} sets \${MAKE}""... $ac_c" 1>&6
-echo "configure:779: checking whether ${MAKE-make} sets \${MAKE}" >&5
+echo "configure:838: checking whether ${MAKE-make} sets \${MAKE}" >&5
 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
 set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -803,7 +862,7 @@ fi
 
 
 
 
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:807: checking how to run the C preprocessor" >&5
+echo "configure:866: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
   CPP=
@@ -818,14 +877,14 @@ else
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 822 "configure"
+#line 881 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <assert.h>
 #include <assert.h>
 Syntax Error
 Syntax Error
 EOF
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:828: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:887: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
 if test -z "$ac_err"; then
   :
   :
 else
 else
@@ -835,14 +894,31 @@ else
   rm -rf conftest*
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 839 "configure"
+#line 898 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <assert.h>
 #include <assert.h>
 Syntax Error
 Syntax Error
 EOF
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:845: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:904: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  :
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  CPP="${CC-cc} -nologo -E"
+  cat > conftest.$ac_ext <<EOF
+#line 915 "configure"
+#include "confdefs.h"
+#include <assert.h>
+Syntax Error
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:921: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
 if test -z "$ac_err"; then
   :
   :
 else
 else
@@ -854,6 +930,8 @@ else
 fi
 fi
 rm -f conftest*
 rm -f conftest*
 fi
 fi
+rm -f conftest*
+fi
 rm -f conftest*
 rm -f conftest*
   ac_cv_prog_CPP="$CPP"
   ac_cv_prog_CPP="$CPP"
 fi
 fi
@@ -864,12 +942,12 @@ fi
 echo "$ac_t""$CPP" 1>&6
 echo "$ac_t""$CPP" 1>&6
 
 
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:868: checking for ANSI C header files" >&5
+echo "configure:946: checking for ANSI C header files" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 873 "configure"
+#line 951 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdarg.h>
@@ -877,8 +955,8 @@ else
 #include <float.h>
 #include <float.h>
 EOF
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:881: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:959: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
 if test -z "$ac_err"; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_header_stdc=yes
   ac_cv_header_stdc=yes
@@ -894,7 +972,7 @@ rm -f conftest*
 if test $ac_cv_header_stdc = yes; then
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
 cat > conftest.$ac_ext <<EOF
-#line 898 "configure"
+#line 976 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <string.h>
 #include <string.h>
 EOF
 EOF
@@ -912,7 +990,7 @@ fi
 if test $ac_cv_header_stdc = yes; then
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
 cat > conftest.$ac_ext <<EOF
-#line 916 "configure"
+#line 994 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdlib.h>
 EOF
 EOF
@@ -933,7 +1011,7 @@ if test "$cross_compiling" = yes; then
   :
   :
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 937 "configure"
+#line 1015 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <ctype.h>
 #include <ctype.h>
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
@@ -944,7 +1022,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
 exit (0); }
 exit (0); }
 
 
 EOF
 EOF
-if { (eval echo configure:948: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1026: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
 then
   :
   :
 else
 else
@@ -968,12 +1046,12 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6
 echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6
-echo "configure:972: checking whether time.h and sys/time.h may both be included" >&5
+echo "configure:1050: checking whether time.h and sys/time.h may both be included" >&5
 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 977 "configure"
+#line 1055 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/time.h>
@@ -982,7 +1060,7 @@ int main() {
 struct tm *tp;
 struct tm *tp;
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:986: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1064: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_header_time=yes
   ac_cv_header_time=yes
 else
 else
@@ -1003,12 +1081,12 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking for sys/wait.h that is POSIX.1 compatible""... $ac_c" 1>&6
 echo $ac_n "checking for sys/wait.h that is POSIX.1 compatible""... $ac_c" 1>&6
-echo "configure:1007: checking for sys/wait.h that is POSIX.1 compatible" >&5
+echo "configure:1085: checking for sys/wait.h that is POSIX.1 compatible" >&5
 if eval "test \"`echo '$''{'ac_cv_header_sys_wait_h'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_header_sys_wait_h'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1012 "configure"
+#line 1090 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/wait.h>
@@ -1024,7 +1102,7 @@ wait (&s);
 s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;
 s = WIFEXITED (s) ? WEXITSTATUS (s) : 1;
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1028: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1106: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_header_sys_wait_h=yes
   ac_cv_header_sys_wait_h=yes
 else
 else
@@ -1048,18 +1126,18 @@ for ac_hdr in ctype.h errno.h fcntl.h netdb.h signal.h strings.h string.h syslog
 do
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1052: checking for $ac_hdr" >&5
+echo "configure:1130: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1057 "configure"
+#line 1135 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <$ac_hdr>
 #include <$ac_hdr>
 EOF
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1062: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out`
+{ (eval echo configure:1140: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
 if test -z "$ac_err"; then
   rm -rf conftest*
   rm -rf conftest*
   eval "ac_cv_header_$ac_safe=yes"
   eval "ac_cv_header_$ac_safe=yes"
@@ -1086,12 +1164,12 @@ done
 
 
 
 
 echo $ac_n "checking for working const""... $ac_c" 1>&6
 echo $ac_n "checking for working const""... $ac_c" 1>&6
-echo "configure:1090: checking for working const" >&5
+echo "configure:1168: checking for working const" >&5
 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1095 "configure"
+#line 1173 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 
 
 int main() {
 int main() {
@@ -1140,7 +1218,7 @@ ccp = (char const *const *) p;
 
 
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1144: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1222: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_c_const=yes
   ac_cv_c_const=yes
 else
 else
@@ -1161,12 +1239,12 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking whether struct tm is in sys/time.h or time.h""... $ac_c" 1>&6
 echo $ac_n "checking whether struct tm is in sys/time.h or time.h""... $ac_c" 1>&6
-echo "configure:1165: checking whether struct tm is in sys/time.h or time.h" >&5
+echo "configure:1243: checking whether struct tm is in sys/time.h or time.h" >&5
 if eval "test \"`echo '$''{'ac_cv_struct_tm'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_struct_tm'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1170 "configure"
+#line 1248 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 #include <time.h>
 #include <time.h>
@@ -1174,7 +1252,7 @@ int main() {
 struct tm *tp; tp->tm_sec;
 struct tm *tp; tp->tm_sec;
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1178: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1256: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_struct_tm=time.h
   ac_cv_struct_tm=time.h
 else
 else
@@ -1195,12 +1273,12 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking for mode_t""... $ac_c" 1>&6
 echo $ac_n "checking for mode_t""... $ac_c" 1>&6
-echo "configure:1199: checking for mode_t" >&5
+echo "configure:1277: checking for mode_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_mode_t'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_type_mode_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1204 "configure"
+#line 1282 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 #if STDC_HEADERS
 #if STDC_HEADERS
@@ -1209,7 +1287,7 @@ else
 #endif
 #endif
 EOF
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  egrep "mode_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+  egrep "(^|[^a-zA-Z_0-9])mode_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_type_mode_t=yes
   ac_cv_type_mode_t=yes
 else
 else
@@ -1228,12 +1306,12 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking for pid_t""... $ac_c" 1>&6
 echo $ac_n "checking for pid_t""... $ac_c" 1>&6
-echo "configure:1232: checking for pid_t" >&5
+echo "configure:1310: checking for pid_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_pid_t'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_type_pid_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1237 "configure"
+#line 1315 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 #if STDC_HEADERS
 #if STDC_HEADERS
@@ -1242,7 +1320,7 @@ else
 #endif
 #endif
 EOF
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  egrep "pid_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+  egrep "(^|[^a-zA-Z_0-9])pid_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_type_pid_t=yes
   ac_cv_type_pid_t=yes
 else
 else
@@ -1261,12 +1339,12 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking for size_t""... $ac_c" 1>&6
 echo $ac_n "checking for size_t""... $ac_c" 1>&6
-echo "configure:1265: checking for size_t" >&5
+echo "configure:1343: checking for size_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1270 "configure"
+#line 1348 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 #if STDC_HEADERS
 #if STDC_HEADERS
@@ -1275,7 +1353,7 @@ else
 #endif
 #endif
 EOF
 EOF
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
 if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
-  egrep "size_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
+  egrep "(^|[^a-zA-Z_0-9])size_t[^a-zA-Z_0-9]" >/dev/null 2>&1; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_type_size_t=yes
   ac_cv_type_size_t=yes
 else
 else
@@ -1294,12 +1372,12 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6
 echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6
-echo "configure:1298: checking return type of signal handlers" >&5
+echo "configure:1376: checking return type of signal handlers" >&5
 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1303 "configure"
+#line 1381 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 #include <signal.h>
 #include <signal.h>
@@ -1316,7 +1394,7 @@ int main() {
 int i;
 int i;
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1320: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1398: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   rm -rf conftest*
   ac_cv_type_signal=void
   ac_cv_type_signal=void
 else
 else
@@ -1335,12 +1413,12 @@ EOF
 
 
 
 
 echo $ac_n "checking for uid_t in sys/types.h""... $ac_c" 1>&6
 echo $ac_n "checking for uid_t in sys/types.h""... $ac_c" 1>&6
-echo "configure:1339: checking for uid_t in sys/types.h" >&5
+echo "configure:1417: checking for uid_t in sys/types.h" >&5
 if eval "test \"`echo '$''{'ac_cv_type_uid_t'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_type_uid_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1344 "configure"
+#line 1422 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/types.h>
 EOF
 EOF
@@ -1369,7 +1447,7 @@ EOF
 fi
 fi
 
 
 echo $ac_n "checking type of array argument to getgroups""... $ac_c" 1>&6
 echo $ac_n "checking type of array argument to getgroups""... $ac_c" 1>&6
-echo "configure:1373: checking type of array argument to getgroups" >&5
+echo "configure:1451: checking type of array argument to getgroups" >&5
 if eval "test \"`echo '$''{'ac_cv_type_getgroups'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_type_getgroups'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
@@ -1377,7 +1455,7 @@ else
   ac_cv_type_getgroups=cross
   ac_cv_type_getgroups=cross
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1381 "configure"
+#line 1459 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 
 
 /* Thanks to Mike Rendell for this test.  */
 /* Thanks to Mike Rendell for this test.  */
@@ -1402,7 +1480,7 @@ main()
 }
 }
 
 
 EOF
 EOF
-if { (eval echo configure:1406: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1484: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
 then
     ac_cv_type_getgroups=gid_t
     ac_cv_type_getgroups=gid_t
 else
 else
@@ -1416,7 +1494,7 @@ fi
 
 
 if test $ac_cv_type_getgroups = cross; then
 if test $ac_cv_type_getgroups = cross; then
         cat > conftest.$ac_ext <<EOF
         cat > conftest.$ac_ext <<EOF
-#line 1420 "configure"
+#line 1498 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <unistd.h>
 #include <unistd.h>
 EOF
 EOF
@@ -1441,7 +1519,7 @@ EOF
 
 
 
 
 echo $ac_n "checking for main in -lnsl""... $ac_c" 1>&6
 echo $ac_n "checking for main in -lnsl""... $ac_c" 1>&6
-echo "configure:1445: checking for main in -lnsl" >&5
+echo "configure:1523: checking for main in -lnsl" >&5
 ac_lib_var=`echo nsl'_'main | sed 'y%./+-%__p_%'`
 ac_lib_var=`echo nsl'_'main | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1449,14 +1527,14 @@ else
   ac_save_LIBS="$LIBS"
   ac_save_LIBS="$LIBS"
 LIBS="-lnsl  $LIBS"
 LIBS="-lnsl  $LIBS"
 cat > conftest.$ac_ext <<EOF
 cat > conftest.$ac_ext <<EOF
-#line 1453 "configure"
+#line 1531 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 
 
 int main() {
 int main() {
 main()
 main()
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1460: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1538: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
 else
@@ -1477,7 +1555,7 @@ else
 fi
 fi
 
 
 echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6
 echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6
-echo "configure:1481: checking for socket in -lsocket" >&5
+echo "configure:1559: checking for socket in -lsocket" >&5
 ac_lib_var=`echo socket'_'socket | sed 'y%./+-%__p_%'`
 ac_lib_var=`echo socket'_'socket | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1485,7 +1563,7 @@ else
   ac_save_LIBS="$LIBS"
   ac_save_LIBS="$LIBS"
 LIBS="-lsocket  $LIBS"
 LIBS="-lsocket  $LIBS"
 cat > conftest.$ac_ext <<EOF
 cat > conftest.$ac_ext <<EOF
-#line 1489 "configure"
+#line 1567 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
 /* We use char because int might match the return type of a gcc2
@@ -1496,7 +1574,7 @@ int main() {
 socket()
 socket()
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1500: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1578: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
 else
@@ -1520,12 +1598,12 @@ fi
 for ac_func in strdup strstr strtoul
 for ac_func in strdup strstr strtoul
 do
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:1524: checking for $ac_func" >&5
+echo "configure:1602: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
   echo $ac_n "(cached) $ac_c" 1>&6
 else
 else
   cat > conftest.$ac_ext <<EOF
   cat > conftest.$ac_ext <<EOF
-#line 1529 "configure"
+#line 1607 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
     which can conflict with char $ac_func(); below.  */
@@ -1548,7 +1626,7 @@ $ac_func();
 
 
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1552: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:1630: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
   eval "ac_cv_func_$ac_func=yes"
 else
 else
@@ -1574,19 +1652,19 @@ done
 
 
 
 
 echo $ac_n "checking for type of socket size""... $ac_c" 1>&6
 echo $ac_n "checking for type of socket size""... $ac_c" 1>&6
-echo "configure:1578: checking for type of socket size" >&5
+echo "configure:1656: checking for type of socket size" >&5
 cat > conftest.$ac_ext <<EOF
 cat > conftest.$ac_ext <<EOF
-#line 1580 "configure"
+#line 1658 "configure"
 #include "confdefs.h"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
 
 
 int main() {
 int main() {
-int a = send(1, (const void *) buffer, (size_t *) 0, (int *) 0);
+int a = send(1, (const void *)0, (size_t *) 0, (int *) 0);
 ; return 0; }
 ; return 0; }
 EOF
 EOF
-if { (eval echo configure:1590: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1668: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   rm -rf conftest*
   cat >> confdefs.h <<\EOF
   cat >> confdefs.h <<\EOF
 #define SOCKET_SIZE_TYPE size_t
 #define SOCKET_SIZE_TYPE size_t
@@ -1626,7 +1704,7 @@ EOF
 # Ultrix sh set writes to stderr and can't be redirected directly,
 # Ultrix sh set writes to stderr and can't be redirected directly,
 # and sets the high bit in the cache file unless we assign to the vars.
 # and sets the high bit in the cache file unless we assign to the vars.
 (set) 2>&1 |
 (set) 2>&1 |
-  case `(ac_space=' '; set) 2>&1` in
+  case `(ac_space=' '; set | grep ac_space) 2>&1` in
   *ac_space=\ *)
   *ac_space=\ *)
     # `set' does not quote correctly, so add quotes (double-quote substitution
     # `set' does not quote correctly, so add quotes (double-quote substitution
     # turns \\\\ into \\, and sed turns \\ into \).
     # turns \\\\ into \\, and sed turns \\ into \).
@@ -1693,7 +1771,7 @@ do
     echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
     echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion"
     exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
     exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;;
   -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
   -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
-    echo "$CONFIG_STATUS generated by autoconf version 2.12"
+    echo "$CONFIG_STATUS generated by autoconf version 2.13"
     exit 0 ;;
     exit 0 ;;
   -help | --help | --hel | --he | --h)
   -help | --help | --hel | --he | --h)
     echo "\$ac_cs_usage"; exit 0 ;;
     echo "\$ac_cs_usage"; exit 0 ;;
@@ -1713,9 +1791,11 @@ sed 's/%@/@@/; s/@%/@@/; s/%g\$/@g/; /@g\$/s/[\\\\&%]/\\\\&/g;
  s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
  s/@@/%@/; s/@@/@%/; s/@g\$/%g/' > conftest.subs <<\\CEOF
 $ac_vpsub
 $ac_vpsub
 $extrasub
 $extrasub
+s%@SHELL@%$SHELL%g
 s%@CFLAGS@%$CFLAGS%g
 s%@CFLAGS@%$CFLAGS%g
 s%@CPPFLAGS@%$CPPFLAGS%g
 s%@CPPFLAGS@%$CPPFLAGS%g
 s%@CXXFLAGS@%$CXXFLAGS%g
 s%@CXXFLAGS@%$CXXFLAGS%g
+s%@FFLAGS@%$FFLAGS%g
 s%@DEFS@%$DEFS%g
 s%@DEFS@%$DEFS%g
 s%@LDFLAGS@%$LDFLAGS%g
 s%@LDFLAGS@%$LDFLAGS%g
 s%@LIBS@%$LIBS%g
 s%@LIBS@%$LIBS%g
@@ -1735,6 +1815,7 @@ s%@oldincludedir@%$oldincludedir%g
 s%@infodir@%$infodir%g
 s%@infodir@%$infodir%g
 s%@mandir@%$mandir%g
 s%@mandir@%$mandir%g
 s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
 s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
+s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g
 s%@INSTALL_DATA@%$INSTALL_DATA%g
 s%@INSTALL_DATA@%$INSTALL_DATA%g
 s%@INSTALL@%$INSTALL%g
 s%@INSTALL@%$INSTALL%g
 s%@CC@%$CC%g
 s%@CC@%$CC%g
@@ -1961,6 +2042,10 @@ rm -fr confdefs* $ac_clean_files
 test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
 test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS || exit 1
 
 
 
 
+echo ""
+echo ""
+echo "Type 'make all' to compile the NRPE daemon and client."
+echo ""
 
 
 
 
 
 

+ 5 - 1
configure.in

@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT(src/nrpe.c)
 AC_INIT(src/nrpe.c)
 AC_CONFIG_HEADER(common/config.h)
 AC_CONFIG_HEADER(common/config.h)
-AC_PREFIX_DEFAULT(/usr/local/nnagios)
+AC_PREFIX_DEFAULT(/usr/local/nagios)
 
 
 dnl Figure out how to invoke "install" and what install options to use.
 dnl Figure out how to invoke "install" and what install options to use.
 
 
@@ -44,6 +44,10 @@ AC_TRY_COMPILE([#include <stdlib.h>
 
 
 AC_OUTPUT(Makefile src/Makefile)
 AC_OUTPUT(Makefile src/Makefile)
 
 
+echo ""
+echo ""
+echo "Type 'make all' to compile the NRPE daemon and client."
+echo ""
 
 
 
 
 
 

+ 31 - 0
contrib/README.nrpe_check_control

@@ -0,0 +1,31 @@
+------- Forwarded message follows -------
+Date sent:      	Fri, 30 Mar 2001 18:51:48 -0500
+From:           	adam.bowen@<>
+Subject:        	Event Handler
+To:             	[nagios@nagios.org]
+
+I am attaching the source code for an event handler I wrote to 
+control checks using nrpe.  I add the following check to all remote hosts
+using nrpe:
+
+service[<host Hame>]=NRPE;0;24x7;3;5;1;<contactgroup>;120;24x7;1;1;0;nrpe_check_control;check_tcp!-p 5666
+
+I added this line to the commands.cfg file:
+
+command[nrpe_check_control]=$USER2$/nrpe_check_control $SERVICESTATE$ $STATETYPE$ $SERVICEATTEMPT$ "$HOSTNAME$"
+
+When the NRPE service check listed above has 3 failed connection
+attempts, it will run the nrpe_check_control which will search the
+services file for all services for $HOSTNAME$ that use the check_nrpe.
+
+It will then request that all these services be disabled.  When the
+NRPE check returns to the OK state, it will request that all services
+using check_nrpe be re-enabled. This will prevent unnecessary e-mail
+when there is a problem with the NRPE daemon.  This does require 
+that external commands be enabled.
+
+(See attached file: nrpe_check_control.c)
+
+I thought some other [Nagios] users might find this useful.
+
+Adam G. Bowen

+ 121 - 0
contrib/nrpe_check_control.c

@@ -0,0 +1,121 @@
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+#define MAX_CHARS	1024
+#define SERVICE_COUNT	12
+
+#define COMMAND_FILE	"/usr/local/nagios/var/rw/nagios.cmd"
+#define SERVICES_FILE	"/usr/local/nagios/etc/services.cfg"
+
+int main(int argc, char *argv[])
+{
+  char check_name[MAX_CHARS];
+  char ent_type[MAX_CHARS];
+  char input_buffer[MAX_CHARS];
+  char host_name[MAX_CHARS];
+  char service_name[MAX_CHARS];
+  char state[MAX_CHARS];
+  char state_type[MAX_CHARS];
+  char temp_input[MAX_CHARS];
+  char temp_string[MAX_CHARS];
+  char test_host[MAX_CHARS];
+
+  char *temp_var;
+
+  FILE *command_fp;
+  FILE *services_fp;
+
+  int attempt;
+  int i;
+
+  time_t current_time;
+
+  strcpy(state,argv[1]);
+  strcpy(state_type,argv[2]);
+  attempt=atoi(argv[3]);
+  strcpy(host_name,argv[4]);
+
+  if(strcmp(state,"OK") == 0)
+  {
+    services_fp=fopen(SERVICES_FILE,"r");
+    command_fp=fopen(COMMAND_FILE,"a");
+    while((fgets(input_buffer,MAX_CHARS-1,services_fp)) != NULL)
+    {
+      if(input_buffer[0]=='#' || input_buffer[0]=='\x0' || input_buffer[0]=='\n' || input_buffer[0]=='\r')
+      {
+        continue;
+      }
+      else
+      {
+        strcpy(temp_input,input_buffer);
+        strcpy(temp_string,strtok(temp_input,"="));
+        strcpy(ent_type,strtok(temp_string,"["));
+        if(strcmp(ent_type,"service") == 0)
+        {
+          strcpy(test_host,strtok(NULL,"]"));
+          if(strcmp(test_host,host_name) == 0)
+          {
+            temp_var=strtok(input_buffer,"=");
+            strcpy(service_name,strtok(NULL,";")); 
+            for(i=1;i<=SERVICE_COUNT;i++)
+            {
+              temp_var=strtok(NULL,";");
+            }
+            strcpy(check_name,strtok(temp_var,"!"));
+            if(strcmp(check_name,"check_nrpe") == 0)
+            {
+              time(&current_time);
+              fprintf(command_fp,"[%lu] ENABLE_SVC_CHECK;%s;%s\n",current_time,host_name,service_name);
+            }
+          }
+        }
+      }
+    }
+    fclose(command_fp);
+    fclose(services_fp);
+  }
+  else if(strcmp(state,"CRITICAL") == 0)
+  {
+    if(attempt == 3)
+    {
+      services_fp=fopen(SERVICES_FILE,"r");
+      command_fp=fopen(COMMAND_FILE,"a");
+      while((fgets(input_buffer,MAX_CHARS-1,services_fp)) != NULL)
+      {
+        if(input_buffer[0]=='#' || input_buffer[0]=='\x0' || input_buffer[0]=='\n' || input_buffer[0]=='\r')
+        {
+          continue;
+        }
+        else
+        {
+          strcpy(temp_input,input_buffer);
+          strcpy(temp_string,strtok(temp_input,"="));
+          strcpy(ent_type,strtok(temp_string,"["));
+          if(strcmp(ent_type,"service") == 0)
+          {
+            strcpy(test_host,strtok(NULL,"]"));
+            if(strcmp(test_host,host_name) == 0)
+            {
+              temp_var=strtok(input_buffer,"=");
+              strcpy(service_name,strtok(NULL,";")); 
+              for(i=1;i<=SERVICE_COUNT;i++)
+              {
+                temp_var=strtok(NULL,";");
+              }
+              strcpy(check_name,strtok(temp_var,"!"));
+              if(strcmp(check_name,"check_nrpe") == 0)
+              {
+                time(&current_time);
+                fprintf(command_fp,"[%lu] DISABLE_SVC_CHECK;%s;%s\n",current_time,host_name,service_name);
+              }
+            }
+          }
+        }
+      }
+      fclose(command_fp);
+      fclose(services_fp);
+    }
+  }
+  return 0;
+}

+ 63 - 0
init-script

@@ -0,0 +1,63 @@
+#!/bin/sh
+#
+#  Created 2000-01-03 by jaclu@grm.se
+#
+# nrpe          This shell script takes care of starting and stopping
+#               nrpe.
+#
+# chkconfig: 2345 80 30
+# description: nrpe is a daemon for a remote nagios server, \
+#              running nagios plugins on this host.
+# processname: nrpe
+# config: /usr/local/nagios/etc/nrpe.cfg
+
+
+# Source function library
+if [ -f /etc/rc.d/init.d/functions ]; then
+. /etc/rc.d/init.d/functions
+elif [ -f /etc/init.d/functions ]; then
+. /etc/init.d/functions
+elif [ -f /etc/rc.d/functions ]; then
+. /etc/rc.d/functions
+fi
+
+# Source networking configuration.
+. /etc/sysconfig/network
+
+# Check that networking is up.
+[ ${NETWORKING} = "no" ] && exit 0
+
+prefix=/usr/local/nagios
+exec_prefix=${prefix}
+NrpeBin=${exec_prefix}/bin/nrpe
+NrpeCfg=${prefix}/etc/nrpe.cfg
+
+# See how we were called.
+case "$1" in
+  start)
+	# Start daemons.
+	echo -n "Starting nrpe: "
+	daemon $NrpeBin -d $NrpeCfg
+	echo
+	touch /var/lock/subsys/nrpe
+	;;
+  stop)
+	# Stop daemons.
+	echo -n "Shutting down nrpe: "
+	killproc nrpe
+	echo
+	rm -f /var/lock/subsys/nrpe
+	;;
+  restart)
+	$0 stop
+	$0 start
+	;;
+  status)
+	status nrpe
+	;;
+  *)
+	echo "Usage: nrpe {start|stop|restart|status}"
+	exit 1
+esac
+
+exit 0

+ 1 - 1
nrpe.cfg

@@ -2,7 +2,7 @@
 # Sample NRPE Config File 
 # Sample NRPE Config File 
 # Written by: Ethan Galstad (nagios@nagios.org)
 # Written by: Ethan Galstad (nagios@nagios.org)
 # 
 # 
-# Last Modified: 06/23/2001
+# Last Modified: 02-21-2002
 ####################################################
 ####################################################
 
 
 
 

+ 5 - 6
src/Makefile.in

@@ -1,7 +1,7 @@
 ###############################
 ###############################
 # Makefile for NRPE
 # Makefile for NRPE
 #
 #
-# Last Modified: 06/23/2001
+# Last Modified: 12-23-2001
 ###############################
 ###############################
 
 
 
 
@@ -25,11 +25,10 @@ check_nrpe: check_nrpe.c netutils.c netutils.h $(SRC_COMMON)/common.h $(SRC_COMM
 	$(CC) $(CFLAGS) $(LDFLAGS) $(SOCKETLIBS) check_nrpe.c netutils.c -o $@
 	$(CC) $(CFLAGS) $(LDFLAGS) $(SOCKETLIBS) check_nrpe.c netutils.c -o $@
 
 
 clean:
 clean:
-	rm -f core \
-	nrpe check_nrpe
+	rm -f core nrpe check_nrpe
+	rm -f *~ */*~
+	rm -f Makefile
 
 
 distclean: clean
 distclean: clean
-	rm -f Makefile
 
 
-devclean: distclean
-	rm -f *~ */*~
+devclean: clean

+ 22 - 60
src/check_nrpe.c

@@ -4,10 +4,9 @@
  *
  *
  * Program: NRPE plugin for Nagios
  * Program: NRPE plugin for Nagios
  * License: GPL
  * License: GPL
- * Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)
+ * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
  *
  *
- * Version: 1.3
- * Last Modified: 06-23-2001
+ * Last Modified: 02-21-2002
  *
  *
  * Command line: CHECK_NRPE <host_address> [-p port] [-c command] [-wt warn_time] \
  * Command line: CHECK_NRPE <host_address> [-p port] [-c command] [-wt warn_time] \
  *                          [-ct crit_time] [-to to_sec]
  *                          [-ct crit_time] [-to to_sec]
@@ -25,24 +24,14 @@
 #include "../common/config.h"
 #include "../common/config.h"
 #include "netutils.h"
 #include "netutils.h"
 
 
-
-#define PROGRAM_VERSION "1.3"
-#define MODIFICATION_DATE "06-23-2001"
-
 #define DEFAULT_NRPE_COMMAND	"_NRPE_CHECK"  /* check version of NRPE daemon */
 #define DEFAULT_NRPE_COMMAND	"_NRPE_CHECK"  /* check version of NRPE daemon */
 
 
-time_t start_time,end_time;
-
 int server_port=DEFAULT_SERVER_PORT;
 int server_port=DEFAULT_SERVER_PORT;
 char server_name[MAX_HOST_ADDRESS_LENGTH];
 char server_name[MAX_HOST_ADDRESS_LENGTH];
 
 
 char query_string[MAX_PACKETBUFFER_LENGTH]=DEFAULT_NRPE_COMMAND;;
 char query_string[MAX_PACKETBUFFER_LENGTH]=DEFAULT_NRPE_COMMAND;;
 int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
 int socket_timeout=DEFAULT_SOCKET_TIMEOUT;
 
 
-int warning_time=0;
-int check_warning_time=FALSE;
-int critical_time=0;
-int check_critical_time=FALSE;
 
 
 
 
 int process_arguments(int,char **);
 int process_arguments(int,char **);
@@ -57,6 +46,8 @@ int main(int argc, char **argv){
 	int result;
 	int result;
 	packet send_packet;
 	packet send_packet;
 	packet receive_packet;
 	packet receive_packet;
+	int bytes_to_send;
+	int bytes_to_recv;
 
 
 	result=process_arguments(argc,argv);
 	result=process_arguments(argc,argv);
 
 
@@ -65,7 +56,7 @@ int main(int argc, char **argv){
 		printf("Incorrect command line arguments supplied\n");
 		printf("Incorrect command line arguments supplied\n");
 		printf("\n");
 		printf("\n");
 		printf("NRPE Plugin for Nagios\n");
 		printf("NRPE Plugin for Nagios\n");
-		printf("Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)\n");
+		printf("Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)\n");
 		printf("Version: %s\n",PROGRAM_VERSION);
 		printf("Version: %s\n",PROGRAM_VERSION);
 		printf("Last Modified: %s\n",MODIFICATION_DATE);
 		printf("Last Modified: %s\n",MODIFICATION_DATE);
 		printf("License: GPL\n");
 		printf("License: GPL\n");
@@ -77,10 +68,6 @@ int main(int argc, char **argv){
 		printf(" <host_address> = The IP address of the host running the NRPE daemon\n");
 		printf(" <host_address> = The IP address of the host running the NRPE daemon\n");
 		printf(" [port]         = The port on which the daemon is running - default is %d\n",DEFAULT_SERVER_PORT);
 		printf(" [port]         = The port on which the daemon is running - default is %d\n",DEFAULT_SERVER_PORT);
 		printf(" [command]      = The name of the command that the remote daemon should run\n");
 		printf(" [command]      = The name of the command that the remote daemon should run\n");
-		printf(" [warn_time]    = Response time in seconds necessary to result in a warning\n");
-		printf("                  status\n");
-		printf(" [crit_time]    = Response time in seconds necessary to result in a critical\n");
-		printf("                  status\n");
 		printf(" [to_sec]       = Number of seconds before connection attempt times out.\n");
 		printf(" [to_sec]       = Number of seconds before connection attempt times out.\n");
 		printf("                  Default timeout is %d seconds\n",DEFAULT_SOCKET_TIMEOUT);
 		printf("                  Default timeout is %d seconds\n",DEFAULT_SOCKET_TIMEOUT);
 		printf("\n");
 		printf("\n");
@@ -103,8 +90,6 @@ int main(int argc, char **argv){
 	/* set socket timeout */
 	/* set socket timeout */
 	alarm(socket_timeout);
 	alarm(socket_timeout);
 
 
-	time(&start_time);
-
 	/* try to connect to the host at the given port number */
 	/* try to connect to the host at the given port number */
 	result=my_tcp_connect(server_name,server_port,&sd);
 	result=my_tcp_connect(server_name,server_port,&sd);
 
 
@@ -118,48 +103,43 @@ int main(int argc, char **argv){
 		send_packet.buffer_length=htonl(strlen(query_string));
 		send_packet.buffer_length=htonl(strlen(query_string));
 		strcpy(&send_packet.buffer[0],query_string);
 		strcpy(&send_packet.buffer[0],query_string);
 
 
-		rc=send(sd,(void *)&send_packet,sizeof(send_packet),0);
+		bytes_to_send=sizeof(send_packet);
+		rc=sendall(sd,(char *)&send_packet,&bytes_to_send);
 
 
 		if(rc==-1){
 		if(rc==-1){
-			printf("CHECK_NRPE: Error sending query to host\n");
+			printf("CHECK_NRPE: Error sending query to host.\n");
 			close(sd);
 			close(sd);
 			return STATE_UNKNOWN;
 			return STATE_UNKNOWN;
 		        }
 		        }
 
 
 		/* wait for the response packet */
 		/* wait for the response packet */
-		bzero(&receive_packet,sizeof(receive_packet));
-		rc=recv(sd,(void *)&receive_packet,sizeof(receive_packet),0);
+		bytes_to_recv=sizeof(receive_packet);
+		rc=recvall(sd,(char *)&receive_packet,&bytes_to_recv,socket_timeout);
 
 
-		if(rc==-1){
-			printf("CHECK_NRPE: Error receiving data from host\n");
+		/* recv() error */
+		if(rc<0){
+			printf("CHECK_NRPE: Error receiving data from host.\n");
 			close(sd);
 			close(sd);
+			alarm(0);
 			return STATE_UNKNOWN;
 			return STATE_UNKNOWN;
 		        }
 		        }
 
 
+		/* server disconnected */
 		else if(rc==0){
 		else if(rc==0){
-			printf("CHECK_NRPE: Received 0 bytes. Is this host authorized to connect with nrpe daemon?\n");
+			printf("CHECK_NRPE: Received 0 bytes.  Are we allowed to connect to the host?\n");
 			close(sd);
 			close(sd);
+			alarm(0);
 			return STATE_UNKNOWN;
 			return STATE_UNKNOWN;
 		        }
 		        }
 
 
-		else if(rc<sizeof(receive_packet)){
-			printf("CHECK_NRPE: Receive underflow.  Only %d bytes received (%d expected).\n",rc,sizeof(receive_packet));
+		/* receive underflow */
+		else if(bytes_to_recv<sizeof(receive_packet)){
+			printf("CHECK_NRPE: Receive underflow - only %d bytes received (%d expected).\n",bytes_to_recv,sizeof(receive_packet));
 			close(sd);
 			close(sd);
+			alarm(0);
 			return STATE_UNKNOWN;
 			return STATE_UNKNOWN;
 		        }
 		        }
 
 
-		time(&end_time);
-
-		result=STATE_OK;
-
-		if(check_critical_time==TRUE && (end_time-start_time)>critical_time)
-			result=STATE_CRITICAL;
-		else if(check_warning_time==TRUE && (end_time-start_time)>warning_time)
-			result=STATE_WARNING;
-
-		if(result!=STATE_OK)
-			printf("CHECK_NRPE problem - %d second response time: ",(int)(end_time-start_time));
-
 		/* get the return code from the remote plugin */
 		/* get the return code from the remote plugin */
 		result=ntohl(receive_packet.result_code);
 		result=ntohl(receive_packet.result_code);
 
 
@@ -224,24 +204,6 @@ int process_arguments(int argc, char **argv){
 			else
 			else
 				return ERROR;
 				return ERROR;
 		        }
 		        }
-		else if(!strcmp(argv[x-1],"-wt")){
-			if(x<argc){
-				warning_time=atoi(argv[x]);
-				check_warning_time=TRUE;
-				x++;
-			        }
-			else
-				return ERROR;
-		        }
-		else if(!strcmp(argv[x-1],"-ct")){
-			if(x<argc){
-				critical_time=atoi(argv[x]);
-				check_critical_time=TRUE;
-				x++;
-			        }
-			else
-				return ERROR;
-		        }
 		else
 		else
 			return ERROR;
 			return ERROR;
 	        }
 	        }
@@ -253,7 +215,7 @@ int process_arguments(int argc, char **argv){
 
 
 void alarm_handler(int sig){
 void alarm_handler(int sig){
 
 
-	printf("CHECK_NRPE: Socket timeout after %d seconds\n",socket_timeout);
+	printf("CHECK_NRPE: Socket timeout after %d seconds.\n",socket_timeout);
 
 
 	exit(STATE_CRITICAL);
 	exit(STATE_CRITICAL);
         }
         }

+ 78 - 101
src/netutils.c

@@ -1,9 +1,11 @@
 /****************************************************************************
 /****************************************************************************
  *
  *
  * NETUTILS.C - NRPE Network Utilities
  * NETUTILS.C - NRPE Network Utilities
- * Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)
+ *
  * License: GPL
  * License: GPL
- * Last Modified: 06-23-2001
+ * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
+ *
+ * Last Modified: 02-21-2002
  *
  *
  * Description:
  * Description:
  *
  *
@@ -30,95 +32,6 @@
 #include "../common/common.h"
 #include "../common/common.h"
 #include "netutils.h"
 #include "netutils.h"
 
 
-extern int socket_timeout;    /* this doesn't have to be used, but it is nice to know how many seconds we timed out after */
-
-extern int errno;
-
-
-/* handles socket timeouts */
-void socket_timeout_alarm_handler(int sig){
-
-	printf("Socket timeout after %d seconds\n",socket_timeout);
-
-	exit(STATE_CRITICAL);
-        }
-
-
-/* connects to a host on a specified TCP port, sends a string, and gets a response */
-int process_tcp_request(char *server_address, int server_port, char *send_buffer, char *recv_buffer, int recv_size){
-	int result;
-
-	result=process_request(server_address,server_port,"tcp",send_buffer,recv_buffer,recv_size);
-
-	return result;
-        }
-
-
-/* connects to a host on a specified UDP port, sends a string, and gets a response */
-int process_udp_request(char *server_address, int server_port, char *send_buffer, char *recv_buffer, int recv_size){
-	int result;
-
-	result=process_request(server_address,server_port,"udp",send_buffer,recv_buffer,recv_size);
-
-	return result;
-        }
-
-
-/* connects to a host on a specified port, sends a string, and gets a response */
-int process_request(char *server_address, int server_port, char *proto, char *send_buffer, char *recv_buffer, int recv_size){
-	int result;
-	int send_result;
-	int recv_result;
-	int sd;
-	struct timeval tv;
-	fd_set readfds;
-
-	result=STATE_OK;
-
-	result=my_connect(server_address,server_port,&sd,proto);
-	if(result!=STATE_OK)
-		return STATE_CRITICAL;
-
-	send_result=send(sd,send_buffer,strlen(send_buffer),0);
-	if(send_result!=strlen(send_buffer)){
-		printf("send() failed\n");
-		result=STATE_WARNING;
-	        }
-
-	/* wait up to the number of seconds for socket timeout minus one for data from the host */
-	tv.tv_sec=socket_timeout-1;
-	tv.tv_usec=0;
-	FD_ZERO(&readfds);
-	FD_SET(sd,&readfds);
-	select(sd+1,&readfds,NULL,NULL,&tv);
-
-	/* make sure some data has arrived */
-	if(!FD_ISSET(sd,&readfds)){
-		strcpy(recv_buffer,"");
-		printf("No data was recieved from host!\n");
-		result=STATE_WARNING;
-	        }
-
-	else{
-		recv_result=recv(sd,recv_buffer,recv_size-1,0);
-		if(recv_result==-1){
-			strcpy(recv_buffer,"");
-			if(!strcmp(proto,"tcp"))
-				printf("recv() failed\n");
-			result=STATE_WARNING;
-	                }
-		else
-			recv_buffer[recv_result]='\x0';
-
-		/* terminate returned string */
-		recv_buffer[recv_size-1]='\x0';
-	        }
-
-	close(sd);
-
-	return result;
-        }
-
 
 
 /* opens a connection to a remote host/tcp port */
 /* opens a connection to a remote host/tcp port */
 int my_tcp_connect(char *host_name,int port,int *sd){
 int my_tcp_connect(char *host_name,int port,int *sd){
@@ -130,16 +43,6 @@ int my_tcp_connect(char *host_name,int port,int *sd){
         }
         }
 
 
 
 
-/* opens a connection to a remote host/udp port */
-int my_udp_connect(char *host_name,int port,int *sd){
-	int result;
-
-	result=my_connect(host_name,port,sd,"udp");
-
-	return result;
-        }
-
-
 /* opens a tcp or udp connection to a remote host */
 /* opens a tcp or udp connection to a remote host */
 int my_connect(char *host_name,int port,int *sd,char *proto){
 int my_connect(char *host_name,int port,int *sd,char *proto){
 	struct sockaddr_in servaddr;
 	struct sockaddr_in servaddr;
@@ -317,3 +220,77 @@ void strip(char *buffer){
 
 
 	return;
 	return;
         }
         }
+
+
+/* sends all data - thanks to Beej's Guide to Network Programming */
+int sendall(int s, char *buf, int *len){
+	int total=0;
+	int bytesleft=*len;
+	int n;
+
+	/* send all the data */
+	while(total<*len){
+
+		/* send some data */
+		n=send(s,buf+total,bytesleft,0);
+
+		/* break on error */
+		if(n==-1)
+			break;
+
+		/* apply bytes we sent */
+		total+=n;
+		bytesleft-=n;
+	        }
+
+	/* return number of bytes actually send here */
+	*len=total;
+
+	/* return -1 on failure, 0 on success */
+	return n==-1?-1:0;
+        }
+
+
+/* receives all data - modelled after sendall() */
+int recvall(int s, char *buf, int *len, int timeout){
+	int total=0;
+	int bytesleft=*len;
+	int n;
+	time_t start_time;
+	time_t current_time;
+	
+	/* clear the receive buffer */
+	bzero(buf,*len);
+
+	time(&start_time);
+
+	/* receive all data */
+	while(total<*len){
+
+		/* receive some data */
+		n=recv(s,buf+total,bytesleft,0);
+
+		/* no data has arrived yet (non-blocking socket) */
+		if(n==-1 && errno==EAGAIN){
+			time(&current_time);
+			if(current_time-start_time>timeout)
+				break;
+			sleep(1);
+			continue;
+		        }
+
+		/* receive error or client disconnect */
+		else if(n<=0)
+			break;
+
+		/* apply bytes we received */
+		total+=n;
+		bytesleft-=n;
+	        }
+
+	/* return number of bytes actually received here */
+	*len=total;
+
+	/* return <=0 on failure, bytes received on success */
+	return (n<=0)?n:total;
+        }

+ 12 - 13
src/netutils.h

@@ -1,8 +1,11 @@
 /************************************************************************************************
 /************************************************************************************************
  *
  *
- * NETUTILS.H - NRPE Network Function Header File
- * Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)
- * Last Modified: 06-23-2001
+ * NETUTILS.H - NRPE Network Utilities Include File
+ *
+ * License: GPL
+ * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
+ *
+ * Last Modified: 02-21-2002
  *
  *
  * Description:
  * Description:
  *
  *
@@ -28,20 +31,16 @@
 
 
 #include "../common/config.h"
 #include "../common/config.h"
 
 
-void socket_timeout_alarm_handler(int);
-
-int process_tcp_request(char *address,int port,char *sbuffer,char *rbuffer,int rsize);
-int process_udp_request(char *address,int port,char *sbuffer,char *rbuffer,int rsize);
-int process_request(char *address,int port,char *proto,char *sbuffer,char *rbuffer,int rsize);
+int my_tcp_connect(char *,int,int *);
+int my_connect(char *,int,int *,char *);
 
 
-int my_tcp_connect(char *address,int port,int *sd);
-int my_udp_connect(char *address,int port,int *sd);
-int my_connect(char *address,int port,int *sd,char *proto);
-
-int my_inet_aton(register const char *cp, struct in_addr *addr);
+int my_inet_aton(register const char *,struct in_addr *);
 
 
 void strip(char *);
 void strip(char *);
 
 
+int sendall(int,char *,int *);
+int recvall(int,char *,int *,int);
+
 
 
 
 
 
 

+ 44 - 57
src/nrpe.c

@@ -1,11 +1,10 @@
 /*******************************************************************************
 /*******************************************************************************
  *
  *
  * NRPE.C - Nagios Remote Plugin Executor
  * NRPE.C - Nagios Remote Plugin Executor
- * Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)
- * Version: 1.3
+ * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
  * License: GPL
  * License: GPL
  *
  *
- * Last Modified: 06-23-2001
+ * Last Modified: 02-21-2002
  *
  *
  * Command line: nrpe [-i | -d] <config_file>
  * Command line: nrpe [-i | -d] <config_file>
  *
  *
@@ -32,10 +31,8 @@
 #include "netutils.h"
 #include "netutils.h"
 
 
 
 
-#define PROGRAM_VERSION "1.3"
-#define MODIFICATION_DATE "06-23-2001"
-
 #define COMMAND_TIMEOUT		60			/* timeout for execution of plugins */
 #define COMMAND_TIMEOUT		60			/* timeout for execution of plugins */
+#define MAXFD                   64
 
 
 char allowed_hosts[MAX_INPUT_BUFFER];
 char allowed_hosts[MAX_INPUT_BUFFER];
 int server_port=DEFAULT_SERVER_PORT;
 int server_port=DEFAULT_SERVER_PORT;
@@ -63,6 +60,7 @@ int debug=FALSE;
 int main(int argc, char **argv){
 int main(int argc, char **argv){
 	int error=FALSE;
 	int error=FALSE;
 	int result;
 	int result;
+	int i;
 	char config_file[MAX_INPUT_BUFFER];
 	char config_file[MAX_INPUT_BUFFER];
 	char buffer[MAX_INPUT_BUFFER];
 	char buffer[MAX_INPUT_BUFFER];
 
 
@@ -82,7 +80,7 @@ int main(int argc, char **argv){
 
 
 		printf("\n");
 		printf("\n");
 		printf("NRPE - Nagios Remote Plugin Executor\n");
 		printf("NRPE - Nagios Remote Plugin Executor\n");
-		printf("Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)\n");
+		printf("Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)\n");
 		printf("Version: %s\n",PROGRAM_VERSION);
 		printf("Version: %s\n",PROGRAM_VERSION);
 		printf("Last Modified: %s\n",MODIFICATION_DATE);
 		printf("Last Modified: %s\n",MODIFICATION_DATE);
 		printf("License: GPL\n");
 		printf("License: GPL\n");
@@ -90,8 +88,8 @@ int main(int argc, char **argv){
 		printf("Usage: %s <-i | -d> <config_file>\n",argv[0]);
 		printf("Usage: %s <-i | -d> <config_file>\n",argv[0]);
 		printf("\n");
 		printf("\n");
 		printf("Options:\n");
 		printf("Options:\n");
-		printf("  -i      Run as a service under inetd\n");
-		printf("  -d      Run as a standalone daemon without inetd\n");
+		printf("  -i      Run as a service under inetd or xinetd\n");
+		printf("  -d      Run as a standalone daemon\n");
 		printf("\n");
 		printf("\n");
 		printf("Notes:\n");
 		printf("Notes:\n");
 		printf("This program is designed to process requests from the check_nrpe\n");
 		printf("This program is designed to process requests from the check_nrpe\n");
@@ -149,6 +147,26 @@ int main(int argc, char **argv){
 	/* else daemonize and start listening for requests... */
 	/* else daemonize and start listening for requests... */
 	else if(fork()==0){
 	else if(fork()==0){
 
 
+		/* We are in the 1st child, become session leader */
+		setsid();
+
+		/* ignore SIGHUP */
+		signal(SIGHUP, SIG_IGN);
+
+		/* fork again, 1st child exits */
+		if(fork()!=0)
+			exit(0);
+
+		/* grandchild process continues... */
+	  
+		chdir("/");
+		umask(0);
+
+		/*
+		for(i=0;i<MAXFD;i++)
+			close(i);
+		*/
+
 		/* wait for connections */
 		/* wait for connections */
 		wait_for_connections();
 		wait_for_connections();
 	        }
 	        }
@@ -476,12 +494,12 @@ void handle_connection(int sock){
 	command *temp_command;
 	command *temp_command;
 	packet receive_packet;
 	packet receive_packet;
 	packet send_packet;
 	packet send_packet;
+	int bytes_to_send;
+	int bytes_to_recv;
 	char buffer[MAX_INPUT_BUFFER];
 	char buffer[MAX_INPUT_BUFFER];
 	int result=STATE_OK;
 	int result=STATE_OK;
 	int early_timeout=FALSE;
 	int early_timeout=FALSE;
 	int rc;
 	int rc;
-	time_t current_time;
-	time_t start_time;
 
 
 
 
 	/* log info to syslog facility */
 	/* log info to syslog facility */
@@ -491,53 +509,25 @@ void handle_connection(int sock){
 	/* socket should be non-blocking */
 	/* socket should be non-blocking */
 	fcntl(sock,F_SETFL,O_NONBLOCK);
 	fcntl(sock,F_SETFL,O_NONBLOCK);
 
 
-	/* clear the request packet buffer */
-	bzero(&receive_packet,sizeof(receive_packet));
-
-	/* get the current time */
-	time(&start_time);
-
-	/* wait for the data from the client */
-	while(1){
-
-		/* read the packet */
-		rc=recv(sock,(void *)&receive_packet,sizeof(receive_packet),0);
-
-		/* we haven't received data, hang around for a bit more */
-		if(rc==-1 && errno==EAGAIN){
-			time(&current_time);
-			if(current_time-start_time>DEFAULT_SOCKET_TIMEOUT){
-				return;
-			        }
-			sleep(1);
-			continue;
-		        }
-
-		/* the client connection was closed */
-		else if(rc==0)
-			return;
-
-		/* there was an error receiving data... */
-		else if(rc==-1){
+	bytes_to_recv=sizeof(receive_packet);
+	rc=recvall(sock,(char *)&receive_packet,&bytes_to_recv,socket_timeout);
 
 
-			/* log error to syslog facility */
-			syslog(LOG_ERR,"Could not read request from client, bailing out...");
+	/* recv() error or client disconnect */
+	if(rc<=0){
 
 
-			return;
-	                }
+		/* log error to syslog facility */
+		syslog(LOG_ERR,"Could not read request from client, bailing out...");
 
 
-		/* we couldn't read the correct amount of data, so bail out */
-		else if(rc!=sizeof(receive_packet)){
+		return;
+                }
 
 
-			/* log error to syslog facility */
-			syslog(LOG_ERR,"Data packet from client was too short, bailing out...");
+	/* we couldn't read the correct amount of data, so bail out */
+	else if(bytes_to_recv!=sizeof(receive_packet)){
 
 
-			return;
-		        }
+		/* log error to syslog facility */
+		syslog(LOG_ERR,"Data packet from client was too short, bailing out...");
 
 
-		/* the packet looks good so far... */
-		else
-			break;
+		return;
 	        }
 	        }
 
 
 	/* make sure this is the right type of packet */
 	/* make sure this is the right type of packet */
@@ -626,7 +616,8 @@ void handle_connection(int sock){
 	send_packet.buffer[sizeof(send_packet.buffer)-1]='\x0';
 	send_packet.buffer[sizeof(send_packet.buffer)-1]='\x0';
 	
 	
 	/* send the response back to the client */
 	/* send the response back to the client */
-	send(sock,(void *)&send_packet,sizeof(send_packet),0);
+	bytes_to_send=sizeof(send_packet);
+	sendall(sock,(char *)&send_packet,&bytes_to_send);
 
 
 	/* log info to syslog facility */
 	/* log info to syslog facility */
 	if(debug==TRUE)
 	if(debug==TRUE)
@@ -857,7 +848,3 @@ void my_system_sighandler(int sig){
 	exit(STATE_CRITICAL);
 	exit(STATE_CRITICAL);
         }
         }
 
 
-
-
-
-

+ 2 - 2
src/nrpe.h

@@ -1,8 +1,8 @@
 /************************************************************************
 /************************************************************************
  *
  *
  * NRPE.H - NRPE Include File
  * NRPE.H - NRPE Include File
- * Copyright (c) 1999-2001 Ethan Galstad (nagios@nagios.org)
- * Last Modified: 06-23-2001
+ * Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)
+ * Last Modified: 02-21-2002
  *
  *
  * License:
  * License:
  *
  *