aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/stats/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/stats/functions.c')
-rw-r--r--src/plugins/stats/functions.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c
index d4695ddd..1a325082 100644
--- a/src/plugins/stats/functions.c
+++ b/src/plugins/stats/functions.c
@@ -34,6 +34,8 @@ static unsigned int lsv_size;
34 34
35static GNUNET_TCP_SOCKET * sock; 35static GNUNET_TCP_SOCKET * sock;
36 36
37static Mutex lock;
38
37static int getStatValue(long long * value, 39static int getStatValue(long long * value,
38 long long * lvalue, 40 long long * lvalue,
39 cron_t * dtime, 41 cron_t * dtime,
@@ -68,9 +70,11 @@ static int getConnectedNodesStat(const void * closure,
68 char * cmh; 70 char * cmh;
69 long cval; 71 long cval;
70 72
73 MUTEX_LOCK(&lock);
71 cmh = getConfigurationOptionValue(sock, 74 cmh = getConfigurationOptionValue(sock,
72 "gnunetd", 75 "gnunetd",
73 "connection-max-hosts"); 76 "connection-max-hosts");
77 MUTEX_UNLOCK(&lock);
74 if (cmh == NULL) 78 if (cmh == NULL)
75 return SYSERR; 79 return SYSERR;
76 cval = atol(cmh); 80 cval = atol(cmh);
@@ -155,9 +159,11 @@ static int getTrafficRecvStats(const void * closure,
155 lqueries = 0; 159 lqueries = 0;
156 } 160 }
157 FREE(buffer); 161 FREE(buffer);
162 MUTEX_LOCK(&lock);
158 available = getConfigurationOptionValue(sock, 163 available = getConfigurationOptionValue(sock,
159 "LOAD", 164 "LOAD",
160 "MAXNETDOWNBPSTOTAL"); 165 "MAXNETDOWNBPSTOTAL");
166 MUTEX_UNLOCK(&lock);
161 if (available == NULL) 167 if (available == NULL)
162 return SYSERR; 168 return SYSERR;
163 band = atol(available) * dtime / cronSECONDS; 169 band = atol(available) * dtime / cronSECONDS;
@@ -241,9 +247,11 @@ static int getTrafficSendStats(const void * closure,
241 lqueries = 0; 247 lqueries = 0;
242 } 248 }
243 FREE(buffer); 249 FREE(buffer);
250 MUTEX_LOCK(&lock);
244 available = getConfigurationOptionValue(sock, 251 available = getConfigurationOptionValue(sock,
245 "LOAD", 252 "LOAD",
246 "MAXNETUPBPSTOTAL"); 253 "MAXNETUPBPSTOTAL");
254 MUTEX_UNLOCK(&lock);
247 if (available == NULL) 255 if (available == NULL)
248 return SYSERR; 256 return SYSERR;
249 band = atol(available) * dtime / cronSECONDS; 257 band = atol(available) * dtime / cronSECONDS;
@@ -310,10 +318,12 @@ static void updateStatValues(void * unused) {
310 318
311 cronTime(&now); 319 cronTime(&now);
312 delta = now - lastUpdate; 320 delta = now - lastUpdate;
321 MUTEX_LOCK(&lock);
313 if (OK == requestStatistics(sock, 322 if (OK == requestStatistics(sock,
314 &statsProcessor, 323 &statsProcessor,
315 &delta)) 324 &delta))
316 lastUpdate = now; 325 lastUpdate = now;
326 MUTEX_UNLOCK(&lock);
317} 327}
318 328
319 329
@@ -369,6 +379,7 @@ void init_functions() {
369 if (UPDATE_INTERVAL == 0) 379 if (UPDATE_INTERVAL == 0)
370 UPDATE_INTERVAL = 30 * cronSECONDS; 380 UPDATE_INTERVAL = 30 * cronSECONDS;
371 sock = getClientSocket(); 381 sock = getClientSocket();
382 MUTEX_CREATE(&lock);
372 addCronJob(&updateStatValues, 383 addCronJob(&updateStatValues,
373 UPDATE_INTERVAL, 384 UPDATE_INTERVAL,
374 UPDATE_INTERVAL, 385 UPDATE_INTERVAL,
@@ -379,6 +390,7 @@ void done_functions() {
379 delCronJob(&updateStatValues, 390 delCronJob(&updateStatValues,
380 UPDATE_INTERVAL, 391 UPDATE_INTERVAL,
381 NULL); 392 NULL);
393 MUTEX_DESTROY(&lock);
382 releaseClientSocket(sock); 394 releaseClientSocket(sock);
383 sock = NULL; 395 sock = NULL;
384} 396}