From: Kamalesh Babulal Date: Mon, 14 Feb 2022 15:10:43 +0000 (-0700) Subject: tools/cgsnapshot: rename FILE *of to output_f X-Git-Tag: v3.0~203 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26d886e35218c08e20363ee73a64e6cc4b6f7686;p=thirdparty%2Flibcgroup.git tools/cgsnapshot: rename FILE *of to output_f LGTM, complained about using FILE *of as shorthand for the output file and recommended using something descriptive. Rename usage of with output_f, to keep it happy. Reported-by: LGTM Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c index a15ab2f0..9f7a64e9 100644 --- a/src/tools/cgsnapshot.c +++ b/src/tools/cgsnapshot.c @@ -48,7 +48,7 @@ struct black_list_type *white_list; typedef char cont_name_t[FILENAME_MAX]; int flags; -FILE *of; +FILE *output_f; /* * Display the usage @@ -247,7 +247,7 @@ static int display_permissions(const char *path, const char * const cg_name, tag is necessery */ /* print the header */ - fprintf(of, "\tperm {\n"); + fprintf(output_f, "\tperm {\n"); /* find out the user and group name */ pw = getpwuid(sba.st_uid); @@ -265,7 +265,7 @@ static int display_permissions(const char *path, const char * const cg_name, } /* print the admin record */ - fprintf(of, "\t\tadmin {\n"\ + fprintf(output_f, "\t\tadmin {\n"\ "\t\t\tuid = %s;\n"\ "\t\t\tgid = %s;\n"\ "\t\t}\n", pw->pw_name, gr->gr_name); @@ -286,12 +286,12 @@ static int display_permissions(const char *path, const char * const cg_name, } /* print the task record */ - fprintf(of, "\t\ttask {\n"\ + fprintf(output_f, "\t\ttask {\n"\ "\t\t\tuid = %s;\n"\ "\t\t\tgid = %s;\n"\ "\t\t}\n", pw->pw_name, gr->gr_name); - fprintf(of, "\t}\n"); + fprintf(output_f, "\t}\n"); } return 0; @@ -321,7 +321,7 @@ static int display_cgroup_data(struct cgroup *group, struct stat sb; /* print the group definition header */ - fprintf(of, "group %s {\n", group->name); + fprintf(output_f, "group %s {\n", group->name); /* for all wanted controllers display controllers tag */ while (controller[i][0] != '\0') { @@ -343,9 +343,9 @@ static int display_cgroup_data(struct cgroup *group, /* print the controller header */ if (strncmp(controller[i], "name=", 5) == 0) - fprintf(of, "\t\"%s\" {\n", controller[i]); + fprintf(output_f, "\t\"%s\" {\n", controller[i]); else - fprintf(of, "\t%s {\n", controller[i]); + fprintf(output_f, "\t%s {\n", controller[i]); i++; nr_var = cgroup_get_value_name_count(group_controller); @@ -416,7 +416,7 @@ static int display_cgroup_data(struct cgroup *group, } if (strcmp("devices.list", name) == 0) { output_name = "devices.allow"; - fprintf(of, + fprintf(output_f, "\t\tdevices.deny=\"a *:* rwm\";\n"); } @@ -431,14 +431,14 @@ static int display_cgroup_data(struct cgroup *group, name); goto err; } - fprintf(of, "\t\t%s=\"%s\";\n", output_name, value); + fprintf(output_f, "\t\t%s=\"%s\";\n", output_name, value); free(value); } - fprintf(of, "\t}\n"); + fprintf(output_f, "\t}\n"); } /* tail of the record */ - fprintf(of, "}\n\n"); + fprintf(output_f, "}\n\n"); err: return ret; @@ -614,9 +614,9 @@ static int show_mountpoints(const char *controller) while (ret == 0) { if (quote) - fprintf(of, "\t\"%s\" = %s;\n", controller, path); + fprintf(output_f, "\t\"%s\" = %s;\n", controller, path); else - fprintf(of, "\t%s = %s;\n", controller, path); + fprintf(output_f, "\t%s = %s;\n", controller, path); ret = cgroup_get_subsys_mount_point_next(&handle, path); } cgroup_get_subsys_mount_point_end(&handle); @@ -675,7 +675,7 @@ static int parse_mountpoints(cont_name_t cont_names[CG_CONTROLLER_MAX], struct cgroup_mount_point mount; /* start mount section */ - fprintf(of, "mount {\n"); + fprintf(output_f, "mount {\n"); /* go through the controller list */ ret = cgroup_get_all_controller_begin(&handle, &info); @@ -717,7 +717,7 @@ static int parse_mountpoints(cont_name_t cont_names[CG_CONTROLLER_MAX], cgroup_get_controller_end(&handle); /* finish mount section */ - fprintf(of, "}\n\n"); + fprintf(output_f, "}\n\n"); return final_ret; } @@ -772,8 +772,8 @@ int main(int argc, char *argv[]) break; case 'f': flags |= FL_OUTPUT; - of = fopen(optarg, "w"); - if (of == NULL) { + output_f = fopen(optarg, "w"); + if (output_f == NULL) { fprintf(stderr, "%s: Failed to open file %s\n", argv[0], optarg); return ECGOTHER; @@ -799,7 +799,7 @@ int main(int argc, char *argv[]) } if ((flags & FL_OUTPUT) == 0) - of = stdout; + output_f = stdout; /* blacklkist */ if (flags & FL_BLACK) { @@ -818,7 +818,7 @@ int main(int argc, char *argv[]) goto finish; /* print the header */ - fprintf(of, "# Configuration file generated by cgsnapshot\n"); + fprintf(output_f, "# Configuration file generated by cgsnapshot\n"); /* initialize libcgroup */ ret = cgroup_init(); @@ -840,8 +840,8 @@ finish: free_list(black_list); free_list(white_list); - if (of != stdout) - fclose(of); + if (output_f != stdout) + fclose(output_f); return ret; }