Changeset 144

Show
Ignore:
Timestamp:
01/10/06 22:12:16 (3 years ago)
Author:
zoeloelip
Message:

Fix for bug 1238736

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ChangeLog

    r142 r144  
    22 
    33        * Fix for bug #1366008 
     4        * Fix for bug #1238736, when a log file is set eA will lock it 
     5          before writing to it. 
    46 
    572005-11-22 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/debug.c

    r142 r144  
    3636#include <ctype.h> 
    3737#include <stdio.h> 
    38  
    39 FILE *F_fp = NULL; 
     38#include <unistd.h> 
     39#include <fcntl.h> 
     40 
     41static FILE *F_fp = NULL; 
     42static int file_no = 0; 
    4043long eaccelerator_debug = 0; 
    4144 
     
    4952    REGISTER_MAIN_LONG_CONSTANT ("EA_LOG", EA_LOG, CONST_PERSISTENT | CONST_CS); 
    5053    REGISTER_MAIN_LONG_CONSTANT ("EA_DEBUG", EA_DEBUG, CONST_PERSISTENT | CONST_CS); 
    51     REGISTER_MAIN_LONG_CONSTANT ("EA_PROFILE_OPCODES", EA_PROFILE_OPCODES, 
    52                             CONST_PERSISTENT | CONST_CS); 
    53     REGISTER_MAIN_LONG_CONSTANT ("EA_TEST_PERFORMANCE", EA_TEST_PERFORMANCE, 
    54                             CONST_PERSISTENT | CONST_CS); 
    55     REGISTER_MAIN_LONG_CONSTANT ("EA_LOG_HASHKEYS", EA_LOG_HASHKEYS, 
    56                             CONST_PERSISTENT | CONST_CS); 
     54    REGISTER_MAIN_LONG_CONSTANT ("EA_PROFILE_OPCODES", EA_PROFILE_OPCODES, CONST_PERSISTENT | CONST_CS); 
     55    REGISTER_MAIN_LONG_CONSTANT ("EA_TEST_PERFORMANCE", EA_TEST_PERFORMANCE, CONST_PERSISTENT | CONST_CS); 
     56    REGISTER_MAIN_LONG_CONSTANT ("EA_LOG_HASHKEYS", EA_LOG_HASHKEYS, CONST_PERSISTENT | CONST_CS); 
    5757 
    5858    F_fp = fopen (EAG (eaccelerator_log_file), "a"); 
    5959    if (!F_fp) 
    6060        F_fp = stderr; 
     61    file_no = fileno(F_fp); 
    6162} 
    6263 
     
    7273} 
    7374 
     75/* lock the log file, don't lock stderr */ 
     76static void ea_debug_lock() { 
     77    int rc; 
     78    struct flock l; 
     79    if (F_fp != stderr) { 
     80        l.l_whence   = SEEK_SET; 
     81        l.l_start    = 0; 
     82        l.l_len      = 0; 
     83        l.l_pid      = 0; 
     84        l.l_type     = F_WRLCK; 
     85        do { 
     86            rc = fcntl(file_no, F_SETLKW, &l); 
     87        } while (rc < 0 && errno == EINTR); 
     88    } 
     89} 
     90 
     91static void ea_debug_unlock() { 
     92    int rc; 
     93    struct flock l; 
     94    if (F_fp != stderr) { 
     95        l.l_whence   = SEEK_SET; 
     96        l.l_start    = 0; 
     97        l.l_len      = 0; 
     98        l.l_pid      = 0; 
     99        l.l_type     = F_UNLCK; 
     100        do { 
     101            rc = fcntl(file_no, F_SETLKW, &l); 
     102        } while (rc < 0 && errno == EINTR); 
     103    } 
     104} 
     105 
    74106/** 
    75107 * Print a log message that will be print when the debug level is 
     
    87119        va_end (args); 
    88120 
     121        ea_debug_lock(); 
    89122#ifdef ZEND_WIN32 
    90123        OutputDebugString (output_buf); 
     
    93126        fflush (F_fp); 
    94127#endif 
     128        ea_debug_unlock(); 
    95129    } 
    96130} 
     
    136170        vsnprintf (output_buf, sizeof (output_buf), format, args); 
    137171        va_end (args); 
    138  
     172         
     173        ea_debug_lock(); 
    139174        fputs (output_buf, F_fp); 
    140175        fflush (F_fp); 
     176        ea_debug_unlock(); 
    141177    } 
    142178} 
     
    154190{ 
    155191    if (debug_level & eaccelerator_debug) { 
     192        ea_debug_lock(); 
    156193        fputs (message, F_fp); 
    157194        fflush (F_fp); 
     195        ea_debug_unlock(); 
    158196    } 
    159197} 
     
    171209{ 
    172210    if (eaccelerator_debug & debug_level) { 
     211        ea_debug_lock(); 
    173212        while (len--) { 
    174213            fputc (*p++, F_fp); 
     
    176215        fputc ('\n', F_fp); 
    177216        fflush (F_fp); 
     217        ea_debug_unlock(); 
    178218    } 
    179219} 
     
    196236        b = ht->pListHead; 
    197237 
    198         fputs (p, F_fp); 
     238        ea_debug_lock(); 
     239        fputs(p, F_fp); 
     240        fflush(F_fp); 
     241        ea_debug_unlock(); 
    199242        while (b) { 
    200243            fprintf (F_fp, "[%d] ", i); 
     
    204247            i++; 
    205248        } 
    206         fflush (F_fp); 
    207249    } 
    208250} 
     
    220262{ 
    221263    if (eaccelerator_debug & debug_level) { 
     264        ea_debug_lock(); 
    222265        int i = EAG (xpad); 
    223266        while (i-- > 0) { 
    224267            fputc ('\t', F_fp); 
    225268        } 
     269        ea_debug_unlock(); 
    226270    } 
    227271}