]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
criu: rework init pid retrieval
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 10 Feb 2021 11:50:20 +0000 (12:50 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 10 Feb 2021 11:52:30 +0000 (12:52 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/criu.c

index c8e51a8d783d678fb900b1a1a58ff09089c40c69..c5d70aa229c9b73202e79a9df63f9b183a25e79e 100644 (file)
@@ -373,13 +373,20 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
        }
 
        if (strcmp(opts->action, "dump") == 0 || strcmp(opts->action, "pre-dump") == 0) {
-               char pid[32], *freezer_relative;
+               pid_t init_pid;
+               char init_pid_str[INTTYPE_TO_STRLEN(int)];
+               char *freezer_relative;
 
-               if (sprintf(pid, "%d", opts->c->init_pid(opts->c)) < 0)
-                       return log_error_errno(-EIO, EIO, "Failed to create init pid entry");
+               init_pid = opts->c->init_pid(opts->c);
+               if (init_pid < 0)
+                       return log_error_errno(-ESRCH, ESRCH, "Failed to retrieve init pid of container");
+
+               ret = snprintf(init_pid_str, sizeof(init_pid_str), "%d", init_pid);
+               if (ret < 0 || (size_t)ret >= sizeof(init_pid_str))
+                       return log_error_errno(-EIO, EIO, "Failed to create entry for init pid of container");
 
                DECLARE_ARG("-t");
-               DECLARE_ARG(pid);
+               DECLARE_ARG(init_pid_str);
 
                freezer_relative = lxc_cmd_get_limiting_cgroup_path(opts->c->name,
                                                                    opts->c->config_path,