]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc: don't do duplicate work when getting pagesize
authorChen Hanxiao <chenhanxiao@cn.fujitsu.com>
Mon, 25 Nov 2013 07:06:29 +0000 (15:06 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 25 Nov 2013 09:52:50 +0000 (10:52 +0100)
Don't do duplicate work when getting pagesize.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
src/lxc/lxc_container.c

index 2059b83518c19e503cf0bbe44660fa702412a950..0e6edbdc3ad55af71558c4561c8ad9a9b759dc05 100644 (file)
@@ -144,6 +144,7 @@ int lxcContainerHasReboot(void)
     int cmd, v;
     int status;
     char *tmp;
+    int stacksize = getpagesize() * 4;
 
     if (virFileReadAll("/proc/sys/kernel/ctrl-alt-del", 10, &buf) < 0)
         return -1;
@@ -160,10 +161,10 @@ int lxcContainerHasReboot(void)
     VIR_FREE(buf);
     cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
 
-    if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0)
+    if (VIR_ALLOC_N(stack, stacksize) < 0)
         return -1;
 
-    childStack = stack + (getpagesize() * 4);
+    childStack = stack + stacksize;
 
     cpid = clone(lxcContainerRebootChild, childStack, flags, &cmd);
     VIR_FREE(stack);
@@ -2031,6 +2032,7 @@ int lxcContainerStart(virDomainDefPtr def,
     /* allocate a stack for the container */
     if (VIR_ALLOC_N(stack, stacksize) < 0)
         return -1;
+
     stacktop = stack + stacksize;
 
     cflags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD;
@@ -2078,6 +2080,7 @@ int lxcContainerAvailable(int features)
     int cpid;
     char *childStack;
     char *stack;
+    int stacksize = getpagesize() * 4;
 
     if (features & LXC_CONTAINER_FEATURE_USER)
         flags |= CLONE_NEWUSER;
@@ -2085,12 +2088,10 @@ int lxcContainerAvailable(int features)
     if (features & LXC_CONTAINER_FEATURE_NET)
         flags |= CLONE_NEWNET;
 
-    if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) {
-        VIR_DEBUG("Unable to allocate stack");
+    if (VIR_ALLOC_N(stack, stacksize) < 0)
         return -1;
-    }
 
-    childStack = stack + (getpagesize() * 4);
+    childStack = stack + stacksize;
 
     cpid = clone(lxcContainerDummyChild, childStack, flags, NULL);
     VIR_FREE(stack);