From 69c78676ad178cd32d87e482b742c36e28c68bd9 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Fri, 5 Jun 2009 13:49:23 -0700 Subject: [PATCH] Redirect STDERR to log --- Shorewall-lite/init.debian.sh | 4 ++++ Shorewall-lite/init.sh | 2 ++ Shorewall/Perl/prog.footer | 18 ++++++++++++++++++ Shorewall/Perl/prog.footer6 | 15 +++++++++++++++ Shorewall/init.debian.sh | 10 +++++++--- Shorewall/init.sh | 2 ++ Shorewall/install.sh | 4 +--- Shorewall6-lite/init.debian.sh | 4 ++++ Shorewall6-lite/init.sh | 2 ++ Shorewall6/init.debian.sh | 4 ++++ Shorewall6/init.sh | 2 ++ 11 files changed, 61 insertions(+), 6 deletions(-) diff --git a/Shorewall-lite/init.debian.sh b/Shorewall-lite/init.debian.sh index a6b5fbc36..72b3df9bc 100755 --- a/Shorewall-lite/init.debian.sh +++ b/Shorewall-lite/init.debian.sh @@ -19,6 +19,10 @@ SRWL_OPTS="-tvv" # keep logs of the firewall (not recommended) INITLOG=/var/log/shorewall-lite-init.log +[ "$INITLOG" eq "/dev/null" && SHOREWALL_INIT_SCRIPT=1 || SHOREWALL_INIT_SCRIPT=0 + +export SHOREWALL_INIT_SCRIPT + test -x $SRWL || exit 0 test -x $WAIT_FOR_IFUP || exit 0 test -n $INITLOG || { diff --git a/Shorewall-lite/init.sh b/Shorewall-lite/init.sh index 60e53e5b7..4d1f91740 100755 --- a/Shorewall-lite/init.sh +++ b/Shorewall-lite/init.sh @@ -67,6 +67,8 @@ elif [ -f /etc/default/shorewall ] ; then . /etc/default/shorewall fi +SHOREWALL_INIT_SCRIPT=1 + ################################################################################ # E X E C U T I O N B E G I N S H E R E # ################################################################################ diff --git a/Shorewall/Perl/prog.footer b/Shorewall/Perl/prog.footer index 57006c929..4ea85e70e 100644 --- a/Shorewall/Perl/prog.footer +++ b/Shorewall/Perl/prog.footer @@ -14,10 +14,13 @@ usage() { # # Start trace if first arg is "debug" or "trace" # +tracing= + if [ $# -gt 1 ]; then if [ "x$1" = "xtrace" ]; then set -x shift + tracing=1 elif [ "x$1" = "xdebug" ]; then DEBUG=Yes shift @@ -26,6 +29,21 @@ fi initialize +if [ -n "$STARTUP_LOG" ]; then + if [ -a ${SHOREWALL_INIT_SCRIPT:-0} -eq 1 ]; then + # + # We're being run by a startup script that isn't redirecting STDOUT + # Redirect it to the log + # + exec 2> $STARTUP_LOG + elif [ -z "${SHOREWALL_INIT_SCRIPT}${DEBUG}${tracing}" ]; then + # + # We're not tracing or debugging -- tee STDOUT to the log + # + exec 2>| tee $STARTUP_LOG + fi +fi + finished=0 while [ $finished -eq 0 -a $# -gt 0 ]; do diff --git a/Shorewall/Perl/prog.footer6 b/Shorewall/Perl/prog.footer6 index 7513b9696..9d3f32ec0 100644 --- a/Shorewall/Perl/prog.footer6 +++ b/Shorewall/Perl/prog.footer6 @@ -26,6 +26,21 @@ fi initialize +if [ -n "$STARTUP_LOG" ]; then + if [ -a ${SHOREWALL_INIT_SCRIPT:-0} -eq 1 ]; then + # + # We're being run by a startup script that isn't redirecting STDOUT + # Redirect it to the log + # + exec 2> $STARTUP_LOG + elif [ -z "${SHOREWALL_INIT_SCRIPT}${DEBUG}${tracing}" ]; then + # + # We're not tracing or debugging -- tee STDOUT to the log + # + exec 2>| tee $STARTUP_LOG + fi +fi + finished=0 while [ $finished -eq 0 -a $# -gt 0 ]; do diff --git a/Shorewall/init.debian.sh b/Shorewall/init.debian.sh index 7b98f359f..b2b8f8f58 100755 --- a/Shorewall/init.debian.sh +++ b/Shorewall/init.debian.sh @@ -15,9 +15,13 @@ SRWL=/sbin/shorewall SRWL_OPTS="" WAIT_FOR_IFUP=/usr/share/shorewall/wait4ifup -# Note, set INITLOG to /dev/null if you do not want to -# keep logs of the firewall (not recommended) -INITLOG=/dev/null +# Note, set INITLOG to /dev/null if you want to +# use Shorewall's STARTUP_LOG feature. +INITLOG=/var/log/shorewall-init.log + +[ "$INITLOG" eq "/dev/null" && SHOREWALL_INIT_SCRIPT=1 || SHOREWALL_INIT_SCRIPT=0 + +export SHOREWALL_INIT_SCRIPT test -x $SRWL || exit 0 test -x $WAIT_FOR_IFUP || exit 0 diff --git a/Shorewall/init.sh b/Shorewall/init.sh index c3956d2d2..2a4010535 100755 --- a/Shorewall/init.sh +++ b/Shorewall/init.sh @@ -68,6 +68,8 @@ elif [ -f /etc/default/shorewall ] ; then . /etc/default/shorewall fi +export SHOREWALL_INIT_SCRIPT=1 + ################################################################################ # E X E C U T I O N B E G I N S H E R E # ################################################################################ diff --git a/Shorewall/install.sh b/Shorewall/install.sh index e1f536856..ed3bea017 100755 --- a/Shorewall/install.sh +++ b/Shorewall/install.sh @@ -243,9 +243,7 @@ if [ ! -f ${PREFIX}/etc/shorewall/shorewall.conf ]; then # # Make a Debian-like shorewall.conf # - perl -p -w -i -e 's|^STARTUP_ENABLED=.*|STARTUP_ENABLED=Yes|; - s|^STARTUP_LOG=.*|STARTUP_LOG=/var/lib/shorewall-init.log|; - s|^LOG_VERBOSITY=.*|LOG_VERBOSITY=2|;' ${PREFIX}/etc/shorewall.conf + perl -p -w -i -e 's|^STARTUP_ENABLED=.*|STARTUP_ENABLED=Yes|;' ${PREFIX}/etc/shorewall.conf fi echo "Config file installed as ${PREFIX}/etc/shorewall/shorewall.conf" diff --git a/Shorewall6-lite/init.debian.sh b/Shorewall6-lite/init.debian.sh index 5d7aef514..c6b9816c1 100755 --- a/Shorewall6-lite/init.debian.sh +++ b/Shorewall6-lite/init.debian.sh @@ -19,6 +19,10 @@ SRWL_OPTS="-tvv" # keep logs of the firewall (not recommended) INITLOG=/var/log/shorewall6-lite-init.log +[ "$INITLOG" eq "/dev/null" && SHOREWALL_INIT_SCRIPT=1 || SHOREWALL_INIT_SCRIPT=0 + +export SHOREWALL_INIT_SCRIPT + test -x $SRWL || exit 0 test -x $WAIT_FOR_IFUP || exit 0 test -n $INITLOG || { diff --git a/Shorewall6-lite/init.sh b/Shorewall6-lite/init.sh index 17a01bb2e..2fab7296d 100755 --- a/Shorewall6-lite/init.sh +++ b/Shorewall6-lite/init.sh @@ -67,6 +67,8 @@ elif [ -f /etc/default/shorewall6-lite ] ; then . /etc/default/shorewall6-lite fi +export SHOREWALL_INIT_SCRIPT=1 + ################################################################################ # E X E C U T I O N B E G I N S H E R E # ################################################################################ diff --git a/Shorewall6/init.debian.sh b/Shorewall6/init.debian.sh index 96ea36076..e740c3ee6 100755 --- a/Shorewall6/init.debian.sh +++ b/Shorewall6/init.debian.sh @@ -19,6 +19,10 @@ WAIT_FOR_IFUP=/usr/share/shorewall6/wait4ifup # keep logs of the firewall (not recommended) INITLOG=/var/log/shorewall6-init.log +[ "$INITLOG" eq "/dev/null" && SHOREWALL_INIT_SCRIPT=1 || SHOREWALL_INIT_SCRIPT=0 + +export SHOREWALL_INIT_SCRIPT + test -x $SRWL || exit 0 test -x $WAIT_FOR_IFUP || exit 0 test -n $INITLOG || { diff --git a/Shorewall6/init.sh b/Shorewall6/init.sh index 054f18269..47d66de11 100755 --- a/Shorewall6/init.sh +++ b/Shorewall6/init.sh @@ -68,6 +68,8 @@ elif [ -f /etc/default/shorewall6 ] ; then . /etc/default/shorewall6 fi +export SHOREWALL_INIT_SCRIPT=1 + ################################################################################ # E X E C U T I O N B E G I N S H E R E # ################################################################################