]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Make possible to daemonize lxc-start
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Sun, 7 Jun 2009 19:48:46 +0000 (21:48 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Sun, 7 Jun 2009 19:48:46 +0000 (21:48 +0200)
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>
doc/lxc-start.sgml.in
src/lxc/arguments.h
src/lxc/lxc_start.c

index 34a983707a55295213b0b49931fe99696e83ce48..7a92519ad6489d5c3a9372b1bc6d104beca1174a 100644 (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>
index 9b7fbf5542a86dd1d3cbb8ca7a43ffefa2cf9160..ffb436fe35c87551ced919fe7c1e5c792b82ede6 100644 (file)
@@ -42,6 +42,7 @@ struct lxc_arguments {
        char *log_file;
        char *log_priority;
        int quiet;
+       int daemonize;
        const char *rcfile;
        const char *statefile;
 
index 8db3bd3c703e318db75154057d88fdb63c8c2368..b5a34a7b5fee1a59006ba3c65bab4ed1f2cbca27 100644 (file)
 #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>
 
 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);