#!/bin/bash
#
# Tests a "full" setup.  Specifically, a setup including
# userv-ipif, authbind, and with the iptables check not defeated.
#
# The server is run via the init script.
# The client is run by hand as a user "user".

set -e
. "${0%/*}"/acommon

xxxx-server-status-dump () {
    in- server bash -xc >&2 '
	ls -al /dev/log /run
	ls -alL /dev/log
	ps -Hef
#	systemctl is-active hippotatd.service ||:
#	journalctl -u hippotatd.service ||:
	# empirically, daemon.log is the only one anything useful turns up
	egrep . /dev/null /var/log/daemon.log
#	egrep . /dev/null /etc/systemd/journald.conf
#	egrep . /dev/null /etc/rsyslog.conf
	ls -al /dev/log /run
	exit 0
    '
}

setup-pair

xxxx-server-status-dump

sleep 5

xxxx-server-status-dump

in- server service hippotatd restart || {
  in- server strace -s500 \
     -e 'trace=!rt_sigprocmask,mmap,mprotect,sigaltstack,prctl,sched_yield,set_robust_list,futex,sched_getaffinity,munmap,getrandom' \
     -fftt /usr/sbin/hippotatd --syslog-facility daemon &
  sleep 5
}

sleep 5

xxxx-server-status-dump

sleep 5

in-ns-await-up server 192.0.2.1

in- client su user -c hippotat &
clientpid=$!

in-ns-await-up client 192.0.2.3

in-ns client \
      env LC_MESSAGES=C \
      ping -i 0.1 -c 100 192.0.2.1 \
    | tee $tmp/ping

grep ' 0% packet loss' $tmp/ping

echo tests passed, cleaning up.

$src/adt/acleanup

t-ok
