On 09/02/2010 12:17 PM, Ivana Hutarova Varekova wrote:
> This patch rework cgget to use cgroup_read_vars_{begin/next/end}
> iterators - it fix the problem with long variables (like e.g. devices.list)
> it also fixes the bug in stat file reading (it shows the variables in root
> directory all time)
>
> Signed-off-by: Ivana Hutarova Varekova<[email protected]>
> ---
>
> src/tools/cgget.c | 61
> ++++++++++++++++++++++++-----------------------------
> 1 files changed, 28 insertions(+), 33 deletions(-)
>
> diff --git a/src/tools/cgget.c b/src/tools/cgget.c
> index 3e76f81..2cc4d7c 100644
> --- a/src/tools/cgget.c
> +++ b/src/tools/cgget.c
> @@ -13,6 +13,7 @@
> #define MODE_SHOW_NAMES 2
> #define MODE_SHOW_ALL_CONTROLLERS 4
>
> +#define LL_MAX 100
>
>
> static void usage(int status, const char *program_name)
> {
> @@ -27,50 +28,44 @@ static void usage(int status, const char *program_name)
> }
>
> static int display_one_record(char *name, struct cgroup_controller
> *group_controller,
> - const char *program_name, int mode)
> + const char *group_name, const char *program_name, int mode)
> {
> - int ret;
> - char *value = NULL;
> -
> - ret = cgroup_get_value_string(group_controller, name,&value);
> - if (ret != 0) {
> - fprintf(stderr, "%s: cannot read parameter '%s' "\
> - "from group '%s': %s\n", program_name, name,
> - group_controller->name, cgroup_strerror(ret));
> - return ret;
> - }
> + int ret = 0;
> + void *handle;
> + char line[LL_MAX];
>
> if (mode& MODE_SHOW_NAMES)
> - printf("%s=", name);
> + printf("%s: ", name);
>
> - if (strcmp(strchr(name, '.')+1, "stat"))
> - printf("%s\n", value);
> + ret = cgroup_read_value_begin(group_controller->name,
> + group_name, name,&handle, line, LL_MAX);
>
> - else {
> - void *handle;
> - struct cgroup_stat stat;
> -
> - ret = cgroup_read_stats_begin(group_controller->name,
> - "/",&handle,&stat);
> - if (ret != 0) {
> - fprintf(stderr, "stats read failed\n");
> - return ret;
> - }
> - printf("%s %s", stat.name, stat.value);
> + if (ret == ECGEOF) {
> + ret = 0;
> + goto read_end;
> + }
>
> - while ((ret = cgroup_read_stats_next(&handle,&stat)) !=
> - ECGEOF) {
> - printf("\t%s %s", stat.name, stat.value);
> - }
> + if (ret != 0) {
> + fprintf(stderr, "variable file read failed %d\n", ret);
> + return ret;
> + }
> + printf("%s", line);
>
> - cgroup_read_stats_end(&handle);
> + while ((ret = cgroup_read_value_next(&handle, line, LL_MAX)) !=
> + ECGEOF) {
cgroup_read_value_next might return also different error than ECGEOF!
I.e. while (ret = cgroup_read_value_next(..) == 0) is better.
> + printf("\t%s", line);
I am not sure LL_MAX == 100 wouldn't cause problems in future... If a
line in the file is longer than 100 charactes, it will be shown with
'\t' in the middle. Maybe I am just paranoind :).
> }
>
> - free(value);
> + if (ret == ECGEOF)
> + ret = 0;
> +read_end:
> +
> + cgroup_read_value_end(&handle);
> return ret;
> }
>
>
> +
> static int display_name_values(char **names, int count, const char*
> group_name,
> const char *program_name, int mode)
> {
> @@ -124,7 +119,7 @@ static int display_name_values(char **names, int count,
> const char* group_name,
>
> /* Finally read the parameter value.*/
> ret = display_one_record(names[i], group_controller,
> - program_name, mode);
> + group_name, program_name, mode);
> if (ret != 0)
> goto err;
> }
> @@ -181,7 +176,7 @@ static int display_controller_values(char **controllers,
> int count,
> name = cgroup_get_value_name(group_controller, i);
> if (name != NULL) {
> ret = display_one_record(name, group_controller,
> - program_name, mode);
> + group_name, program_name, mode);
> if (ret) {
> result = ret;
> goto err;
>
>
> ------------------------------------------------------------------------------
> This SF.net Dev2Dev email is sponsored by:
>
> Show off your parallel programming skills.
> Enter the Intel(R) Threading Challenge 2010.
> http://p.sf.net/sfu/intel-thread-sfd
> _______________________________________________
> Libcg-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel