[Pkg-clamav-devel] Bug#999869: Support networkd-dispatcher (and modernize ifupdown scripts)

Sergio Durigan Junior sergiodj at debian.org
Wed Nov 17 23:39:07 GMT 2021


Control: tags -1 + patch

On Wednesday, November 17 2021, I wrote:

> Hello,
>
> I am taking the liberty to file this bug in order to replicate the
> following Merge Request:
>
>   https://salsa.debian.org/clamav-team/clamav/-/merge_requests/4
[...]
> I will attach a debdiff as soon as I have a bug number.

Here it is.

Thank you,

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
https://sergiodj.net/

diff --git a/debian/changelog b/debian/changelog
index 8844213d..359a48f4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,15 @@
+clamav (0.103.4+dfsg-2) UNRELEASED; urgency=medium
+
+  * Extend ifupdown script to support networkd-dispatcher.
+    - d/clamav-freshclam-ifupdown: Modernize some parts of the script.
+      Implement support for networkd-dispatcher.
+    - d/clamav-freshclam.links: Install the clamav-freshclam-ifupdown
+      script inside the proper
+      /usr/lib/networkd-dispatcher/{off,routable}.d/ directories.
+    (Closes: #999869) (LP: #1718227)
+
+ -- Sergio Durigan Junior <sergiodj at debian.org>  Wed, 17 Nov 2021 18:37:32 -0500
+
 clamav (0.103.4+dfsg-1) unstable; urgency=medium
 
   * Import 0.103.4
diff --git a/debian/clamav-freshclam-ifupdown b/debian/clamav-freshclam-ifupdown
index 875c0cca..232fd79b 100755
--- a/debian/clamav-freshclam-ifupdown
+++ b/debian/clamav-freshclam-ifupdown
@@ -1,16 +1,25 @@
 #!/bin/sh
 # 2004-01-25, Thomas Lamy <thomas.lamy at in-online.net>
 # From Magnus Ekdahl's <magnus at debian.org> clamav-freshclam-handledaemon(8)
+# Adjust to be networkd-dispatcher compatible by
+# Sergio Durigan Junior <sergiodj at debian.org>
 
 set -e
 
-[ -e /var/lib/clamav/interface ] || exit 0
+[ -f /var/lib/clamav/interface ] || exit 0
+
+if [ -d /run/systemd/system ]; then
+    INIT='systemctl'
+    INIT_SUFFIX='clamav-freshclam'
+else
+    INIT='invoke-rc.d clamav-freshclam'
+    INIT_SUFFIX=''
+fi
 
-INIT=invoke-rc.d clamav-freshclam
 CLAMAV_CONF_FILE=/etc/clamav/clamd.conf
 FRESHCLAM_CONF_FILE=/etc/clamav/freshclam.conf
 
-INTERNETIFACE=`cat /var/lib/clamav/interface`
+INTERNETIFACE=$(cat /var/lib/clamav/interface)
 
 if grep -q freshclam /proc/*/stat 2>/dev/null; then
   IS_RUNNING=true
@@ -18,61 +27,104 @@ else
   IS_RUNNING=false
 fi
 
-# $IFACE is set by ifup/down, $PPP_IFACE by pppd 
-[ -n "$PPP_IFACE" ] && IFACE=$PPP_IFACE
+handle_ifupdown ()
+{
+    # $IFACE is set by ifup/down, $PPP_IFACE by pppd 
+    [ -n "$PPP_IFACE" ] && IFACE=$PPP_IFACE
 
-# This is sloppy - woody's pppd exports variables, while sid's passes them as 
-# arguments and exports them.
+    # This is sloppy - woody's pppd exports variables, while sid's passes them as 
+    # arguments and exports them.
 
-if [ "$1" = "$IFACE" ]; then # We're called by sid's pppd
-  shift 6                    # and we already know the interface
-fi                           # Dump the arguments passed.
+    if [ "$1" = "$IFACE" ]; then # We're called by sid's pppd
+	shift 6                    # and we already know the interface
+    fi                           # Dump the arguments passed.
+
+    if [ -z "$1" ]; then
+	case $(dirname "$0") in
+	    */if-up.d|*/ip-up.d)
+		# Short circuit and exit early if freshclam is already running
+		[ "$IS_RUNNING" = 'true' ] && exit 0
+		for interface in $INTERNETIFACE; do
+		    if [ "$interface" = "$IFACE" ]; then
+			FMODE=start
+			break
+		    else
+			FMODE=skip
+		    fi
+		done
+		;;
+	    */if-down.d|*/ip-down.d)
+		# Short circuit and exit early if freshclam is not already running
+		[ "$IS_RUNNING" = 'false' ] && exit 0
+		for interface in $INTERNETIFACE; do
+		    if [ "$interface" = "$IFACE" ]; then
+			FMODE=stop
+			break
+		    else
+			FMODE=skip
+		    fi
+		done
+		;;
+	    *)
+		FMODE=skip
+		;;
+	esac
+    else
+	FMODE="$1"
+    fi
+
+    case "$FMODE" in
+	start|stop)
+	    IFACE="$IFACE" $INIT $FMODE $INIT_SUFFIX
+	    ;;
+	skip)
+	    ;;
+	*)
+	    echo "Usage: $0 {start|stop|skip}" >&2
+	    exit 1
+	    ;;
+    esac
+}
+
+handle_networkd_dispatcher ()
+{
+    FOUND_IFACE=false
 
-if [ -z "$1" ]; then
-  case $(dirname "$0") in
-    */if-up.d|*/ip-up.d)
-    # Short circuit and exit early if freshclam is already running
-    [ "$IS_RUNNING" = 'true' ] && exit 0
-    for interface in $INTERNETIFACE; do
-      if [ "$interface" = "$IFACE" ]; then
-	FMODE=start
-	break
-      else
-	FMODE=skip
-      fi
-    done
-    ;;
-    */if-down.d|*/ip-down.d)
-    # Short circuit and exit early if freshclam is not already running
-    [ "$IS_RUNNING" = 'false' ] && exit 0
     for interface in $INTERNETIFACE; do
