summaryrefslogtreecommitdiff
path: root/mail/clamav/files/clamd.sh
blob: c4c2fa265d868d9c152500e39d57c31cf2ac1258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
#
# $NetBSD: clamd.sh,v 1.3 2004/08/01 04:35:33 jlam Exp $
#
# clamd does anti-virus checking.
#
## only for NetBSD
# PROVIDE: clamd
# REQUIRE: LOGIN
##	only because it might be used by mimedefang
# BEFORE: mail
# KEYWORD: shutdown
##

if [ -f /etc/rc.subr ]; then
	. /etc/rc.subr
fi

name="clamd"
rcvar=$name
command="@PREFIX@/sbin/${name}"
scan_command="@PREFIX@/bin/clamdscan"
required_files="@PKG_SYSCONFDIR@/clamav.conf"
start_precmd="clamd_precmd"
stop_cmd="clamd_stopcmd"

if [ -f "${required_files}" ]; then
	pidfile_=`@AWK@ '/^#/ {next}; /^PidFile[ 	]/ {r = $2};
			END {print r}' ${required_files}`
	if [ -n "${pidfile_}" ]; then
		pidfile=${pidfile_}
	fi
	logfile=`@AWK@ 'BEGIN {r = "/tmp/clamd.log"};
			/^#/ {next}; /^LogFile[ 	]/ {r = $2};
			END {print r}' ${required_files}`
	socket=`@AWK@ 'BEGIN {r = "/tmp/clamd"};
			/^#/ {next}; /^LocalSocket[ 	]/ {r = $2};
			END {print r}' ${required_files}`
	clamd_user=`@AWK@ 'BEGIN {r = "@CLAMAV_USER@"};
			/^#/ {next}; /^User[ 	]/ {r = $2};
			END {print r}' ${required_files}`
fi

clamd_precmd()
{
	@RM@ -f ${socket}
	if [ -n "${logfile}" ]; then
    		@TOUCH@ ${logfile}
    		@CHOWN@ ${clamd_user} ${logfile}
	fi
	if [ -n "${pidfile}" ]; then
    		@TOUCH@ ${pidfile}
    		@CHOWN@ ${clamd_user} ${pidfile}
	fi
}

clamd_stopcmd()
{
	# Workaround bug when clamd is built against pth by send TERM to
	# clamd, then forcing it to start a worker thread that exits.
	# This forces the main thread to awaken and realize that it's
	# supposed to shutdown.
	#
        @ECHO@ "Stopping ${name}."
        doit="@SU@ -m ${clamd_user} -c \"kill -TERM $rc_pid\""
        if ! eval $doit && [ -z "$rc_force" ]; then
                return 1
        fi
        ${scan_command} --quiet ${scan_command} 2>/dev/null
        wait_for_pids $rc_pid
}

if [ -f /etc/rc.subr -a -f /etc/rc.conf \
     -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then
	load_rc_config $name
	run_rc_command "$1"
else
	@ECHO@ -n " ${name}"
	eval ${start_precmd}
	${command} ${clamd_flags} ${command_args}
fi