--- squid	2009-01-20 23:19:05.000000000 -0500
+++ squid_auth	2010-03-18 06:55:03.000000000 -0400
@@ -21,40 +21,39 @@
 # Source networking configuration.
 . /etc/sysconfig/network
 
+# Source networking configuration.
+prog=`basename $0`
+. /etc/sysconfig/$prog
+
 # don't raise an error if the config file is incomplete
 # set defaults instead:
-SQUID_OPTS=${SQUID_OPTS:-"-D"}
+SQUID_CONF_DIR=${SQUID_CONF_DIR:-"/etc/squid/squid.conf"}
+SQUID_OPTS="$SQUID_OPTS -f $SQUID_CONF_DIR"
 SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
 SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
+SQUID_LOG_OUT=${SQUID_LOG_OUT:-"/var/log/squid/squid.out"}
 
 # determine the name of the squid binary
-[ -f /usr/sbin/squid ] && SQUID=squid
-
-prog="$SQUID"
+[ -f /usr/sbin/squid ] && SQUID=/usr/sbin/squid
 
+LOCK_FILE=${LOCK_FILE:-"/var/lock/subsys/${SQUID}"}
 # determine which one is the cache_swap directory
-CACHE_SWAP=`sed -e 's/#.*//g' /etc/squid/squid.conf | \
-	grep cache_dir |  awk '{ print $3 }'`
+CACHE_SWAP=`awk '/^[\t ]*cache_dir/{print $3}' $SQUID_CONF_DIR`
 [ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/spool/squid
-
+# determine which one is the pid file
+SQUID_PIDFILE=`awk '/^[\t ]*pid_filename/{print $2}' $SQUID_CONF_DIR`
+[ -z "$SQUID_PIDFILE" ] && SQUID_PIDFILE=/var/run/squid.pid
 RETVAL=0
 
 start() {
-
         #check if the squid conf file is present
-        if [ ! -f /etc/squid/squid.conf ]; then
-            echo "Configuration file /etc/squid/squid.conf missing" 1>&2
+        if [ ! -f $SQUID_CONF_DIR ]; then
+            echo "Configuration file $SQUID_CONF_DIR missing" 1>&2
             exit 6
         fi
-        . /etc/sysconfig/squid
 
-        # don't raise an error if the config file is incomplete.
-        # set defaults instead:
-        SQUID_OPTS=${SQUID_OPTS:-"-D"}
-        SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
-        SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
-
-        if [ -z "$SQUID" ]; then
+	#check if the squid binary is executable
+        if [ ! -x "$SQUID" ]; then
                 echo "Insufficient privilege" 1>&2
                 exit 4
         fi
@@ -62,16 +61,16 @@
         for adir in $CACHE_SWAP; do
         if [ ! -d $adir/00 ]; then
 	     echo -n "init_cache_dir $adir... "
-	     $SQUID -z -F -D >> /var/log/squid/squid.out 2>&1
+	     $SQUID -z -F $SQUID_OPTS >> $SQUID_LOG_OUT 2>&1
 	fi
     done
     echo -n $"Starting $prog: "
-    $SQUID $SQUID_OPTS >> /var/log/squid/squid.out 2>&1
+    $SQUID $SQUID_OPTS >> $SQUID_LOG_OUT 2>&1
     RETVAL=$?
     if [ $RETVAL -eq 0 ]; then
        timeout=0;
        while : ; do
-          [ ! -f /var/run/squid.pid ] || break
+          [ ! -f $SQUID_PIDFILE ] || break
 	  if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then
 	     RETVAL=1
 	     break
@@ -80,7 +79,7 @@
 	  timeout=$((timeout+1))
        done
     fi
-    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
+    [ $RETVAL -eq 0 ] && touch $LOCK_FILE
     [ $RETVAL -eq 0 ] && echo_success
     [ $RETVAL -ne 0 ] && echo_failure
     echo
@@ -88,21 +87,15 @@
 }
 
 stop() {
-    . /etc/sysconfig/squid
-
-    # don't raise an error if the config file is incomplete.
-    # set defaults instead:
-    SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
-
     echo -n  $"Stopping $prog: "
-    $SQUID -k check >> /var/log/squid/squid.out 2>&1
+    $SQUID -k check >> $SQUID_LOG_OUT 2>&1
     RETVAL=$?
     if [ $RETVAL -eq 0 ] ; then
-        $SQUID -k shutdown &
-    	rm -f /var/lock/subsys/$SQUID
+        $SQUID $SQUID_OPTS -k shutdown &
+    	rm -f $LOCK_FILE
 	timeout=0
  	while : ; do
-		[ -f /var/run/squid.pid ] || break
+		[ -f $SQUID_PIDFILE ] || break
 		if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
 		    echo
 		    return 1
@@ -120,11 +113,6 @@
 }
 
 reload() {
-    . /etc/sysconfig/squid
-    # don't raise an error if the config file is incomplete.
-    # set defaults instead:
-    SQUID_OPTS=${SQUID_OPTS:-"-D"}
-
     $SQUID $SQUID_OPTS -k reconfigure
 }
 
@@ -134,11 +122,11 @@
 }
 
 condrestart() {
-    [ -e /var/lock/subsys/squid ] && restart || :
+    [ -e $LOCK_FILE ] && restart || :
 }
 
 rhstatus() {
-    status $SQUID && $SQUID -k check
+    status $SQUID && $SQUID $SQUID_OPTS -k check
 }
 
 probe() {