-      if [ "$interface" = "$IFACE" ]; then
-	FMODE=stop
-	break
-      else
-	FMODE=skip
-      fi
+	if [ "$interface" = "$IFACE" ]; then
+	    FOUND_IFACE=true
+	    break
+	fi
     done
-    ;;
-    *)
-    FMODE=skip
-    ;;
-  esac
+
+    [ "$FOUND_IFACE" = 'false' ] && return
+
+    FMODE=""
+
+    case "$STATE" in
+	"off")
+	    if [ "$IS_RUNNING" = 'true' ]; then
+		FMODE="stop"
+	    fi
+	    ;;
+	"routable")
+	    if [ "$IS_RUNNING" = 'false' ]; then
+		FMODE="start"
+	    fi
+	    ;;
+	*)
+	    return
+    esac
+
+    if [ -n "$FMODE" ]; then
+	IFACE="$IFACE" $INIT $FMODE $INIT_SUFFIX
+    fi
+}
+
+if [ -n "$STATE" ]; then
+    handle_networkd_dispatcher "$@"
 else
-  FMODE="$1"
+    handle_ifupdown "$@"
 fi
 
-case "$FMODE" in
-  start|stop)
-  IFACE="$IFACE" $INIT $FMODE
-  ;;
-  skip)
-  ;;
-  *)
-  echo "Usage: $0 {start|stop|skip}" >&2
-  exit 1
-  ;;
-esac
-
 exit 0
-
diff --git a/debian/clamav-freshclam.links b/debian/clamav-freshclam.links
index 04ad83db..3f0cfff1 100644
--- a/debian/clamav-freshclam.links
+++ b/debian/clamav-freshclam.links
@@ -1,2 +1,4 @@
 /usr/share/doc/clamav-base/README.Debian.gz /usr/share/doc/clamav-freshclam/README.Debian.gz
 /usr/share/doc/clamav-base/NEWS.gz /usr/share/doc/clamav-freshclam/NEWS.gz
+/etc/network/if-up.d/clamav-freshclam-ifupdown /usr/lib/networkd-dispatcher/routable.d/clamav-freshclam
+/etc/network/if-down.d/clamav-freshclam-ifupdown /usr/lib/networkd-dispatcher/off.d/clamav-freshclam
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-clamav-devel/attachments/20211117/7edfe4b0/attachment.sig>


More information about the Pkg-clamav-devel mailing list