[clamav] clamav-notify-servers: rewrote script to be init-neutral

ensc ensc at fedoraproject.org
Sat Jan 21 12:46:46 UTC 2012


commit adba5caebf647afaee1806880f6b7485e1021c64
Author: Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
Date:   Sat Jan 21 13:23:21 2012 +0100

    clamav-notify-servers: rewrote script to be init-neutral
    
    it just sends a 'zRELOAD' command to autodetected and/or configurable
    sockets,
    
    NOTE: new scripts requires the 'timeout' utility from recent
    'coreutils'.  It is *not* shipped by RHEL5 and before.

 clamav-notify-servers |   80 ++++++++++++++++++++++++++++++++++++++++--------
 clamav.spec           |    4 ++
 2 files changed, 70 insertions(+), 14 deletions(-)
---
diff --git a/clamav-notify-servers b/clamav-notify-servers
index f115e89..8c298aa 100644
--- a/clamav-notify-servers
+++ b/clamav-notify-servers
@@ -1,10 +1,10 @@
 #! /bin/bash
 
-# Copyright (C) 2004 Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
+# Copyright (C) 2004,2012 Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
+# the Free Software Foundation; version 2 and/or 3 of the License.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -18,21 +18,73 @@
 # Usage:  clamav-notify-servers
 
 CFGFILE=/etc/sysconfig/clamav-servers
-BASE=/var/lock/subsys/clamd.
-INITRDDIR=/etc/init.d
+OP=nc
+NC=nc
+TIMEOUT_TERM=30
+TIMEOUT_KILL=60
 
-ok=1
+get_sockets() {
+    (
+	cd /etc/clamd.d
+	for i in *.conf; do
+	    test -f "$i" || continue
+	    test -r "$i" || continue
 
-f=/usr/sbin/clamav-notify-servers.local
-test ! -e "$f" || . "$f"
+	    base=${i%%.conf}
+	    S=/var/run/clamd.$base/clamd.sock
+	    test -S "$S" || continue
+	    test -w "$S" || continue
+
+	    echo "$S"
+	done
+    )
+}
+
+op_nc() {
+    cd /var/run
+    for i in ${CLAMD_SOCKETS}; do
+	case $i in
+	  (/*)
+		test -S "$i" || { 
+		  echo "socket '$i' does not exist" >&2
+		  continue
+		}
+		CMD=( $NC -U $i )
+		;;
+
+	  (ip4:*)
+		addr=${i##ip4:}
+		CMD=( $NC -4 ${addr%%:*} ${addr##*:} )
+		;;
 
-for i in ${BASE}*; do
-    test -e "$i" || continue
+	  (ip6:*)
+		addr=${i##ip6:}
+		CMD=( $NC -6 ${addr%%:*} ${addr##*:} )
+		;;
+	  (*)
+		echo "unsupported socket name '$i'" >&2
+		continue
+	esac
 
-    srv=${INITRDDIR}/clamd.${i##${BASE}}
-    test -e "$srv" || continue
+	resp=`printf 'zRELOAD\0' | timeout -k $TIMEOUT_KILL $TIMEOUT_TERM "${CMD[@]}"`
+	case $resp in
+	  (RELOADING)
+		;;
+	  (*)
+		echo "clamd server '$i' gave '$resp' response" >&2
+		let ++fail
+		;;
+	esac
+    done
+    cd - &>/dev/null
+}
+
+
+CLAMD_SOCKETS=`get_sockets`
+f=$CFGFILE
+test ! -e "$f" || . "$f"
 
-    "$srv" reload  || ok=
-done >/dev/null
+fail=0
+op_$OP "$@"
 
-test "$ok"
+exit $fail
diff --git a/clamav.spec b/clamav.spec
index 0c8d60f..339a411 100644
--- a/clamav.spec
+++ b/clamav.spec
@@ -150,6 +150,7 @@ Group:		System Environment/Daemons
 Requires:	data(clamav)
 Requires:	clamav-filesystem = %version-%release
 Requires:	clamav-lib        = %version-%release
+Requires:	nc coreutils
 
 %package server-sysvinit
 Summary:	SysV initscripts for clamav server
@@ -851,6 +852,9 @@ test "$1" != "0" || /sbin/initctl -q stop clamav-milter || :
 
 
 %changelog
+* Sat Jan 21 2012 Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de>
+- rewrote clamav-notify-servers to be init system neutral
+
 * Sun Jan  8 2012 Enrico Scholz <enrico.scholz at informatik.tu-chemnitz.de> - 0.97.3-1702
 - set correct SELinux context for logfiles generated in %%post (#754555)
 - create systemd tmpfiles in %%post


More information about the scm-commits mailing list