From adba5caebf647afaee1806880f6b7485e1021c64 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Sat, 21 Jan 2012 13:23:21 +0100 Subject: [PATCH] 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 | 82 +++++++++++++++++++++++++++++++++++-------- clamav.spec | 4 +++ 2 files changed, 71 insertions(+), 15 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 +# Copyright (C) 2004,2012 Enrico Scholz # # 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 + 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##*:} ) + ;; + + (ip6:*) + addr=${i##ip6:} + CMD=( $NC -6 ${addr%%:*} ${addr##*:} ) + ;; + (*) + echo "unsupported socket name '$i'" >&2 + continue + esac + + 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" -for i in ${BASE}*; do - test -e "$i" || continue +fail=0 +op_$OP "$@" - srv=${INITRDDIR}/clamd.${i##${BASE}} - test -e "$srv" || continue - - "$srv" reload || ok= -done >/dev/null - -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 +- rewrote clamav-notify-servers to be init system neutral + * Sun Jan 8 2012 Enrico Scholz - 0.97.3-1702 - set correct SELinux context for logfiles generated in %%post (#754555) - create systemd tmpfiles in %%post