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 <dlezcano@fr.ibm.com>
This commit is contained in:
Daniel Lezcano 2009-06-07 21:48:46 +02:00
parent f8e09a0b76
commit c36583c303
3 changed files with 46 additions and 5 deletions

View File

@ -74,6 +74,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</refsect1>
<refsect1>
<title>Options</title>
<variablelist>
<varlistentry>
<term>
<option>-d, --daemon</option>
</term>
<listitem>
<para>
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.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
&commonoptions;
<refsect1>
@ -102,7 +125,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@ -42,6 +42,7 @@ struct lxc_arguments {
char *log_file;
char *log_priority;
int quiet;
int daemonize;
const char *rcfile;
const char *statefile;

View File

@ -26,11 +26,13 @@
#include <string.h>
#include <termios.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/param.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <net/if.h>
@ -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",
-n, --name=NAME NAME for name of the container\n\
-d, --daemon daemonize the container",
.options = my_longopts,
.parser = NULL,
.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);