[CRIU] test/zdtm/mountpoints: clear the umask when creating /dev/null

Yicheng Qin yichengq at google.com
Tue Aug 6 16:58:05 EDT 2013


From: Yicheng Qin <yichengq at google.com>
Subject: [PATCH] test/zdtm/mountpoints: clear the umask when creating
 /dev/null

Clear the umask when creating /dev/null and restore the umask
after the creation.

Mountpoints test unlinks and makes new /dev/null inside. But
it may happen that the default umask is not 0, e.g., 022. This means that
/dev/null created directly cannot be written by group and other users.
It is not reasonable because /dev/null should be accessable to all
users.

Signed-off-by: Yicheng Qin <yichengq at google.com>
---
 test/zdtm/live/static/mountpoints.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/test/zdtm/live/static/mountpoints.c
b/test/zdtm/live/static/mountpoints.c
index 1109711..ee75f9b 100644
--- a/test/zdtm/live/static/mountpoints.c
+++ b/test/zdtm/live/static/mountpoints.c
@@ -20,6 +20,7 @@ static int test_fn(int argc, char **argv)
        int fd, tmpfs_fd;
        unsigned fs_cnt, fs_cnt_last = 0;
        bool private = false;
+       mode_t old_mask;

 again:
        fs_cnt = 0;
@@ -121,7 +122,16 @@ done:
        }

        unlink("/dev/null");
-       mknod("/dev/null", 0777 | S_IFCHR, makedev(1, 3));
+       /*
+        * Clear umask first, create readable & writeable /dev/null,
+        * and change it back. This is done to ensure that file mode
+        * creation mask will not impede it to create file that grants
+        * read and write permission to all users.
+        */
+       old_mask = umask(0);
+       mknod("/dev/null", S_IRWXU | S_IRWXG | S_IRWXO | S_IFCHR,
+               makedev(1, 3));
+       umask(old_mask);

        setup_outfile();

-- 
1.8.3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20130806/85153038/attachment.html>


More information about the CRIU mailing list