From 708d83bc7184efaea9a40e2bf69f7e351a7c5c75 Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Thu, 22 Dec 2016 19:33:59 +0100 Subject: [PATCH] adblock: bugfix 2.0.1 * fixed a dnsmasq restart issue (udhcpc error) * fixed a long standing corner case bug in "disabled" state (does not remove active block lists!) * simplified overall sort, removed needless 'for loop' * cosmetics Signed-off-by: Dirk Brenken --- net/adblock/Makefile | 2 +- net/adblock/files/adblock.init | 2 +- net/adblock/files/adblock.sh | 35 +++++++++++++++++----------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/net/adblock/Makefile b/net/adblock/Makefile index 8bbda68328..c52acf0bf7 100644 --- a/net/adblock/Makefile +++ b/net/adblock/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=adblock -PKG_VERSION:=2.0.0 +PKG_VERSION:=2.0.1 PKG_RELEASE:=1 PKG_LICENSE:=GPL-3.0+ PKG_MAINTAINER:=Dirk Brenken diff --git a/net/adblock/files/adblock.init b/net/adblock/files/adblock.init index 7bf70ca710..2ed89cdc57 100755 --- a/net/adblock/files/adblock.init +++ b/net/adblock/files/adblock.init @@ -8,6 +8,7 @@ EXTRA_COMMANDS="suspend resume" EXTRA_HELP=" suspend Suspend adblock processing resume Resume adblock processing" +exec 2>/dev/null adb_script="/usr/bin/adblock.sh" adb_iface="$(uci -q get adblock.global.adb_iface)" @@ -69,7 +70,6 @@ service_triggers() local iface procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start - if [ -z "${adb_iface}" ] then procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start diff --git a/net/adblock/files/adblock.sh b/net/adblock/files/adblock.sh index a2e624a050..3ec2aed540 100755 --- a/net/adblock/files/adblock.sh +++ b/net/adblock/files/adblock.sh @@ -10,7 +10,7 @@ # LC_ALL=C PATH="/usr/sbin:/usr/bin:/sbin:/bin" -adb_ver="2.0.0" +adb_ver="2.0.1" adb_enabled=1 adb_debug=0 adb_whitelist="/etc/adblock/adblock.whitelist" @@ -88,6 +88,11 @@ f_envcheck() # if [ "${adb_enabled}" != "1" ] then + if [ "$(ls -dA "${adb_dnsdir}/${adb_dnsprefix}"* >/dev/null 2>&1)" ] + then + f_rmdns + f_dnsrestart + fi f_log "info " "status ::: adblock is currently disabled, please set adb_enabled to '1' to use this service" exit 0 fi @@ -153,18 +158,21 @@ f_dnsrestart() dns_running="false" sync - "/etc/init.d/${adb_dns}" restart + killall -q -TERM "${adb_dns}" while [ ${cnt} -le 10 ] do dns_running="$(ubus -S call service list '{"name":"dnsmasq"}' | jsonfilter -e '@.dnsmasq.instances.*.running')" if [ "${dns_running}" = "true" ] then - sleep 1 break fi cnt=$((cnt+1)) sleep 1 done + if [ "${dns_running}" = "false" ] + then + /etc/init.d/"${adb_dns}" restart + fi } # f_list: backup/restore/remove block lists @@ -369,29 +377,22 @@ f_main() f_log "debug" "loop ::: name: ${src_name}, list-rc: ${rc}" done - # overall sort, make block list entries unique + # make overall sort, restart & check dns server # - for list in $(ls -ASr "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null) + for src_name in $(ls -dASr "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null) do - list="${list/*./}" if [ -s "${adb_tmpdir}/blocklist.overall" ] then - sort "${adb_tmpdir}/blocklist.overall" "${adb_tmpdir}/blocklist.overall" "${adb_dnsdir}/${adb_dnsprefix}.${list}" | uniq -u > "${adb_tmpdir}/tmp.blocklist" - cat "${adb_tmpdir}/tmp.blocklist" > "${adb_dnsdir}/${adb_dnsprefix}.${list}" + sort "${adb_tmpdir}/blocklist.overall" "${adb_tmpdir}/blocklist.overall" "${src_name}" | uniq -u > "${adb_tmpdir}/tmp.blocklist" + cat "${adb_tmpdir}/tmp.blocklist" > "${src_name}" fi - cat "${adb_dnsdir}/${adb_dnsprefix}.${list}" >> "${adb_tmpdir}/blocklist.overall" + cat "${src_name}" >> "${adb_tmpdir}/blocklist.overall" + cnt="$(wc -l < "${src_name}")" + sum_cnt=$((sum_cnt + cnt)) done - - # restart & check dns server - # f_dnsrestart if [ "${dns_running}" = "true" ] then - for src_name in $(ls -ASr "${adb_dnsdir}/${adb_dnsprefix}"* 2>/dev/null) - do - cnt="$(wc -l < "${src_name}")" - sum_cnt=$((sum_cnt + cnt)) - done f_debug f_rmtemp f_log "info " "status ::: block lists with overall ${sum_cnt} domains loaded (${adb_sysver})" -- 2.30.2