Project

General

Profile

« Previous | Next » 

Revision 0027de0a

Added by Ermal Luçi about 16 years ago

  • Create two new functions lock($subsystem)/unlock() to have more reliable locking using semaphores.
    This function can sleep till the resource is free and can help find not well behaving code.
  • Remove most of the config_lock/config_unlock logics on the whole scripts/pages it is an abuse of this.
    If any sybsytem wants to lock can do so with its own lock.
  • Lock the config when doing a filter reload to avoid parallell recursion on this function, since it is not reentrant.
    This compenstates for the removal of lock aquiring from the scripts/pages.
  • config_lock/config_unlock are now compate shims that do nothing. They are preserved since packages 'abuse' them too.

View differences:

etc/inc/pfsense-utils.inc
1912 1912
  return $max_states;
1913 1913
}
1914 1914

  
1915
/****f* pfsense-utils/safe_write_file
1916
 * NAME
1917
 *   safe_write_file - Write a file out atomically
1918
 * DESCRIPTION
1919
 *   safe_write_file() Writes a file out atomically by first writing to a
1920
 *   temporary file of the same name but ending with the pid of the current
1921
 *   process, them renaming the temporary file over the original.
1922
 * INPUTS
1923
 *   $filename  - string containing the filename of the file to write
1924
 *   $content   - string containing the file content to write to file
1925
 *   $force_binary      - boolean denoting whether we should force binary
1926
 *   mode writing.
1927
 * RESULT
1928
 *   boolean - true if successful, false if not
1929
 ******/
1930
function safe_write_file($file, $content, $force_binary) {
1931
        $tmp_file = $file . "." . getmypid();
1932
        $write_mode = $force_binary ? "wb" : "w";
1933

  
1934
        $fd = fopen($tmp_file, $write_mode);
1935
        if (!$fd) {
1936
                // Unable to open temporary file for writing
1937
                return false;
1938
        }
1939
        if (!fwrite($fd, $content)) {
1940
                // Unable to write to temporary file
1941
                fclose($fd);
1942
                return false;
1943
        }
1944
        fclose($fd);
1945

  
1946
        if (!rename($tmp_file, $file)) {
1947
                // Unable to move temporary file to original
1948
                unlink($tmp_file);
1949
                return false;
1950
        }
1951
        return true;
1952
}
1953

  
1954 1915
function rule_popup($src,$srcport,$dst,$dstport){
1955 1916
global $config;
1956 1917
$aliases_array = array();

Also available in: Unified diff