]> git.mikk.net Git - ssm_nmsg/commitdiff
Protected nmsg output with mutex lock, and fixed order of the flush,
authorchris mikkelson <chris@mikk.net>
Sat, 13 Mar 2010 02:13:33 +0000 (20:13 -0600)
committerchris mikkelson <chris@mikk.net>
Sat, 13 Mar 2010 02:13:33 +0000 (20:13 -0600)
close, and reopen SIGHUP dance.

ssm_nmsg.c

index c2cc67be4e2e1c88de0f14062444a9872f798615..358e548560b2636eb7c3f7b2797ab93480d6cbca 100644 (file)
@@ -6,6 +6,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
+#include <pthread.h>
 
 #include <netinet/in.h>
 #include <event.h>
@@ -39,18 +40,25 @@ static nmsg_output_t nmsg_out;
 static char         *nmsg_output_filename;
 static int          nmsg_output_fd = -1;
 
+static pthread_mutex_t outmtx = PTHREAD_MUTEX_INITIALIZER;
+
 static void
 ssm_nmsg_reload(void)
 {
+       pthread_mutex_lock(&outmtx);
+
+       if (nmsg_out) nmsg_output_close(&nmsg_out);
+
        if (nmsg_output_fd >= 0)
                close(nmsg_output_fd);
 
        nmsg_output_fd = open(nmsg_output_filename,
                        O_CREAT|O_WRONLY|O_APPEND, 0644);
 
-       if (nmsg_out) nmsg_output_close(&nmsg_out);
        nmsg_out = nmsg_output_open_file(nmsg_output_fd, 4096);
        nmsg_output_set_buffered(nmsg_out, 0);
+
+       pthread_mutex_unlock(&outmtx);
 }
 
 static void
@@ -143,7 +151,9 @@ ssm_nmsg_enddata(struct conn *c)
 {
        struct ssm_nmsg_state *nms = ssm_getpriv(&ss_module, c);
        if (nms && nms->msg && nmsg_out) {
+               pthread_mutex_lock(&outmtx);
                nmsg_output_write(nmsg_out, nms->msg);
+               pthread_mutex_unlock(&outmtx);
        }
        ssm_nmsg_cleanup(c);
        return SSM_PASS;