[1/2] scripts: Do not set -1 as root item pid

Submitted by Pavel Emelianov on April 28, 2016, 2:46 p.m.

Details

Message ID 57222242.8060902@virtuozzo.com
State Accepted
Series "Series without cover letter"
Commit 54649842020e8fe5ee6940f85a5d3c552e9061ed
Headers show

Commit Message

Pavel Emelianov April 28, 2016, 2:46 p.m.
On restore root_item may exist, but its real pid is not yet resolved
Fixes e5e8f791.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/action-scripts.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/action-scripts.c b/criu/action-scripts.c
index aa64703..ee59210 100644
--- a/criu/action-scripts.c
+++ b/criu/action-scripts.c
@@ -44,7 +44,6 @@  static int run_shell_scripts(const char *action)
 	int ret = 0;
 	struct script *script;
 	char image_dir[PATH_MAX];
-	char root_item_pid[16];
 	static unsigned env_set = 0;
 
 #define ENV_IMGDIR	0x1
@@ -65,12 +64,18 @@  static int run_shell_scripts(const char *action)
 	}
 
 	if (!(env_set & ENV_ROOTPID) && root_item) {
-		snprintf(root_item_pid, sizeof(root_item_pid), "%d", root_item->pid.real);
-		if (setenv("CRTOOLS_INIT_PID", root_item_pid, 1)) {
-			pr_perror("Can't set CRTOOLS_INIT_PID=%s", root_item_pid);
-			return -1;
+		int pid;
+		char root_item_pid[16];
+
+		pid = root_item->pid.real;
+		if (pid != -1) {
+			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);
+				return -1;
+			}
+			env_set |= ENV_ROOTPID;
 		}
-		env_set |= ENV_ROOTPID;
 	}
 
 	list_for_each_entry(script, &scripts, node) {

Comments

Andrey Vagin April 28, 2016, 8:33 p.m.
Acked-by: Andrew Vagin <avagin@virtuozzo.com>

On Thu, Apr 28, 2016 at 05:46:26PM +0300, Pavel Emelyanov wrote:
> On restore root_item may exist, but its real pid is not yet resolved
> Fixes e5e8f791.
> 
> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
> ---
>  criu/action-scripts.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/criu/action-scripts.c b/criu/action-scripts.c
> index aa64703..ee59210 100644
> --- a/criu/action-scripts.c
> +++ b/criu/action-scripts.c
> @@ -44,7 +44,6 @@ static int run_shell_scripts(const char *action)
>  	int ret = 0;
>  	struct script *script;
>  	char image_dir[PATH_MAX];
> -	char root_item_pid[16];
>  	static unsigned env_set = 0;
>  
>  #define ENV_IMGDIR	0x1
> @@ -65,12 +64,18 @@ static int run_shell_scripts(const char *action)
>  	}
>  
>  	if (!(env_set & ENV_ROOTPID) && root_item) {
> -		snprintf(root_item_pid, sizeof(root_item_pid), "%d", root_item->pid.real);
> -		if (setenv("CRTOOLS_INIT_PID", root_item_pid, 1)) {
> -			pr_perror("Can't set CRTOOLS_INIT_PID=%s", root_item_pid);
> -			return -1;
> +		int pid;
> +		char root_item_pid[16];
> +
> +		pid = root_item->pid.real;
> +		if (pid != -1) {
> +			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);
> +				return -1;
> +			}
> +			env_set |= ENV_ROOTPID;
>  		}
> -		env_set |= ENV_ROOTPID;
>  	}
>  
>  	list_for_each_entry(script, &scripts, node) {
> -- 
> 2.5.0
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu