#!/bin/sh
# Helper script to provide legacy auditd service options not 
# directly supported by systemd

# Check that we are root ... so non-root users stop here
test $(id -u) = 0  ||  exit 4

PATH=/sbin:/bin:/usr/bin:/usr/sbin
prog="auditd"
. /etc/rc.d/init.d/functions
pid="$(__pids_pidof "$prog")"

printf "Stopping logging: "
killproc $prog -TERM
RETVAL=$?
count=0
while [ 1 == 1  ]
do
   pid_tmp=`pidof auditd`
   if [ "A$pid_tmp" == "A" ];then
      break
   else
      if [ $count -gt 5 ];then
         kill -s TERM $pid_tmp
         break
      fi
      count=`expr $count + 1`
      sleep 1
   fi
done
if [ -n "$pid" ] ; then
    # Wait up to 20 seconds for auditd to shutdown
    timeout 20 tail --pid="$pid" -f /dev/null
fi
echo
exit $RETVAL
