From: chris mikkelson Date: Sat, 13 Mar 2010 02:13:33 +0000 (-0600) Subject: Protected nmsg output with mutex lock, and fixed order of the flush, X-Git-Url: https://git.mikk.net/?a=commitdiff_plain;h=8cae69ba2af8982a8c7ed5778a25588ea66aeeaf;p=ssm_nmsg Protected nmsg output with mutex lock, and fixed order of the flush, close, and reopen SIGHUP dance. --- diff --git a/ssm_nmsg.c b/ssm_nmsg.c index c2cc67b..358e548 100644 --- a/ssm_nmsg.c +++ b/ssm_nmsg.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -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;