syslog 引发死锁

主线程在写 syslog,同时在信号处理函数中也在写syslog,当主线程在写的时候,如果同时触发了信号,那么将会导致死锁。

$pstack 4289

#0 0x00000036768df9ee in __lll_lock_wait_private () from /lib64/libc.so.6

#1 0x000000367688d0dd in _L_lock_1685 () from /lib64/libc.so.6

#2 0x000000367688ce27 in __tz_convert () from /lib64/libc.so.6

#3 0x00000036768cff7d in __vsyslog_chk () from /lib64/libc.so.6

#4 0x00000036768d0580 in syslog () from /lib64/libc.so.6

#5 0x00000000004c8c81 in SigChldHandler ()

#6

#7 0x000000367688d2ad in __tzfile_compute () from /lib64/libc.so.6

#8 0x000000367688ce5f in __tz_convert () from /lib64/libc.so.6

#9 0x00000036768cff7d in __vsyslog_chk () from /lib64/libc.so.6

#10 0x00000036768d0580 in syslog () from /lib64/libc.so.6

#11 0x00000000004c5c21 in HandleNewBinRequest ()


根本原因是syslog内部会调用malloc,而malloc是不可重入函数,在信号处理函数中调用不可重入函数会导致死锁问题。