#!/bin/sh

process_count="`ps ax | grep -E "/usr/local/sbin/clamd\$" | grep -v grep | cat -n | tail -n1 | awk '{print $1}'`"
if [ -n "$process_count" ]; then
    echo There are already $process_count clamd processes running
    exit 1
fi

CLAMDMEMORYLIMIT=`cat /var/clamd/control/clamdmemorylimit`

if [ -z "$CLAMDMEMORYLIMIT" ]; then
    echo CLAMDMEMORYLIMIT is unset in
    echo /var/clamd/supervise/clamd/run
    exit 1
fi

# exec /usr/local/bin/softlimit -m $CLAMDMEMORYLIMIT \
/usr/local/bin/setuidgid clamd /usr/local/sbin/clamd
