Hi,

building and running monit 4.9 on NetBSD 3.1 I encountered a problem
when sending SIGHUP to the process:

  Awakened by the SIGHUP signal
  Reinitializing monit - Control file '/usr/pkg/etc/monit/monitrc'
  monit: Debug: Adding host allow 'localhost'
  monit: Debug: Skipping redundant host 'localhost'
  Starting monit HTTP server at [localhost:2812]
  monit: Error detected by libpthread: Invalid mutex.
  Detected by file 
"/home/builds/ab/netbsd-3-0-RELEASE/src/lib/libpthread/pthread_
  mutex.c", line 334, function "pthread_mutex_unlock".
  See pthread(3) for information.
  Abort trap (core dumped)

gdb showed this backtrace:

  #0  0xbd9fe0bb in kill () from /usr/lib/libc.so.12
  #1  0xbdbe52e5 in pthread__errorfunc () from /usr/lib/libpthread.so.0
  #2  0xbdbe23d9 in pthread_mutex_unlock () from /usr/lib/libpthread.so.0
  #3  0x0804fbb9 in log_log (priority=6,
      s=0x80704a0 "Starting %s HTTP server at [%s:%d]\n",
      ap=0xbfbfe7e4 "Ðé¿¿ða\n\bü\n") at log.c:377
  #4  0x0804f98a in LogInfo (s=0x80704a0 "Starting %s HTTP server at [%s:%d]\n")
      at log.c:247
  #5  0x0804f765 in monit_http (action=1) at http.c:133
  #6  0x0805102a in do_reinit () at monitor.c:339
  #7  0x080514e9 in do_default () at monitor.c:506
  #8  0x08050ddb in main (argc=8, argv=0xbfbfe8b0) at monitor.c:119
  #9  0x0804b156 in ___start ()


After a little investigation, I came up with the following scenario:

- In log.c the mutex "log_mutex" gets initialized at program start (via
  PTHREAD_MUTEX_INITIALIZER).
- After receiving SIGHUP the function do_reinit() calls log_close()
  which destroys "log_mutex".
- Right after the call to log_close(), log_init() is called again, but
  this function does not initialize "log_mutex".
- Subsequent usage of "log_mutex" may or may not crash the process. On
  NetBSD, it does.

The appended patch fixes the problem for me, please review.

ciao
     Klaus


$NetBSD$

Initialize log_mutex dynamically in log_init(). The static initializiation
via PTHREAD_MUTEX_INITIALIZER is not sufficient because it happens only once,
at program startup.

--- log.c.orig  2007-01-03 22:02:06.000000000 +0100
+++ log.c
@@ -127,6 +127,10 @@ static void log_log(int priority, const 
  */
 int log_init() {
 
+  if (pthread_mutex_init(&log_mutex, NULL)) {
+    return FALSE; 
+  }
+
   if(!Run.dolog) {
     return TRUE;
   }
_______________________________________________
monit-dev mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/monit-dev

Reply via email to