]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
bugfix: add a lock in handle_request_create, fix the rrdcached crash 456/head
authorlaiwei <laiwei.ustc@gmail.com>
Mon, 24 Mar 2014 03:47:17 +0000 (11:47 +0800)
committerlaiwei <laiwei.ustc@gmail.com>
Mon, 24 Mar 2014 03:49:37 +0000 (11:49 +0800)
src/rrd_daemon.c

index 0bc40a6b154fb191dba6176816d28f70f035903a..e9803ee44bc86965703d4ec93cda6b815f54075e 100644 (file)
@@ -271,6 +271,7 @@ static uint64_t stats_data_sets_written = 0;
 static uint64_t stats_journal_bytes = 0;
 static uint64_t stats_journal_rotate = 0;
 static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t rrdfilecreate_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static int opt_no_overwrite = 0; /* default for the daemon */
 
@@ -1929,6 +1930,7 @@ static int handle_request_create (HANDLER_PROTO) /* {{{ */
   }
   RRDD_LOG(LOG_INFO, "rrdcreate request for %s",file);
 
+  pthread_mutex_lock(&rrdfilecreate_lock);
   dir = dirname(file_copy);
   if (realpath(dir, dir_tmp) == NULL && errno == ENOENT) {
     if (!config_allow_recursive_mkdir) {
@@ -1940,6 +1942,7 @@ static int handle_request_create (HANDLER_PROTO) /* {{{ */
         return send_response(sock, RESP_ERR, "Cannot create: %s\n", dir);
     }
   }
+  pthread_mutex_unlock(&rrdfilecreate_lock);
   free(file_copy);
 
   while ((status = buffer_get_field(&buffer, &buffer_size, &tok)) == 0 && tok) {
@@ -1971,7 +1974,9 @@ static int handle_request_create (HANDLER_PROTO) /* {{{ */
   }
 
   rrd_clear_error ();
+  pthread_mutex_lock(&rrdfilecreate_lock);
   status = rrd_create_r2(file,step,last_up,no_overwrite,ac,(const char **)av);
+  pthread_mutex_unlock(&rrdfilecreate_lock);
 
   if(!status) {
     return send_response(sock, RESP_OK, "RRD created OK\n");