All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Lezcano <dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
To: Sukadev Bhattiprolu
	<sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Cc: Containers
	<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	clg-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH 4/5][lxc] Hook up lxc_restart() with app_restart()
Date: Mon, 22 Mar 2010 15:48:48 +0100	[thread overview]
Message-ID: <4BA78350.3080402@fr.ibm.com> (raw)
In-Reply-To: <20100319064121.GE25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

Sukadev Bhattiprolu wrote:
> From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> Date: Thu, 11 Mar 2010 20:47:56 -0800
> Subject: [PATCH 4/5][lxc] Hook up lxc_restart() with app_restart()
> 
> Have lxc_restart() call app_restart() implemented in the 'restart.o' from
> USER-CR git tree.
> 
> Changelog[v2]:
> 	- Link with restart.o from usercr rather than libcheckpoint.a
> 	- rename 'struct restart_args' to 'struct app_restart_args'
> 	- Initialize the new field app_restart_args->uerrfd
> 	- (Oren Laadan)Remove ->send_sigint field from 'struct app_restart_args'
> ---
>  src/lxc/restart.c |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 104 insertions(+), 0 deletions(-)
> 
> diff --git a/src/lxc/restart.c b/src/lxc/restart.c
> index 467489e..945435c 100644
> --- a/src/lxc/restart.c
> +++ b/src/lxc/restart.c
> @@ -22,11 +22,115 @@
>   */
>  #include <lxc/lxc.h>
>  #include <lxc/log.h>
> +#include <lxc/start.h>
> +#include <lxc/namespace.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <signal.h>
> +#include <sys/prctl.h>
> +#include <app-checkpoint.h>
> +
> +struct lxc_restart_arg {
> +	const char *name;
> +	const char *statefile;
> +	char *const argv;
> +	struct lxc_handler *handler;
> +};
> 
>  lxc_log_define(lxc_restart, lxc);
> 
> +static int do_restart(struct lxc_restart_arg *lxcarg)
> +{
> +	int pid;
> +	struct lxc_handler *handler = lxcarg->handler;
> +	const char *name = lxcarg->name;
> +	char *const argv = lxcarg->argv;
> +	const char *statefile = lxcarg->statefile;
> +	struct app_restart_args restart_args;
> +
> +        if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) {
> +                SYSERROR("failed to set sigprocmask");
> +                return -1;
> +        }
> +
> +        if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) {
> +                SYSERROR("failed to set pdeath signal");
> +                return -1;
> +        }
> +
> +	memset(&restart_args, 0, sizeof(restart_args));
> +
> +	if (statefile) {

Why do you need to check if statefile is valid ? It's a mandatory 
option, no ? if it is not specified, we should not reach this point.

> +		restart_args.infd = open(statefile, O_RDONLY, 0);
> +		if (restart_args.infd < 0) {
> +			SYSERROR("Failed to open statefile %s\n", statefile);
> +			return -1;
> +		}
> +	}
> +
> +	restart_args.pids = 1;
> +	restart_args.pidns = 1;
> +	restart_args.mnt_pty = 1;
> +	restart_args.mntns = 1;
> +	restart_args.klogfd = -1;
> +	restart_args.ulogfd = lxc_log_fd;
> +	restart_args.uerrfd = fileno(stderr);
> +	restart_args.debug = 1;
> +	restart_args.wait = 0;
> +
> +        pid = app_restart(&restart_args);
> +
> +        return pid;
> +}
> +
>  int lxc_restart(const char *name, const char *statefile, struct lxc_conf *conf,
>  		int flags)
>  {
> +	int err;
> +	int status;
> +	struct lxc_handler *handler;
> +	struct lxc_restart_arg lxcarg = {
> +		.name = name,
> +		.statefile = statefile,
> +		.handler = NULL,
> +	};
> +
> +	handler = lxc_init(name, conf);
> +	if (!handler) {
> +		ERROR("failed to initialize the container");
> +		return -1;
> +	}
> +
> +	lxcarg.handler = handler;
> +	handler->pid = do_restart(&lxcarg);
> +
> +	INFO("do_restart(): returns pid %d\n", handler->pid);
> +	lxc_rename_nsgroup(name, handler);
> +
> +	err = lxc_close_all_inherited_fd();
> +	if (err) {
> +		ERROR("unable to close inherited fds");
> +		goto out_abort;
> +	}

A small change here, recently committed. Now we check there is *no* 
inherited fd at this point instead of trying to detect them.

> +	err = lxc_poll(name, handler);
> +	if (err) {
> +		ERROR("mainloop exited with an error");
> +		goto out_abort;
> +	}
> +
> +	while (waitpid(handler->pid, &status, 0) < 0 && errno == EINTR)
> +		continue;
> +
> +	err =  lxc_error_set_and_log(handler->pid, status);
> +
> +out_fini:
> +	lxc_fini(name, handler);
> +	return err;
> +
> +out_abort:
> +	lxc_abort(name, handler);
> +	goto out_fini;
> +
>  	return 0;
>  }

  parent reply	other threads:[~2010-03-22 14:48 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-19  6:39 [RFC][PATCH 0/5][lxc]: Link with USERCR Sukadev Bhattiprolu
     [not found] ` <20100319063912.GA25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-19  6:40   ` [PATCH 1/5][lxc] Enable static linking of some lxc binaries Sukadev Bhattiprolu
     [not found]     ` <20100319064024.GB25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:44       ` Daniel Lezcano
2010-03-19  6:40   ` [PATCH 2/5][lxc] lxc_restart: Add --image option Sukadev Bhattiprolu
     [not found]     ` <20100319064046.GC25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:45       ` Daniel Lezcano
     [not found]         ` <4BA78276.2040308-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-24 19:48           ` Sukadev Bhattiprolu
     [not found]             ` <20100324194851.GD20031-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-24 20:53               ` Daniel Lezcano
2010-03-19  6:41   ` [PATCH 3/5][lxc] lxc_checkpoint: " Sukadev Bhattiprolu
2010-03-19  6:41   ` [PATCH 4/5][lxc] Hook up lxc_restart() with app_restart() Sukadev Bhattiprolu
     [not found]     ` <20100319064121.GE25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:48       ` Daniel Lezcano [this message]
2010-03-19  6:41   ` [PATCH 5/5][lxc] Hook up lxc_checkpoint() with app_checkpoint() Sukadev Bhattiprolu
     [not found]     ` <20100319064141.GF25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:44       ` Daniel Lezcano
     [not found]         ` <4BA78262.6050109-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-24 19:35           ` Sukadev Bhattiprolu
     [not found]             ` <20100324193537.GB20031-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-24 20:51               ` Daniel Lezcano
2010-03-19 10:44   ` [RFC][PATCH 0/5][lxc]: Link with USERCR Michel Normand
2010-03-24 19:22     ` Sukadev Bhattiprolu
2010-03-22 14:45   ` Daniel Lezcano
     [not found]     ` <4BA7826D.10706-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-24 19:27       ` Oren Laadan
2010-03-24 19:47       ` Sukadev Bhattiprolu
     [not found]         ` <20100324194744.GC20031-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-24 20:52           ` Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BA78350.3080402@fr.ibm.com \
    --to=dlezcano-nmtc/0zbporqt0dzr+alfa@public.gmane.org \
    --cc=clg-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.