]> git.ipfire.org Git - people/ms/network.git/commitdiff
Drop old locking functions
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 17:51:13 +0000 (18:51 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Mar 2019 17:51:13 +0000 (18:51 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.device
src/functions/functions.editor
src/functions/functions.firewall
src/functions/functions.lock

index 48f2440398d5aa96c0a6cd428e9d6e504f6578fb..f52eee5b22e38a426cfe7a2c0f6fe25941ec8d1d 100644 (file)
@@ -997,15 +997,11 @@ device_get_link_string() {
 }
 
 device_auto_configure_smp_affinity() {
-       assert [ $# -eq 1 ]
-
-       local device=${1}
-
-       if lock_acquire "smp-affinity" 60; then
-               device_set_smp_affinity ${device} auto
+       local device="${1}"
+       assert isset device
 
-               lock_release "smp-affinity"
-       fi
+       lock "smp-affinity" \
+               device_set_smp_affinity "${device}" "auto"
 }
 
 device_set_smp_affinity() {
index 6edac62a2125ba2d1809820453bd1502f7ecda00..8f0cc0bc901082b75478061a4ad4ca2d23fdafc0 100644 (file)
 #                                                                             #
 ###############################################################################
 
-editor_cleanup() {
-       # Cleanup after a file was edited
-       assert [ $# -eq 2 ]
-
-       local file=${1}
-       local temp_file=${2}
-
-       lock_release "${file}.lock"
-       rm -f ${temp_file}
-}
-
 editor_find_best() {
        # Open a file with the best available editor
        assert [ $# -eq 1 ]
@@ -62,31 +51,26 @@ editor_find_best() {
 }
 
 editor() {
-       # This function open a file for editing and take care of all preperation and postprocessing
-       assert [ $# -ge 1 ]
+       local file="${1}"
+       assert isset file
 
-       local file=${1}
        if [ ! -f ${file} ] || [ ! -w ${file} ]; then
                error "${file} is not valid file or is not writeable"
                return ${EXIT_ERROR}
        fi
 
-       local check_func=${2}
+       lock "${file}.lock" __editor "$@"
+}
 
-       # check if the file is locked
-       if lock_exists "${file}.lock"; then
-               error "Cannot edit ${file} because it is locked"
-               return ${EXIT_ERROR}
-       fi
+__editor() {
+       # This function open a file for editing and take care of all preperation and postprocessing
+       assert [ $# -ge 1 ]
 
-       # lock the file
-       if ! lock_acquire "${file}.lock"; then
-               error "Cannot lock file ${file}"
-               return ${EXIT_ERROR}
-       fi
+       local file="${1}"
+       local check_func="${2}"
 
        # create a temporary file
-       local temp_file=$(mktemp)
+       local temp_file="$(mktemp)"
 
        if ! [ -f "${temp_file}" ]; then
                error "Cannot create temporary file"
@@ -98,21 +82,26 @@ editor() {
        # edit the file
        if ! editor_find_best "${temp_file}"; then
                error "Could not edit ${file}"
-               # cleanup
-               editor_cleanup "${file}" "${temp_file}"
+
+               # Delete temporary file
+               file_delete "${temp_file}"
+
+               return ${EXIT_ERROR}
        fi
 
        # run the check if we have one
        if isset check_func && ! editor_check "${check_func}" "${temp_file}"; then
+               # Delete temporary file
+               file_delete "${temp_file}"
+
                return ${EXIT_ERROR}
        fi
 
        # copy the changes back
        cp -f "${temp_file}" "${file}"
 
-       # cleanup
-       editor_cleanup "${file}" "${temp_file}"
-
+       # Delete temporary file
+       file_delete "${temp_file}"
 }
 
 editor_check() {
index 347916ef63121647767a597abf15af6fc022cb14..e22576b0332964e0308cda25e9eb11aac97e95c6 100644 (file)
@@ -269,7 +269,8 @@ firewall_panic() {
 }
 
 firewall_lock_acquire() {
-       lock_acquire ${RUN_DIR}/.firewall_lock
+       # XXX DEPRECATED
+       #lock_acquire ${RUN_DIR}/.firewall_lock
 
        # Make sure the lock is released after the firewall
        # script has crashed or exited early.
index 6295a22bf2ac3cf42cefb8859db1332d1540f539..fd15e5e327c5feae1990dc67a3983bc635cd2289 100644 (file)
 #                                                                             #
 ###############################################################################
 
-__lock_path() {
-       local name=${1}
-
-       if [ "${name:0:1}" = "/" ]; then
-               echo "${name}"
-       else
-               echo "${LOCK_DIR}/network-${name}"
-       fi
-}
-
 lock() {
        local lock="${1}"
        shift
@@ -65,63 +55,3 @@ lock() {
                exit ${ret}
        ) 9>${lock} || exit $?
 }
-
-lock_exists() {
-       local name=${1}
-       assert isset name
-
-       local lockfile=$(__lock_path ${name})
-
-       if [ -e "${lockfile}" ]; then
-               return ${EXIT_TRUE}
-       else
-               return ${EXIT_FALSE}
-       fi
-}
-
-lock_acquire() {
-       local name=${1}
-       assert isset name
-
-       # timeout value in seconds
-       local timeout=${2}
-
-       if ! isset timeout; then
-               timeout=0
-       fi
-
-       local lockfile=$(__lock_path ${name})
-
-       timeout=$(( ${timeout} * 4 ))
-
-       log DEBUG "Acquiring lock '${name}'"
-
-       # Wait until lock is available
-       while [ ${timeout} -gt 0 ] && [ -e "${lockfile}" ]; do
-               timeout=$(( ${timeout} - 1 ))
-               sleep 0.25
-       done
-
-       # If another lock still exists, we return an error
-       if [ -e "${lockfile}" ]; then
-               error "Could not acquire lock '${name}'"
-               return ${EXIT_ERROR}
-       fi
-
-       # Write out pid to the lockfile and make sure that
-       # nobody else can access it.
-       echo "$$" > ${lockfile}
-       chmod 600 ${lockfile}
-}
-
-lock_release() {
-       local name=${1}
-       assert isset name
-
-       local lockfile=$(__lock_path ${name})
-
-       log DEBUG "Releasing lock '${name}'"
-
-       # Remove the lockfile (okay if it does not exist).
-       rm -f ${lockfile}
-}