From: Daniel Lezcano Date: Wed, 29 Apr 2009 15:49:04 +0000 (+0200) Subject: export-fine-grain-api-for-start X-Git-Tag: lxc_0_6_3~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bc5cc8c0bf725d2baa518db1e2df80cbdff5bd8;p=thirdparty%2Flxc.git export-fine-grain-api-for-start Export the fine grain api of lxc to be usable for external component which wants to have more control on the container. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index fe974d216..09a981c72 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -4,6 +4,7 @@ INCLUDES= -I$(top_srcdir)/src -DLXCPATH="\"@LXCPATH@\"" \ AM_LDFLAGS= -lutil lib_LTLIBRARIES = liblxc.la pkginclude_HEADERS = \ + start.h \ error.h \ monitor.h \ utils.h \ diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index e37467804..2f45523ff 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -43,6 +43,7 @@ extern "C" { #include #include #include +#include /* * Create the container object. Creates the /lxc/ directory diff --git a/src/lxc/start.c b/src/lxc/start.c index 2b75c384b..7c6e4faee 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -98,15 +98,6 @@ lxc_log_define(lxc_start, lxc); LXC_TTY_HANDLER(SIGINT); LXC_TTY_HANDLER(SIGQUIT); -struct lxc_handler { - int sigfd; - int lock; - pid_t pid; - char tty[MAXPATHLEN]; - sigset_t oldmask; - struct lxc_tty_info tty_info; -}; - static int setup_sigchld_fd(sigset_t *oldmask) { sigset_t mask; @@ -238,7 +229,7 @@ out_close: goto out; } -static int lxc_poll(const char *name, struct lxc_handler *handler) +int lxc_poll(const char *name, struct lxc_handler *handler) { int sigfd = handler->sigfd; int pid = handler->pid; @@ -331,7 +322,7 @@ static void remove_init_pid(const char *name, pid_t pid) unlink(init); } -static int lxc_init(const char *name, struct lxc_handler *handler) +int lxc_init(const char *name, struct lxc_handler *handler) { int err = -1; @@ -382,7 +373,7 @@ out_put_lock: goto out; } -static void lxc_fini(const char *name, struct lxc_handler *handler) +void lxc_fini(const char *name, struct lxc_handler *handler) { /* The STOPPING state is there for future cleanup code * which can take awhile @@ -403,13 +394,13 @@ static void lxc_fini(const char *name, struct lxc_handler *handler) LXC_TTY_DEL_HANDLER(SIGINT); } -static void lxc_abort(const char *name, struct lxc_handler *handler) +void lxc_abort(const char *name, struct lxc_handler *handler) { lxc_setstate(name, ABORTING); kill(handler->pid, SIGKILL); } -static int lxc_spawn(const char *name, struct lxc_handler *handler, char *argv[]) +int lxc_spawn(const char *name, struct lxc_handler *handler, char *argv[]) { int sv[2]; int clone_flags; @@ -560,8 +551,8 @@ int lxc_start(const char *name, char *argv[]) goto out_abort; } - waitpid(handler.pid, &status, 0); - + while (waitpid(handler.pid, &status, 0) < 0 && errno == EINTR) + continue; err = 0; out: lxc_fini(name, &handler); diff --git a/src/lxc/start.h b/src/lxc/start.h new file mode 100644 index 000000000..9eccc331c --- /dev/null +++ b/src/lxc/start.h @@ -0,0 +1,42 @@ +/* + * lxc: linux Container library + * + * (C) Copyright IBM Corp. 2007, 2008 + * + * Authors: + * Daniel Lezcano + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +struct lxc_handler { + int sigfd; + int lock; + pid_t pid; + char tty[MAXPATHLEN]; + sigset_t oldmask; + struct lxc_tty_info tty_info; +}; + +extern int lxc_init(const char *name, struct lxc_handler *handler); +extern int lxc_spawn(const char *name, struct lxc_handler *handler, + char *argv[]); + +extern int lxc_poll(const char *name, struct lxc_handler *handler); +extern void lxc_abort(const char *name, struct lxc_handler *handler); +extern void lxc_fini(const char *name, struct lxc_handler *handler); + + +