• Davi Arnaut's avatar
    Bug#51023: Mysql server crashes on SIGHUP and destroys InnoDB files · 78b6ca55
    Davi Arnaut authored
    From a user perspective, the problem is that a FLUSH LOGS or SIGHUP
    signal could end up associating the stdout and stderr to random
    files. In the case of this bug report, the streams would end up
    associated to InnoDB ibd files.
    
    The freopen(3) function is not thread-safe on FreeBSD. What this
    means is that if another thread calls open(2) during freopen()
    is executing that another thread's fd returned by open(2) may get
    re-associated with the file being passed to freopen(3). See FreeBSD
    PR number 79887 for reference:
    
      http://www.freebsd.org/cgi/query-pr.cgi?pr=79887
    
    This problem is worked around by substituting a internal hook within
    the FILE structure. This avoids the loss of atomicity by not having
    the original fd closed before its duplicated.
    
    Patch based on the original work by Vasil Dimov.
    78b6ca55
log.cc 171 KB