[CRIU] [PATCH 3/5] ipc: Drop u32[2] from image, simply use u64 all the time

Cyrill Gorcunov gorcunov at openvz.org
Wed Feb 1 07:24:37 EST 2012


This eliminate

 | ipc_ns.c:287:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]

and makes code simplier.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 include/image.h |    4 +-
 ipc_ns.c        |   64 +++++++++++++-----------------------------------------
 2 files changed, 18 insertions(+), 50 deletions(-)

diff --git a/include/image.h b/include/image.h
index b63e41f..607e613 100644
--- a/include/image.h
+++ b/include/image.h
@@ -111,8 +111,8 @@ struct ipc_ns_entry {
 	u32	msg_ctlmnb;
 	u32	msg_ctlmni;
 	u32	auto_msgmni;
-	u32	shm_ctlmax[2];
-	u64	shm_ctlall[2];
+	u64	shm_ctlmax;
+	u64	shm_ctlall;
 	u32	shm_ctlmni;
 	u32	shm_rmid_forced;
 	u32	mq_queues_max;
diff --git a/ipc_ns.c b/ipc_ns.c
index 88c6b06..725337c 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -284,8 +284,8 @@ static void show_ipc_entry(struct ipc_ns_entry *entry)
 	pr_info("/proc/sys/kernel/msgmnb          : %d\n", entry->msg_ctlmnb);
 	pr_info("/proc/sys/kernel/msgmni          : %d\n", entry->msg_ctlmni);
 	pr_info("/proc/sys/kernel/auto_msgmni     : %d\n", entry->auto_msgmni);
-	pr_info("/proc/sys/kernel/shmmax          : %ld\n", *(u64 *)entry->shm_ctlmax);
-	pr_info("/proc/sys/kernel/shmall          : %ld\n", *(u64 *)entry->shm_ctlall);
+	pr_info("/proc/sys/kernel/shmmax          : %ld\n",(long)entry->shm_ctlmax);
+	pr_info("/proc/sys/kernel/shmall          : %ld\n",(long)entry->shm_ctlall);
 	pr_info("/proc/sys/kernel/shmmni          : %d\n", entry->shm_ctlmni);
 	pr_info("/proc/sys/kernel/shm_rmid_forced : %d\n", entry->shm_rmid_forced);
 	pr_info("/proc/sys/fs/mqueue/queues_max   : %d\n", entry->mq_queues_max);
@@ -311,8 +311,7 @@ void show_ipc_ns(int fd)
 	pr_img_tail(CR_FD_IPCNS);
 }
 
-#ifdef CONFIG_X86_64
-static int write_ipc_sysctl_long(char *name, u64 *data)
+static int write_ipc_sysctl(char *name, long data)
 {
 	int fd;
 	int ret;
@@ -323,30 +322,8 @@ static int write_ipc_sysctl_long(char *name, u64 *data)
 		pr_perror("Can't open %s", name);
 		return fd;
 	}
-	sprintf(buf, "%ld\n", *(long *)data);
-	ret = write(fd, buf, 32);
-	if (ret < 0) {
-		pr_perror("Can't write %s", name);
-		ret = -errno;
-	}
-	close(fd);
-	return ret;
-}
-#endif
-
-static int write_ipc_sysctl(char *name, u32 *data)
-{
-	int fd;
-	int ret;
-	char buf[32];
-
-	fd = open(name, O_WRONLY);
-	if (fd < 0) {
-		pr_perror("Can't open %s", name);
-		return fd;
-	}
-	sprintf(buf, "%d\n", *(int *)data);
-	ret = write(fd, buf, 32);
+	sprintf(buf, "%ld\n", data);
+	ret = write(fd, buf, sizeof(buf));
 	if (ret < 0) {
 		pr_perror("Can't write %s", name);
 		ret = -errno;
@@ -384,46 +361,37 @@ static int prepare_ipc_tun(struct ipc_ns_entry *entry)
 	ret = write_ipc_sem(entry->sem_ctls);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/kernel/msgmax", &entry->msg_ctlmax);
+	ret = write_ipc_sysctl("/proc/sys/kernel/msgmax", (long)entry->msg_ctlmax);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/kernel/msgmnb", &entry->msg_ctlmnb);
+	ret = write_ipc_sysctl("/proc/sys/kernel/msgmnb", (long)entry->msg_ctlmnb);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/kernel/msgmni", &entry->msg_ctlmni);
+	ret = write_ipc_sysctl("/proc/sys/kernel/msgmni", (long)entry->msg_ctlmni);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/kernel/auto_msgmni", &entry->auto_msgmni);
+	ret = write_ipc_sysctl("/proc/sys/kernel/auto_msgmni", (long)entry->auto_msgmni);
 	if (ret < 0)
 		goto err;
-#ifdef CONFIG_X86_64
-	ret = write_ipc_sysctl_long("/proc/sys/kernel/shmmax", (u64 *)entry->shm_ctlmax);
+	ret = write_ipc_sysctl("/proc/sys/kernel/shmmax", (long)entry->shm_ctlmax);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl_long("/proc/sys/kernel/shmall", (u64 *)entry->shm_ctlall);
-#else
-	ret = write_ipc_sysctl("/proc/sys/kernel/shmmax", entry->shm_ctlmax);
-	if (ret < 0)
-		goto err;
-	ret = write_ipc_sysctl("/proc/sys/kernel/shmall", entry->shm_ctlall);
-#endif
+	ret = write_ipc_sysctl("/proc/sys/kernel/shmall", (long)entry->shm_ctlall);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/kernel/shmmni", &entry->shm_ctlmni);
+	ret = write_ipc_sysctl("/proc/sys/kernel/shmmni", (long)entry->shm_ctlmni);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/kernel/shm_rmid_forced", &entry->shm_rmid_forced);
+	ret = write_ipc_sysctl("/proc/sys/kernel/shm_rmid_forced", (long)entry->shm_rmid_forced);
 	if (ret < 0)
 		goto err;
-
-
-	ret = write_ipc_sysctl("/proc/sys/fs/mqueue/queues_max", &entry->mq_queues_max);
+	ret = write_ipc_sysctl("/proc/sys/fs/mqueue/queues_max", (long)entry->mq_queues_max);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/fs/mqueue/msg_max", &entry->mq_msg_max);
+	ret = write_ipc_sysctl("/proc/sys/fs/mqueue/msg_max", (long)entry->mq_msg_max);
 	if (ret < 0)
 		goto err;
-	ret = write_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_max", &entry->mq_msgsize_max);
+	ret = write_ipc_sysctl("/proc/sys/fs/mqueue/msgsize_max", (long)entry->mq_msgsize_max);
 	if (ret < 0)
 		goto err;
 
-- 
1.7.7.6



More information about the CRIU mailing list