[lxc-devel] [PATCH] Set umask before populating /dev and restore it after.

Alexander Vladimirov alexander.idkfa.vladimirov at gmail.com
Tue Jan 8 01:08:54 UTC 2013


According to docs, mknod clears each permission bit whose
corresponding bit in the process umask is set, so we should fix it
before creating device nodes.
---
 src/lxc/conf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 85d72c9..c0a270f 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -963,6 +963,7 @@ static int setup_autodev(char *root)
 	struct lxc_devs *d;
 	char path[MAXPATHLEN];
 	int i;
+	mode_t cmask;
 
 	INFO("Creating initial consoles under %s/dev\n", root);
 
@@ -974,6 +975,7 @@ static int setup_autodev(char *root)
 		run_makedev(path);
 
 	INFO("Populating /dev under %s\n", root);
+	cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
 	for (i = 0; i < sizeof(lxc_devs) / sizeof(lxc_devs[0]); i++) {
 		d = &lxc_devs[i];
 		ret = snprintf(path, MAXPATHLEN, "%s/dev/%s", root, d->name);
@@ -985,6 +987,7 @@ static int setup_autodev(char *root)
 			return -1;
 		}
 	}
+	umask(cmask);
 
 	INFO("Populated /dev under %s\n", root);
 	return 0;
-- 
1.8.1





More information about the lxc-devel mailing list