Skip to content

Commit 7c3c3c3

Browse files
committed
Merge pull request #176 from acv/refactor-status
Use new client list cloning for status.
2 parents 2d5f45f + e516491 commit 7c3c3c3

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/util.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ get_status_text()
381381
pstr_t *pstr = pstr_new();
382382
s_config *config;
383383
t_auth_serv *auth_server;
384-
t_client *first;
384+
t_client *sublist, *current;
385385
int count;
386386
time_t uptime = 0;
387387
unsigned int days = 0, hours = 0, minutes = 0, seconds = 0;
@@ -414,35 +414,26 @@ get_status_text()
414414

415415
LOCK_CLIENT_LIST();
416416

417-
first = client_get_first_client();
417+
count = client_list_dup(&sublist);
418418

419-
if (first == NULL) {
420-
count = 0;
421-
} else {
422-
count = 1;
423-
while (first->next != NULL) {
424-
first = first->next;
425-
count++;
426-
}
427-
}
419+
UNLOCK_CLIENT_LIST();
428420

429-
pstr_append_sprintf(pstr, "%d clients " "connected.\n", count);
421+
current = sublist;
430422

431-
first = client_get_first_client();
423+
pstr_append_sprintf(pstr, "%d clients " "connected.\n", count);
432424

433-
count = 0;
434-
while (first != NULL) {
425+
count = 1;
426+
while (current != NULL) {
435427
pstr_append_sprintf(pstr, "\nClient %d\n", count);
436-
pstr_append_sprintf(pstr, " IP: %s MAC: %s\n", first->ip, first->mac);
437-
pstr_append_sprintf(pstr, " Token: %s\n", first->token);
438-
pstr_append_sprintf(pstr, " Downloaded: %llu\n Uploaded: %llu\n", first->counters.incoming,
439-
first->counters.outgoing);
440-
428+
pstr_append_sprintf(pstr, " IP: %s MAC: %s\n", current->ip, current->mac);
429+
pstr_append_sprintf(pstr, " Token: %s\n", current->token);
430+
pstr_append_sprintf(pstr, " Downloaded: %llu\n Uploaded: %llu\n", current->counters.incoming,
431+
current->counters.outgoing);
441432
count++;
442-
first = first->next;
433+
current = current->next;
443434
}
444435

445-
UNLOCK_CLIENT_LIST();
436+
client_list_destroy(sublist);
446437

447438
config = config_get_config();
448439

0 commit comments

Comments
 (0)