[CRIU] [PATCH] criu: action-scripts -- Don't access @root_item_pid if not present

Cyrill Gorcunov gorcunov at gmail.com
Thu Apr 14 09:04:13 PDT 2016


It might be nil on predump, so dereference only when present.

Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
 criu/action-scripts.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/criu/action-scripts.c b/criu/action-scripts.c
index db3bfc3..addc833 100644
--- a/criu/action-scripts.c
+++ b/criu/action-scripts.c
@@ -48,10 +48,12 @@ int run_scripts(enum script_actions act)
 		return -1;
 	}
 
-	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;
+	if (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;
+		}
 	}
 
 	list_for_each_entry(script, &opts.scripts, node) {
-- 
2.5.5



More information about the CRIU mailing list