On 11/16/2010 12:32 PM, Ivana Hutarova Varekova wrote:
> This patch removes perm part from cgsnapshot output if it
> is set to the default one:
>
> EXAMPLE:
> old version:
> # Configuration file generated by cgsnapshot
> mount {
>       memory = /cgroup/cpu2;
>       devices = /cgroup/cpu3;
> }
>
> group CBSFxx {
>       perm {
>               admin {
>                       uid = root;
>                       gid = root;
>               }
>               task {
>                       uid = root;
>                       gid = root;
>               }
>       }
>       devices {
>               devices.deny="a *:* rwm";
>               devices.allow="a *:* rwm";
>       }
> }
>
>
> new version:
> # Configuration file generated by cgsnapshot
> mount {
>       memory = /cgroup/cpu2;
>       devices = /cgroup/cpu3;
> }
>
> group CBSFxx {
>       devices {
>               devices.deny="a *:* rwm";
>               devices.allow="a *:* rwm";
>       }
> }
>
> Signed-off-by: Ivana Hutarova Varekova<[email protected]>

Acked-By: Jan Safranek <[email protected]>

> ---
>
>   src/tools/cgsnapshot.c |   96 
> +++++++++++++++++++++++++++---------------------
>   1 files changed, 53 insertions(+), 43 deletions(-)
>
> diff --git a/src/tools/cgsnapshot.c b/src/tools/cgsnapshot.c
> index f347b39..cb3b22d 100644
> --- a/src/tools/cgsnapshot.c
> +++ b/src/tools/cgsnapshot.c
> @@ -190,76 +190,86 @@ static int display_permissions(const char *path,
>               const char *program_name)
>   {
>       int ret;
> -     struct stat sb;
> +     struct stat sba;
> +     struct stat sbt;
>       struct passwd *pw;
>       struct group *gr;
>       char tasks_path[FILENAME_MAX];
>
> -     /* print the header */
> -     fprintf(of, "\tperm {\n");
> -
>       /* admin permissions record */
>       /* get the directory statistic */
> -     ret = stat(path,&sb);
> +     ret = stat(path,&sba);
>       if (ret) {
>               fprintf(stderr, "ERROR: can't read statistics about %s\n",
>                       path);
>               return -1;
>       }
>
> -     /* find out the user and group name */
> -     pw = getpwuid(sb.st_uid);
> -     if (pw == NULL) {
> -             fprintf(stderr, "ERROR: can't get %d user name\n", sb.st_uid);
> -             return -1;
> -     }
> -
> -     gr = getgrgid(sb.st_gid);
> -     if (gr == NULL) {
> -             fprintf(stderr, "ERROR: can't get %d group name\n", sb.st_gid);
> -             return -1;
> -     }
> -
> -     /* print the admin record */
> -     fprintf(of, "\t\tadmin {\n"\
> -             "\t\t\tuid = %s;\n"\
> -             "\t\t\tgid = %s;\n"\
> -             "\t\t}\n", pw->pw_name, gr->gr_name);
> -
>       /* tasks permissions record */
>       /* get tasks file statistic */
>       strncpy(tasks_path, path, FILENAME_MAX);
>       tasks_path[FILENAME_MAX-1] = '\0';
>       strncat(tasks_path, "/tasks", FILENAME_MAX);
>       tasks_path[FILENAME_MAX-1] = '\0';
> -
> -     ret = stat(tasks_path,&sb);
> +     ret = stat(tasks_path,&sbt);
>       if (ret) {
>               fprintf(stderr, "ERROR: can't read statistics about %s\n",
>                       tasks_path);
>               return -1;
>       }
>
> -     /* find out the user and group name */
> -     pw = getpwuid(sb.st_uid);
> -     if (pw == NULL) {
> -             fprintf(stderr, "ERROR: can't get %d user name\n", sb.st_uid);
> -             return -1;
> -     }
> +     if ((sba.st_uid) || (sba.st_gid) ||
> +             (sbt.st_uid) || (sbt.st_gid)) {
> +             /* some uid or gid is nonroot, admin permission
> +                tag is necessery */
>
> -     gr = getgrgid(sb.st_gid);
> -     if (gr == NULL) {
> -             fprintf(stderr, "ERROR: can't get %d group name\n", sb.st_gid);
> -             return -1;
> -     }
> +             /* print the header */
> +             fprintf(of, "\tperm {\n");
>
> -     /* print the task record */
> -     fprintf(of, "\t\ttask {\n"\
> -             "\t\t\tuid = %s;\n"\
> -             "\t\t\tgid = %s;\n"\
> -             "\t\t}\n", pw->pw_name, gr->gr_name);
> +             /* find out the user and group name */
> +             pw = getpwuid(sba.st_uid);
> +             if (pw == NULL) {
> +                     fprintf(stderr, "ERROR: can't get %d user name\n",
> +                             sba.st_uid);
> +                     return -1;
> +             }
> +
> +             gr = getgrgid(sba.st_gid);
> +             if (gr == NULL) {
> +                     fprintf(stderr, "ERROR: can't get %d group name\n",
> +                             sba.st_gid);
> +                     return -1;
> +             }
> +
> +             /* print the admin record */
> +             fprintf(of, "\t\tadmin {\n"\
> +                     "\t\t\tuid = %s;\n"\
> +                     "\t\t\tgid = %s;\n"\
> +                     "\t\t}\n", pw->pw_name, gr->gr_name);
> +
> +             /* find out the user and group name */
> +             pw = getpwuid(sbt.st_uid);
> +             if (pw == NULL) {
> +                     fprintf(stderr, "ERROR: can't get %d user name\n",
> +                             sbt.st_uid);
> +                     return -1;
> +             }
> +
> +             gr = getgrgid(sbt.st_gid);
> +             if (gr == NULL) {
> +                     fprintf(stderr, "ERROR: can't get %d group name\n",
> +                             sbt.st_gid);
> +                     return -1;
> +             }
>
> -     fprintf(of, "\t}\n");
> +             /* print the task record */
> +             fprintf(of, "\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");
> +     }
>
>       return 0;
>   }
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2&  L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today
> http://p.sf.net/sfu/msIE9-sfdev2dev
> _______________________________________________
> Libcg-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/libcg-devel


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to