[CRIU] [PATCH] Issue 329: Reducing scope of variables in action-scripts.c

Harshavardhan Unnibhavi hvubfoss at gmail.com
Sat Mar 9 11:09:19 MSK 2019


Signed-off-by: Harshavardhan Unnibhavi <hvubfoss at gmail.com>
---
 criu/action-scripts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/criu/action-scripts.c b/criu/action-scripts.c
index 2803ec0f..2f7617c0 100644
--- a/criu/action-scripts.c
+++ b/criu/action-scripts.c
@@ -49,7 +49,6 @@ static int run_shell_scripts(const char *action)
 {
 	int retval = 0;
 	struct script *script;
-	char image_dir[PATH_MAX];
 	static unsigned env_set = 0;
 
 #define ENV_IMGDIR	0x1
@@ -61,6 +60,7 @@ static int run_shell_scripts(const char *action)
 	}
 
 	if (!(env_set & ENV_IMGDIR)) {
+		char image_dir[PATH_MAX];
 		sprintf(image_dir, "/proc/%ld/fd/%d", (long) getpid(), get_service_fd(IMG_FD_OFF));
 		if (setenv("CRTOOLS_IMAGE_DIR", image_dir, 1)) {
 			pr_perror("Can't set CRTOOLS_IMAGE_DIR=%s", image_dir);
@@ -71,10 +71,10 @@ static int run_shell_scripts(const char *action)
 
 	if (!(env_set & ENV_ROOTPID) && root_item) {
 		int pid;
-		char root_item_pid[16];
 
 		pid = root_item->pid->real;
 		if (pid != -1) {
+			char root_item_pid[16];
 			snprintf(root_item_pid, sizeof(root_item_pid), "%d", pid);
 			if (setenv("CRTOOLS_INIT_PID", root_item_pid, 1)) {
 				pr_perror("Can't set CRTOOLS_INIT_PID=%s", root_item_pid);
-- 
2.17.1



More information about the CRIU mailing list