[CRIU] [PATCH 1/2] zdtm: use syscalls to set hostname and domaninname

Andrey Vagin avagin at openvz.org
Mon Oct 26 06:30:04 PDT 2015


From: Andrew Vagin <avagin at openvz.org>

We don't have enough permissions to set sysctl-s from userns

Signed-off-by: Andrew Vagin <avagin at openvz.org>
---
 test/zdtm.sh                    |  1 -
 test/zdtm/live/static/utsname.c | 29 ++++-------------------------
 2 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 4ed8a7b..cf37f74 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -293,7 +293,6 @@ generate_test_list()
 		ns/static/cow01
 		ns/static/tempfs_ro
 		ns/static/ipc_namespace
-		ns/static/utsname
 	"
 
 	# Add tests which can be executed in an user namespace
diff --git a/test/zdtm/live/static/utsname.c b/test/zdtm/live/static/utsname.c
index 5fedb02..5e1e0cb 100644
--- a/test/zdtm/live/static/utsname.c
+++ b/test/zdtm/live/static/utsname.c
@@ -15,39 +15,18 @@ static struct utsname after;
 
 int main(int argc, char **argv)
 {
-	int ret;
-	int fd;
-
 	test_init(argc, argv);
 
-	fd = open("/proc/sys/kernel/hostname", O_WRONLY);
-	if (fd < 0) {
-		pr_perror("Can't open hostname");
-		return 1;
-	}
-
-	ret = write(fd, ZDTM_NODE, sizeof(ZDTM_NODE));
-	if (ret != sizeof(ZDTM_NODE)) {
-		pr_perror("Can't write nodename");
+	if (sethostname(ZDTM_NODE, sizeof(ZDTM_NODE))) {
+		pr_perror("Unable to set hostname");
 		return 1;
 	}
 
-	close(fd);
-
-	fd = open("/proc/sys/kernel/domainname", O_WRONLY);
-	if (fd < 0) {
-		pr_perror("Can't open domainname");
-		return -errno;
-	}
-
-	ret = write(fd, ZDTM_DOMAIN, sizeof(ZDTM_DOMAIN));
-	if (ret != sizeof(ZDTM_DOMAIN)) {
-		pr_perror("Can't write domainname");
+	if (setdomainname(ZDTM_DOMAIN, sizeof(ZDTM_DOMAIN))) {
+		pr_perror("Unable to set domainname");
 		return 1;
 	}
 
-	close(fd);
-
 	test_daemon();
 	test_waitsig();
 
-- 
2.4.3



More information about the CRIU mailing list