[LTP] [PATCH v5 1/2] cgroup_core01.c: Set system default umaks to 0

Li Wang liwang@redhat.com
Fri Mar 1 08:26:35 CET 2024


Hi Wei, Petr,

Seems the problem Wei met is the default umask of 0077,
any new files or directories that are created will have their
permission bits modified by this umask.

After looking though what you both discussed, I think maybe
another better choice is to set the umask to '0000' temporarily
before creating the directory, and then restoring the previous
umask right after.

All these operations are just put into cgroup_dir_mk function.

Something like this:

--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -368,8 +368,11 @@ static void cgroup_dir_mk(const struct cgroup_dir
*const parent,
        new->ctrl_field = parent->ctrl_field;
        new->we_created_it = 0;

+       mode_t old_umask = umask(0000);
+
        if (!mkdirat(parent->dir_fd, dir_name, 0777)) {
                new->we_created_it = 1;
+               umask(old_umask);
                goto opendir;
        }



-- 
Regards,
Li Wang


More information about the ltp mailing list