From: Daniel Lezcano Date: Sun, 7 Jun 2009 19:48:46 +0000 (+0200) Subject: Make possible to daemonize lxc-start X-Git-Tag: lxc_0_6_3~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c36583c3034ca430c98fc0b5afe6e8f0c6511258;p=thirdparty%2Flxc.git Make possible to daemonize lxc-start If needed the container can be launched in background with a specific option -d. That will make mute the container, the logs can help to check what went wrong. Signed-off-by: Daniel Lezcano --- diff --git a/doc/lxc-start.sgml.in b/doc/lxc-start.sgml.in index 34a983707..7a92519ad 100644 --- a/doc/lxc-start.sgml.in +++ b/doc/lxc-start.sgml.in @@ -74,6 +74,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Options + + + + + + + + + + Run the container as a daemon. As the container has no + more tty, if an error occurs nothing will be displayed, + the log file can be used to check the error. + + + + + + + + &commonoptions; @@ -102,7 +125,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - diff --git a/src/lxc/arguments.h b/src/lxc/arguments.h index 9b7fbf554..ffb436fe3 100644 --- a/src/lxc/arguments.h +++ b/src/lxc/arguments.h @@ -42,6 +42,7 @@ struct lxc_arguments { char *log_file; char *log_priority; int quiet; + int daemonize; const char *rcfile; const char *statefile; diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c index 8db3bd3c7..b5a34a7b5 100644 --- a/src/lxc/lxc_start.c +++ b/src/lxc/lxc_start.c @@ -26,11 +26,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -41,7 +43,16 @@ lxc_log_define(lxc_start, lxc); +static int my_parser(struct lxc_arguments* args, int c, char* arg) +{ + switch (c) { + case 'd': args->daemonize = 1; break; + } + return 0; +} + static const struct option my_longopts[] = { + {"daemon", no_argument, 0, 'd'}, LXC_COMMON_OPTIONS }; @@ -53,10 +64,12 @@ static struct lxc_arguments my_args = { lxc-start start COMMAND in specified container NAME\n\ \n\ Options :\n\ - -n, --name=NAME NAME for name of the container", - .options = my_longopts, - .parser = NULL, - .checker = NULL, + -n, --name=NAME NAME for name of the container\n\ + -d, --daemon daemonize the container", + .options = my_longopts, + .parser = my_parser, + .checker = NULL, + .daemonize = 0, }; static int save_tty(struct termios *tios) @@ -122,6 +135,11 @@ int main(int argc, char *argv[]) my_args.progname, my_args.quiet)) return err; + if (my_args.daemonize && daemon(0 ,0)) { + SYSERROR("failed to daemonize '%s'", my_args.name); + return err; + } + save_tty(&tios); err = lxc_start(my_args.name, args);