Issue 329: Reducing scope of variables in action-scripts.c

Submitted by Harshavardhan Unnibhavi on March 9, 2019, 8:09 a.m.

Details

Message ID 20190309080919.26882-1-hvubfoss@gmail.com
State Accepted
Series "Issue 329: Reducing scope of variables in action-scripts.c"
Headers show

Commit Message

Harshavardhan Unnibhavi March 9, 2019, 8:09 a.m.
Signed-off-by: Harshavardhan Unnibhavi <hvubfoss@gmail.com>
---
 criu/action-scripts.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

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);

Comments

Andrei Vagin March 15, 2019, 4:47 p.m.
you need to move "Issue 329" from the subject to the body,
so the subject will look like this:
action-scripts: Reducing scope of variables

I would like to see a full link to the issue, it is more convinient if
we read the history from a terminal.

On Sat, Mar 09, 2019 at 01:39:19PM +0530, Harshavardhan Unnibhavi wrote:
> Signed-off-by: Harshavardhan Unnibhavi <hvubfoss@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
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
Andrei Vagin March 17, 2019, 5:13 a.m.
Applied, thanks!

On Sat, Mar 09, 2019 at 01:39:19PM +0530, Harshavardhan Unnibhavi wrote:
> Signed-off-by: Harshavardhan Unnibhavi <hvubfoss@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
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu