[rrd-developers] [PATCH] Handle race condition for "UPDATE" with new files. -- Sebastian Harl

Tobias Oetiker tobi at oetiker.ch
Tue Jul 14 14:01:10 CEST 2009


Hi Kevin,

thanks for the patch, its in

cheers
tobi

Today kevin brintnall wrote:

> ---
>  src/rrd_daemon.c |   12 +++++++++++-
>  1 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/src/rrd_daemon.c b/src/rrd_daemon.c
> index 17ec97e..8b1fc9e 100644
> --- a/src/rrd_daemon.c
> +++ b/src/rrd_daemon.c
> @@ -1314,6 +1314,7 @@ static int handle_request_update (HANDLER_PROTO) /* {{{ */
>    if (ci == NULL) /* {{{ */
>    {
>      struct stat statbuf;
> +    cache_item_t *tmp;
>
>      /* don't hold the lock while we setup; stat(2) might block */
>      pthread_mutex_unlock(&cache_lock);
> @@ -1361,7 +1362,16 @@ static int handle_request_update (HANDLER_PROTO) /* {{{ */
>      pthread_cond_init(&ci->flushed, NULL);
>
>      pthread_mutex_lock(&cache_lock);
> -    g_tree_replace (cache_tree, (void *) ci->file, (void *) ci);
> +
> +    /* another UPDATE might have added this entry in the meantime */
> +    tmp = g_tree_lookup (cache_tree, file);
> +    if (tmp == NULL)
> +      g_tree_replace (cache_tree, (void *) ci->file, (void *) ci);
> +    else
> +    {
> +      free_cache_item (ci);
> +      ci = tmp;
> +    }
>    } /* }}} */
>    assert (ci != NULL);
>
>

-- 
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
http://it.oetiker.ch tobi at oetiker.ch ++41 62 775 9902 / sb: -9900



More information about the rrd-developers mailing list