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