From 8f7da57704bba10af5fed306a49d0e64bfa1adbd Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 1 Aug 2012 00:10:53 -0700 Subject: [PATCH] Add locks --- CU2/common.inc | 1 + CU2/handle-control-change.sh | 3 +++ CU2/handle-network-change.sh | 8 +++++++- DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m | 4 ---- DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m | 4 ---- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CU2/common.inc b/CU2/common.inc index 2a53ddf..9e5e457 100644 --- a/CU2/common.inc +++ b/CU2/common.inc @@ -13,6 +13,7 @@ DNSCRYPT_FILE="${CONTROL_DIR}/dnscrypt" FAMILYSHIELD_FILE="${CONTROL_DIR}/familyshield" INSECURE_OPENDNS_FILE="${CONTROL_DIR}/insecure-opendns" FALLBACK_FILE="${CONTROL_DIR}/fallback" +HANDLERS_LOCK_FILE="${STATES_DIR}/handlers-lock" INTERFACE_UNBOUND="127.0.0.53" INTERFACE_UNBOUND_MASK="24" diff --git a/CU2/handle-control-change.sh b/CU2/handle-control-change.sh index 51659a6..6b14e77 100755 --- a/CU2/handle-control-change.sh +++ b/CU2/handle-control-change.sh @@ -2,6 +2,8 @@ . ./common.inc +lockfile "$HANDLERS_LOCK_FILE" + touch "${STATES_DIR}/updating" if [ -e "$DNSCRYPT_FILE" ]; then ./switch-to-dnscrypt-if-required.sh @@ -12,3 +14,4 @@ fi rm -f "${STATES_DIR}/updating" rm -f "${STATES_DIR}/update-request" +rm -f "$HANDLERS_LOCK_FILE" diff --git a/CU2/handle-network-change.sh b/CU2/handle-network-change.sh index e0af817..44af0c8 100755 --- a/CU2/handle-network-change.sh +++ b/CU2/handle-network-change.sh @@ -4,6 +4,12 @@ [ ! -e "$FALLBACK_FILE" ] && exit 0 ./check-network-change.sh || exit 0 + +lockfile "$HANDLERS_LOCK_FILE" ./set-dns-to-dhcp.sh -[ ! -e "$DNSCRYPT_FILE" ] && exit 0 +if [ ! -e "$DNSCRYPT_FILE" ]; then + rm -f "$HANDLERS_LOCK_FILE" + exit 0 +fi ./switch-to-dnscrypt-if-required.sh +rm -f "$HANDLERS_LOCK_FILE" diff --git a/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m b/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m index fde7da9..8b3f67c 100644 --- a/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m +++ b/DNSCrypt-Menubar/DNSCrypt-Menubar/AppDelegate.m @@ -125,8 +125,6 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; - (BOOL) updateStatusWithCurrentConfig { - currentState = kDNS_CONFIGURATION_UNKNOWN; - NSString *stateDescription = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./get-current-resolvers.sh | ./get-resolvers-description.sh", nil]]; NSLog(@"%@", stateDescription); if ([stateDescription isEqualToString: @"FamilyShield"]) { @@ -140,8 +138,6 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; } else if ([stateDescription isEqualToString: @"None"]) { currentState = kDNS_CONFIGURATION_UNKNOWN; } else if ([stateDescription isEqualToString: @"Updating"]) { - currentState = kDNS_CONFIGURATION_UNKNOWN; - return FALSE; } else if (stateDescription.length > 0) { currentState = kDNS_CONFIGURATION_VANILLA; } diff --git a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m index 35b8d9d..7f53872 100644 --- a/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m +++ b/DNSCrypt-Preference-Pane/DNSCrypt/DNSCrypt.m @@ -215,8 +215,6 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; - (BOOL) updateStatusWithCurrentConfig { - currentState = kDNS_CONFIGURATION_UNKNOWN; - NSString *stateDescription = [self fromCommand: @"/bin/ksh" withArguments: [NSArray arrayWithObjects: @"-c", @"cd '" kDNSCRIPT_SCRIPTS_BASE_DIR @"' && ./get-current-resolvers.sh | ./get-resolvers-description.sh", nil]]; NSLog(@"%@", stateDescription); if ([stateDescription isEqualToString: @"FamilyShield"]) { @@ -230,8 +228,6 @@ DNSConfigurationState currentState = kDNS_CONFIGURATION_UNKNOWN; } else if ([stateDescription isEqualToString: @"None"]) { currentState = kDNS_CONFIGURATION_UNKNOWN; } else if ([stateDescription isEqualToString: @"Updating"]) { - currentState = kDNS_CONFIGURATION_UNKNOWN; - return FALSE; } else if (stateDescription.length > 0) { currentState = kDNS_CONFIGURATION_VANILLA; }