diff --git a/usr.sbin/syslogd/tests/Makefile b/usr.sbin/syslogd/tests/Makefile --- a/usr.sbin/syslogd/tests/Makefile +++ b/usr.sbin/syslogd/tests/Makefile @@ -1,4 +1,7 @@ ATF_TESTS_SH+= syslogd_test +# Run in jail with new vnet so we don't need to worry about address conflicts +TEST_METADATA+= execenv="jail" +TEST_METADATA+= execenv_jail_params="vnet=new" # Several syslogd listening on the same port prevent parallel operation TEST_METADATA+= is_exclusive="true" diff --git a/usr.sbin/syslogd/tests/syslogd_test.sh b/usr.sbin/syslogd/tests/syslogd_test.sh --- a/usr.sbin/syslogd/tests/syslogd_test.sh +++ b/usr.sbin/syslogd/tests/syslogd_test.sh @@ -11,7 +11,7 @@ # # Tests to-do: -# actions: hostname, users +# actions: users readonly SYSLOGD_UDP_PORT="5140" readonly SYSLOGD_CONFIG="${PWD}/syslog.conf" @@ -22,27 +22,55 @@ # Start a private syslogd instance. syslogd_start() { - local jail + local jail bind_addr conf_file pid_file socket privsocket + + # Setup loopback so we can deliver messages to ourself. + atf_check ifconfig lo0 inet 127.0.0.1/16 if [ "$1" = "-j" ]; then jail="jexec $2" shift 2 fi + + OPTIND=1 + while getopts ":b:f:P:p:S:" opt; do + case "${opt}" in + b) + bind_addr="${OPTARG}" + ;; + f) + conf_file="${OPTARG}" + ;; + P) + pid_file="${OPTARG}" + ;; + p) + socket="${OPTARG}" + ;; + S) + privsocket="${OPTARG}" + ;; + :) + atf_fail "The -${OPTARG} flag requires an argument" + ;; + esac + done + $jail syslogd \ - -b ":${SYSLOGD_UDP_PORT}" \ + -b "${bind_addr:-":${SYSLOGD_UDP_PORT}"}" \ -C \ -d \ - -f "${SYSLOGD_CONFIG}" \ + -f "${conf_file:-${SYSLOGD_CONFIG}}" \ -H \ - -p "${SYSLOGD_LOCAL_SOCKET}" \ - -P "${SYSLOGD_PIDFILE}" \ - -S "${SYSLOGD_LOCAL_PRIVSOCKET}" \ + -P "${pid_file:-${SYSLOGD_PIDFILE}}" \ + -p "${socket:-${SYSLOGD_LOCAL_SOCKET}}" \ + -S "${privsocket:-${SYSLOGD_LOCAL_PRIVSOCKET}}" \ $@ \ & # Give syslogd a bit of time to spin up. while [ "$((i+=1))" -le 20 ]; do - [ -S "${SYSLOGD_LOCAL_SOCKET}" ] && return + [ -S "${socket:-${SYSLOGD_LOCAL_SOCKET}}" ] && return sleep 0.1 done atf_fail "timed out waiting for syslogd to start" @@ -57,17 +85,19 @@ # Make syslogd reload its configuration file. syslogd_reload() { - pkill -HUP -F "${SYSLOGD_PIDFILE}" + pkill -HUP -F "${1:-${SYSLOGD_PIDFILE}}" } # Stop a private syslogd instance. syslogd_stop() { - pid=$(cat "${SYSLOGD_PIDFILE}") - if pkill -F "${SYSLOGD_PIDFILE}"; then + local pid_file="${1:-${SYSLOGD_PIDFILE}}" + + pid=$(cat "${pid_file}") + if pkill -F "${pid_file}"; then wait "${pid}" - rm -f "${SYSLOGD_PIDFILE}" "${SYSLOGD_LOCAL_SOCKET}" \ - "${SYSLOGD_LOCAL_PRIVSOCKET}" + rm -f "${pid_file}" "${2:-${SYSLOGD_LOCAL_SOCKET}}" \ + "${3:-${SYSLOGD_LOCAL_PRIVSOCKET}}" fi } @@ -270,6 +300,43 @@ syslogd_stop } +atf_test_case "host_action" "cleanup" +host_action_head() +{ + atf_set descr "Sends a message to a specified host" +} +host_action_body() +{ + local addr1="192.0.2.100" + local addr2="192.0.2.101" + local logfile="${PWD}/host_action.log" + + printf "user.debug\t@${addr2}\n" > "${SYSLOGD_CONFIG}" + syslogd_start -b "${addr1}" + + printf "user.debug\t${logfile}\n" > "${SYSLOGD_CONFIG}.2" + syslogd_start \ + -a "${addr1}" \ + -b "${addr2}" \ + -f "${SYSLOGD_CONFIG}.2" \ + -P "${SYSLOGD_PIDFILE}.2" \ + -p "${SYSLOGD_LOCAL_SOCKET}.2" \ + -S "${SYSLOGD_LOCAL_PRIVSOCKET}.2" + + syslogd_log -p user.debug -t "test" -h "${SYSLOGD_LOCAL_SOCKET}" \ + "message from syslogd1" + atf_check -s exit:0 -o match:"test: message from syslogd1" \ + cat "${logfile}" +} +host_action_cleanup() +{ + syslogd_stop + syslogd_stop \ + "${SYSLOGD_PIDFILE}.2" \ + "${SYSLOGD_LOCAL_SOCKET}.2" \ + "${SYSLOGD_LOCAL_PRIVSOCKET}.2" +} + atf_test_case "pipe_action" "cleanup" pipe_action_head() { @@ -326,6 +393,7 @@ atf_add_test_case "prog_filter" atf_add_test_case "host_filter" atf_add_test_case "prop_filter" + atf_add_test_case "host_action" atf_add_test_case "pipe_action" atf_add_test_case "jail_noinet" }