syslog04 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. # 12/05/02 Port to bash -Robbie Williamson <robbiew@us.ibm.com>
  18. # 02/05/03 Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
  19. # fixed bugs.
  20. # 07/27/05 Michael Reed <mreedltp@vnet.ibm.com>
  21. # Made changes to account for the replacement of syslogd
  22. # with syslog-ng
  23. #
  24. ##################################################################
  25. # case4: Test the logging option: LOG_PID #
  26. # #
  27. # Do openlog() with LOG_PID option and see whether pid #
  28. # is logged with message. #
  29. ##################################################################
  30. . syslog-lib.sh || exit 1
  31. syslog_case4()
  32. {
  33. tst_resm TINFO "Testing the log option: LOG_PID..."
  34. # Create the configuration file specific to this test case.
  35. case "$CONFIG_FILE" in
  36. /etc/syslog.conf|/etc/rsyslog.conf)
  37. echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
  38. echo "user.info /var/log/messages" >> $CONFIG_FILE
  39. ;;
  40. /etc/syslog-ng/syslog-ng.conf)
  41. echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
  42. echo " " >> $CONFIG_FILE
  43. echo "filter f_syslog_user { level(info) and facility(user); };" >> $CONFIG_FILE
  44. echo "destination syslog_messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
  45. echo "log { source(src); filter(f_syslog_user); destination(syslog_messages);};" >> $CONFIG_FILE
  46. ;;
  47. esac
  48. restart_syslog_daemon
  49. # Run syslogtst in the background and get the process id.
  50. syslogtst 4 2>/dev/null &
  51. log_pid=$!
  52. if ! wait $log_pid; then
  53. cleanup 1
  54. fi
  55. sleep 2
  56. # check if /var/log/messages script exists
  57. if [ ! -e /var/log/messages ]; then
  58. tst_resm TBROK "/var/log/messages no such log file"
  59. cleanup 1
  60. fi
  61. found=`grep -c "\[$log_pid\]: syslogtst: user info test." /var/log/messages`
  62. if [ $found -ne 1 ]; then
  63. status_flag=1
  64. fi
  65. }
  66. tst_resm TINFO "case4: Test the logging option: LOG_PID"
  67. tst_resm TINFO "Do openlog() with LOG_PID option and see whether pid"
  68. tst_resm TINFO "is logged with message."
  69. setup
  70. syslog_case4
  71. cleanup ${status_flag:=0}