From 70111cd03653c3ceab9d907c14fa35e5881b2735 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Fri, 15 May 2009 17:30:24 +0900 Subject: Fix the deadlock of vsyslog() call. Hi, I found the deadlock problem that a cgrulesengd daemon stalls if service "cgred" is reloaded while many UID events happen. The following is the gdb output by attaching the stalling daemon: (gdb) bt #0 0x0000003b298dd918 in __lll_mutex_lock_wait () from /lib64/libc.so.6 #1 0x0000003b298ce847 in _L_lock_646 () from /lib64/libc.so.6 #2 0x0000003b298ce2da in __vsyslog_chk () from /lib64/libc.so.6 #3 0x0000000000401533 in flog (level=5, format=0x402778 "Reloading rules configuration.") at cgrule sengd.c:130 #4 0x00000000004015d1 in cgre_flash_rules (signum=) at cgrulesengd.c:644 #5 #6 0x0000003b298d27b5 in send () from /lib64/libc.so.6 #7 0x0000003b298ce3a0 in __vsyslog_chk () from /lib64/libc.so.6 #8 0x0000000000401533 in flog (level=4, format=0x402b82 "Failed to open %s") at cgrulesengd.c:130 #9 0x0000000000401cc7 in cgre_process_event (ev=0x7fff8ad11cc4, type=4) at cgrulesengd.c:161 #10 0x0000000000401fd5 in cgre_create_netlink_socket_process_msg () at cgrulesengd.c:486 #11 0x00000000004023ca in main (argc=1, argv=) at cgrulesengd.c:878 (gdb) We can see __vsyslog_chk() is called twice, because the daemon recieved a SIGUSR2 signal in __vsyslog_chk(). In __vsyslog_chk(), "syslog_lock" is locked by __libc_lock_lock(syslog_lock). So I think vsyslog() should be protected by blocking the signal, and this patch fixes the problem by doing it. Thanks Ken'ichi Ohmichi Signed-off-by: Ken'ichi Ohmichi Signed-off-by: Dhaval Giani --- src/daemon/cgrulesengd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/daemon/cgrulesengd.c b/src/daemon/cgrulesengd.c index c025862..1a61476 100644 --- a/src/daemon/cgrulesengd.c +++ b/src/daemon/cgrulesengd.c @@ -126,9 +126,17 @@ void flog(int level, const char *format, ...) } if (logfacility) { + sigset_t sigset; + + sigemptyset(&sigset); + sigaddset(&sigset, SIGUSR2); + sigprocmask(SIG_BLOCK, &sigset, NULL); + va_start(ap, format); vsyslog(LOG_MAKEPRI(logfacility, level), format, ap); va_end(ap); + + sigprocmask(SIG_UNBLOCK, &sigset, NULL); } } -- cgit