[Devel] [PATCH 4/8] vzctl: save PID of init in a state file
Kir Kolyshkin
kir at parallels.com
Wed May 15 17:44:45 PDT 2013
On 05/15/2013 09:10 AM, Andrey Vagin wrote:
> It will be used for checkpointing this CT
>
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
> src/lib/hooks_ct.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/hooks_ct.c b/src/lib/hooks_ct.c
> index 0d4e439..3c82823 100644
> --- a/src/lib/hooks_ct.c
> +++ b/src/lib/hooks_ct.c
> @@ -86,6 +86,10 @@ static int ct_destroy(vps_handler *h, envid_t veid, const vps_res *res)
>
> snprintf(ctpath, STR_SIZE, "%s/%d", NETNS_RUN_DIR, veid);
> unlink(ctpath);
> +
> + get_state_file(veid, res->env.statedir, ctpath, sizeof(ctpath));
> + unlink(ctpath);
> +
> return destroy_container(veid);
> }
>
> @@ -230,7 +234,8 @@ static int ct_env_create_real(struct arg_start *arg)
> long stack_size;
> char *child_stack;
> int clone_flags;
> - int ret;
> + int ret, fd;
> + char pidpath[STR_SIZE];
>
> stack_size = get_pagesize();
> if (stack_size < 0)
> @@ -251,15 +256,26 @@ static int ct_env_create_real(struct arg_start *arg)
> clone_flags |= CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC;
> clone_flags |= CLONE_NEWNET|CLONE_NEWNS;
>
> + get_state_file(arg->veid, arg->res->env.statedir, pidpath, sizeof(pidpath));
> + fd = open(pidpath, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0666);
I hope you are not serious about 0666 here.
> + if (fd == -1) {
> + logger(-1, errno, "Unable to create a state file %s", pidpath);
> + return VZ_RESOURCE_ERROR;
> + }
> +
> ret = clone(_env_create, child_stack, clone_flags, arg);
> if (ret < 0) {
> + close(fd);
> logger(-1, errno, "Unable to clone");
> /* FIXME: remove ourselves from container first */
> destroy_container(arg->veid);
> return VZ_RESOURCE_ERROR;
> }
>
> - return 0;
> + dprintf(fd, "%d", ret);
> + close(fd);
> +
> + return ret;
> }
>
> int ct_env_create(struct arg_start *arg)
More information about the Devel
mailing list