]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
chmod_file: Introduce intelligent file permissions setting
authorMichal Hocko <mhocko@suse.cz>
Wed, 15 Jun 2011 15:24:19 +0000 (17:24 +0200)
committerJan Safranek <jsafrane@redhat.com>
Wed, 15 Jun 2011 15:24:19 +0000 (17:24 +0200)
commit3e7f4af57447d044e8cd34fe297243a9dafdce26
tree623f7b3f3df4c908ddf8872dcdd1ac794059d83e
parentc89f2e79a35d0e5f74eabdda60c7f0097791d94f
chmod_file: Introduce intelligent file permissions setting

There is no general rule on which permissions make sense for files in
different subsystems. Nevertheless the kernel creates those files with
the maximum allowed permissions for owner so we should use its part as
an umask for group and others permissions as well.
This means that if we specify 777 for file_mode we will end up having
same permissions as owner what ever they are.

The primary intelligence is implemented in cg_chmod_path function which
takes an argument which says whether user permissions should be used
as a template.

This patch adds and exports cgroup_set_permissions which sets
permissions for control and task files into the cgroup descriptor
and cgroup_create_cgroup does the rest.

Example:
/etc/cgconfig.conf:
mount {
        cpu = /cgroup/cpuctl/;
}

group devel {
        perm {
                task {
                        uid = root;
                        gid = cgroup;
                        fperm = 770;
                }
                admin {
                        uid = root;
                        gid = cgroup;
                        dperm = 775;
                        fperm = 770;
                }
        }
        cpu {
                cpu.shares = 5120;
        }
}

cd /cgroup/cpuctl/devel/
ls -la
drwxrwxr-x 2 root cgroup 0 May 19 16:42 .
drwxr-xr-x 4 root root   0 May 19 16:14 ..
-rw-rw---- 1 root cgroup 0 May 19 16:42 cgroup.clone_children
--w--w---- 1 root cgroup 0 May 19 16:42 cgroup.event_control
-r--r----- 1 root cgroup 0 May 19 16:42 cgroup.procs
-rw-rw---- 1 root cgroup 0 May 19 16:42 cpu.rt_period_us
-rw-rw---- 1 root cgroup 0 May 19 16:42 cpu.rt_runtime_us
-rw-rw---- 1 root cgroup 0 May 19 16:42 cpu.shares
-rw-rw---- 1 root cgroup 0 May 19 16:42 notify_on_release
-rw-rw---- 1 root cgroup 0 May 19 16:42 tasks

Signed-off-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
include/libcgroup/groups.h
src/api.c
src/libcgroup-internal.h
src/libcgroup.map
src/tools/cgcreate.c