Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Varnish: Dev

[PATCH] Lock panic buffer before mangling it

 

 

Varnish dev RSS feed   Index | Next | Previous | View Threaded


tfheen at varnish-software

Aug 19, 2011, 6:17 AM

Post #1 of 2 (276 views)
Permalink
[PATCH] Lock panic buffer before mangling it

If we were panic-ing in multiple threads at the same time, the panic
buffer would be partially overwritten. Prevent this with a mutex
---
bin/varnishd/cache_panic.c | 5 +++++
bin/varnishd/cache_shmlog.c | 2 +-
2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/bin/varnishd/cache_panic.c b/bin/varnishd/cache_panic.c
index c443b67..9279029 100644
--- a/bin/varnishd/cache_panic.c
+++ b/bin/varnishd/cache_panic.c
@@ -34,6 +34,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <pthread.h>

#ifndef HAVE_EXECINFO_H
#include "compat/execinfo.h"
@@ -56,6 +57,7 @@
*/

static struct vsb vsps, *vsp;
+pthread_mutex_t panicstr_mtx = PTHREAD_MUTEX_INITIALIZER;

/*--------------------------------------------------------------------*/

@@ -294,6 +296,9 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
const char *q;
const struct sess *sp;

+ AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released,
+ we're going to die
+ anyway */
switch(xxx) {
case 3:
VSB_printf(vsp,
diff --git a/bin/varnishd/cache_shmlog.c b/bin/varnishd/cache_shmlog.c
index e0b332d..023c20a 100644
--- a/bin/varnishd/cache_shmlog.c
+++ b/bin/varnishd/cache_shmlog.c
@@ -288,7 +288,7 @@ VSL_Init(void)

vsl_wrap();
VSM_head->starttime = (intmax_t)TIM_real();
- VSM_head->panicstr[0] = '\0';
+ memset(VSM_head->panicstr, '\0', sizeof *VSM_head->panicstr);
memset(VSC_C_main, 0, sizeof *VSC_C_main);
VSM_head->child_pid = getpid();
}
--
1.7.5.4


_______________________________________________
varnish-dev mailing list
varnish-dev [at] varnish-cache
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev


phk at phk

Aug 19, 2011, 9:46 AM

Post #2 of 2 (274 views)
Permalink
Re: [PATCH] Lock panic buffer before mangling it [In reply to]

In message <1313759878-7836-1-git-send-email-tfheen [at] varnish-software>, Toll
ef Fog Heen writes:

Go for it...


>If we were panic-ing in multiple threads at the same time, the panic
>buffer would be partially overwritten. Prevent this with a mutex
>---
> bin/varnishd/cache_panic.c | 5 +++++
> bin/varnishd/cache_shmlog.c | 2 +-
> 2 files changed, 6 insertions(+), 1 deletions(-)
>
>diff --git a/bin/varnishd/cache_panic.c b/bin/varnishd/cache_panic.c
>index c443b67..9279029 100644
>--- a/bin/varnishd/cache_panic.c
>+++ b/bin/varnishd/cache_panic.c
>@@ -34,6 +34,7 @@
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
>+#include <pthread.h>
>
> #ifndef HAVE_EXECINFO_H
> #include "compat/execinfo.h"
>@@ -56,6 +57,7 @@
> */
>
> static struct vsb vsps, *vsp;
>+pthread_mutex_t panicstr_mtx = PTHREAD_MUTEX_INITIALIZER;
>
> /*--------------------------------------------------------------------*/
>
>@@ -294,6 +296,9 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
> const char *q;
> const struct sess *sp;
>
>+ AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released,
>+ we're going to die
>+ anyway */
> switch(xxx) {
> case 3:
> VSB_printf(vsp,
>diff --git a/bin/varnishd/cache_shmlog.c b/bin/varnishd/cache_shmlog.c
>index e0b332d..023c20a 100644
>--- a/bin/varnishd/cache_shmlog.c
>+++ b/bin/varnishd/cache_shmlog.c
>@@ -288,7 +288,7 @@ VSL_Init(void)
>
> vsl_wrap();
> VSM_head->starttime = (intmax_t)TIM_real();
>- VSM_head->panicstr[0] = '\0';
>+ memset(VSM_head->panicstr, '\0', sizeof *VSM_head->panicstr);
> memset(VSC_C_main, 0, sizeof *VSC_C_main);
> VSM_head->child_pid = getpid();
> }
>--
>1.7.5.4
>
>
>_______________________________________________
>varnish-dev mailing list
>varnish-dev [at] varnish-cache
>https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev
>

--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk [at] FreeBSD | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.

_______________________________________________
varnish-dev mailing list
varnish-dev [at] varnish-cache
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Varnish dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.