Home | History | Annotate | Download | only in syslog
      1 #! /bin/sh
      2 
      3 #  Copyright (c) International Business Machines  Corp., 2002
      4 #
      5 #  This program is free software;  you can redistribute it and/or modify
      6 #  it under the terms of the GNU General Public License as published by
      7 #  the Free Software Foundation; either version 2 of the License, or
      8 #  (at your option) any later version.
      9 #
     10 #  This program is distributed in the hope that it will be useful,
     11 #  but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13 #  the GNU General Public License for more details.
     14 #
     15 #  You should have received a copy of the GNU General Public License
     16 #  along with this program;  if not, write to the Free Software
     17 #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18 
     19 # 12/05/02  Port to bash -Robbie Williamson <robbiew (at] us.ibm.com>
     20 # 02/05/03  Modified - Manoj Iyer <manjo (at] mail.utexas.edu> use USCTEST macros
     21 #	   fixed bugs.
     22 # 07/27/05  Michael Reed  <mreedltp (at] vnet.ibm.com>
     23 #	   Made changes to account for the replacement of syslogd
     24 #	   with syslog-ng
     25 #
     26 ##################################################################
     27 # case 9: Test setlogmask() with LOG_UPTO macro.		 #
     28 #								#
     29 #	 o Use setlogmask() with LOG_UPTO macro to set some     #
     30 #	    priority level.				     #
     31 #	 o Send message which is lower priority than the one    #
     32 #	   set above, which should not be logged.	       #
     33 ##################################################################
     34 
     35 . syslog-lib.sh || exit 1
     36 
     37 syslog_case9()
     38 {
     39 	tst_resm TINFO "syslog: Testing setlogmask() with LOG_UPTO macro"
     40 
     41 	# Create the configuration file specific to this test case.
     42 	case "$CONFIG_FILE" in
     43 	/etc/syslog.conf|/etc/rsyslog.conf)
     44 		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
     45 		echo "user.debug       /var/log/messages" >> $CONFIG_FILE
     46 		;;
     47 
     48 	/etc/syslog-ng/syslog-ng.conf)
     49 		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
     50 		#echo "filter f_syslog_debug { level(debug) and facility(user); };" >> $CONFIG_FILE
     51 		echo "filter f_syslog_debug { facility(user); };" >> $CONFIG_FILE
     52 		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
     53 		echo "log { source(src); filter(f_syslog_debug); destination(syslog-messages);};" >> $CONFIG_FILE
     54 		;;
     55 	esac
     56 
     57 	restart_syslog_daemon
     58 
     59 	if [ -e /var/log/messages ]; then
     60 		allow1=`grep -c "syslogtst: error level is logged" /var/log/messages`
     61 		donot_allow1=`grep -c "syslogtst: warning level not to be logged" /var/log/messages`
     62 	else
     63 		allow1=0
     64 		donot_allow1=0
     65 	fi
     66 
     67 	if ! syslogtst 9 2>/dev/null; then
     68 		cleanup 1
     69 	fi
     70 	sleep 2
     71 
     72 	# check if /var/log/messages script exists
     73 	if [ ! -e /var/log/messages ]; then
     74 		tst_resm TBROK "/var/log/messages no such log file"
     75 		cleanup 1
     76 	fi
     77 
     78 	allow2=`grep -c "syslogtst: error level is logged" /var/log/messages`
     79 	donot_allow2=`grep -c "syslogtst: warning level not to be logged" /var/log/messages`
     80 
     81 	diff1=$(( $allow2 - $allow1 ))
     82 	if [ $diff1 -ne 1 ]; then
     83 		tst_resm TFAIL "Expected message was not logged...."
     84 		status_flag=1
     85 		return
     86 	fi
     87 
     88 	diff2=$(( $donot_allow2 - $donot_allow1 ))
     89 	if [ $diff2 -ne 0 ]; then
     90 		tst_resm TFAIL "Unexpected message was logged..."
     91 		status_flag=1
     92 	fi
     93 }
     94 
     95 tst_resm TINFO " Test setlogmask() with LOG_UPTO macro."
     96 tst_resm TINFO " o Use setlogmask() with LOG_UPTO macro to set some priority"
     97 tst_resm TINFO "   level."
     98 tst_resm TINFO " o Send message which is lower priority than the one"
     99 tst_resm TINFO "   set above, which should not be logged"
    100 
    101 setup
    102 syslog_case9
    103 cleanup ${status_flag:=0}
    104