From: Christian Brauner Date: Sat, 20 Oct 2018 09:28:11 +0000 (+0200) Subject: tools/lxc_top: do not hide global variable X-Git-Tag: lxc-3.1.0~29^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=551105ff4639d1f64c97d6dd50dc30534e575c4a;p=thirdparty%2Flxc.git tools/lxc_top: do not hide global variable Signed-off-by: Christian Brauner --- diff --git a/src/lxc/tools/lxc_top.c b/src/lxc/tools/lxc_top.c index 9fad3a433..41ff10139 100644 --- a/src/lxc/tools/lxc_top.c +++ b/src/lxc/tools/lxc_top.c @@ -73,7 +73,7 @@ struct stats { struct blkio_stats io_serviced; }; -struct ct { +struct container_stats { struct lxc_container *c; struct stats *stats; }; @@ -84,7 +84,7 @@ static int delay = 3; static char sort_by = 'n'; static int sort_reverse = 0; static struct termios oldtios; -static struct ct *ct = NULL; +static struct container_stats *container_stats = NULL; static int ct_alloc_cnt = 0; static int my_parser(struct lxc_arguments *args, int c, char *arg) @@ -336,7 +336,7 @@ out: return; } -static void stats_get(struct lxc_container *c, struct ct *ct, struct stats *total) +static void stats_get(struct lxc_container *c, struct container_stats *ct, struct stats *total) { ct->c = c; ct->stats->mem_used = stat_get_int(c, "memory.usage_in_bytes"); @@ -448,8 +448,8 @@ static void stats_print(const char *name, const struct stats *stats, static int cmp_name(const void *sct1, const void *sct2) { - const struct ct *ct1 = sct1; - const struct ct *ct2 = sct2; + const struct container_stats *ct1 = sct1; + const struct container_stats *ct2 = sct2; if (sort_reverse) return strncmp(ct2->c->name, ct1->c->name, strlen(ct2->c->name)); @@ -459,8 +459,8 @@ static int cmp_name(const void *sct1, const void *sct2) static int cmp_cpuuse(const void *sct1, const void *sct2) { - const struct ct *ct1 = sct1; - const struct ct *ct2 = sct2; + const struct container_stats *ct1 = sct1; + const struct container_stats *ct2 = sct2; if (sort_reverse) return ct2->stats->cpu_use_nanos < ct1->stats->cpu_use_nanos; @@ -470,8 +470,8 @@ static int cmp_cpuuse(const void *sct1, const void *sct2) static int cmp_blkio(const void *sct1, const void *sct2) { - const struct ct *ct1 = sct1; - const struct ct *ct2 = sct2; + const struct container_stats *ct1 = sct1; + const struct container_stats *ct2 = sct2; if (sort_reverse) return ct2->stats->io_service_bytes.total < ct1->stats->io_service_bytes.total; @@ -481,8 +481,8 @@ static int cmp_blkio(const void *sct1, const void *sct2) static int cmp_memory(const void *sct1, const void *sct2) { - const struct ct *ct1 = sct1; - const struct ct *ct2 = sct2; + const struct container_stats *ct1 = sct1; + const struct container_stats *ct2 = sct2; if (sort_reverse) return ct2->stats->mem_used < ct1->stats->mem_used; @@ -492,8 +492,8 @@ static int cmp_memory(const void *sct1, const void *sct2) static int cmp_memorysw(const void *sct1, const void *sct2) { - const struct ct *ct1 = sct1; - const struct ct *ct2 = sct2; + const struct container_stats *ct1 = sct1; + const struct container_stats *ct2 = sct2; if (sort_reverse) return ct2->stats->memsw_used < ct1->stats->memsw_used; @@ -503,8 +503,8 @@ static int cmp_memorysw(const void *sct1, const void *sct2) static int cmp_kmemory(const void *sct1, const void *sct2) { - const struct ct *ct1 = sct1; - const struct ct *ct2 = sct2; + const struct container_stats *ct1 = sct1; + const struct container_stats *ct2 = sct2; if (sort_reverse) return ct2->stats->kmem_used < ct1->stats->kmem_used; @@ -526,7 +526,7 @@ static void ct_sort(int active) case 'k': cmp_func = cmp_kmemory; break; } - qsort(ct, active, sizeof(*ct), (int (*)(const void *,const void *))cmp_func); + qsort(container_stats, active, sizeof(*container_stats), (int (*)(const void *,const void *))cmp_func); } static void ct_free(void) @@ -534,13 +534,13 @@ static void ct_free(void) int i; for (i = 0; i < ct_alloc_cnt; i++) { - if (ct[i].c) { - lxc_container_put(ct[i].c); - ct[i].c = NULL; + if (container_stats[i].c) { + lxc_container_put(container_stats[i].c); + container_stats[i].c = NULL; } - free(ct[i].stats); - ct[i].stats = NULL; + free(container_stats[i].stats); + container_stats[i].stats = NULL; } } @@ -551,15 +551,15 @@ static void ct_realloc(int active_cnt) ct_free(); - ct = realloc(ct, sizeof(*ct) * active_cnt); - if (!ct) { + container_stats = realloc(container_stats, sizeof(*container_stats) * active_cnt); + if (!container_stats) { fprintf(stderr, "Cannot alloc mem\n"); exit(EXIT_FAILURE); } for (i = 0; i < active_cnt; i++) { - ct[i].stats = malloc(sizeof(*ct[0].stats)); - if (!ct[i].stats) { + container_stats[i].stats = malloc(sizeof(*container_stats[0].stats)); + if (!container_stats[i].stats) { fprintf(stderr, "Cannot alloc mem\n"); exit(EXIT_FAILURE); } @@ -640,7 +640,7 @@ int main(int argc, char *argv[]) memset(&total, 0, sizeof(total)); for (i = 0; i < active_cnt; i++) - stats_get(active[i], &ct[i], &total); + stats_get(active[i], &container_stats[i], &total); ct_sort(active_cnt); @@ -650,7 +650,7 @@ int main(int argc, char *argv[]) } for (i = 0; i < active_cnt && i < ct_print_cnt; i++) { - stats_print(ct[i].c->name, ct[i].stats, &total); + stats_print(container_stats[i].c->name, container_stats[i].stats, &total); printf("\n"); } @@ -661,8 +661,8 @@ int main(int argc, char *argv[]) fflush(stdout); for (i = 0; i < active_cnt; i++) { - lxc_container_put(ct[i].c); - ct[i].c = NULL; + lxc_container_put(container_stats[i].c); + container_stats[i].c = NULL; } in_char = '\0';