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