startone.c revision 0a18b5458b6d0fcad9a82b96f99035254af50c7a
/* liblxcapi
*
* Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
* Copyright © 2012 Canonical Ltd.
*
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "../lxc/lxccontainer.h"
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define MYNAME "lxctest1"
static int destroy_ubuntu(void)
{
if (pid < 0) {
perror("fork");
return -1;
}
if (pid == 0) {
// Should not return
perror("execl");
exit(1);
}
if (ret == -1) {
goto again;
perror("waitpid");
return -1;
}
goto again;
return -1;
}
return WEXITSTATUS(status);
}
static int create_ubuntu(void)
{
if (pid < 0) {
perror("fork");
return -1;
}
if (pid == 0) {
ret = execlp("lxc-create", "lxc-create", "-t", "ubuntu", "-f", LXC_DEFAULT_CONFIG, "-n", MYNAME, NULL);
// Should not return
perror("execl");
exit(1);
}
if (ret == -1) {
goto again;
perror("waitpid");
return -1;
}
goto again;
return -1;
}
return WEXITSTATUS(status);
}
{
struct lxc_container *c;
int ret = 0;
const char *s;
bool b;
char buf[201];
int len;
ret = 1;
/* test a real container */
if (!c) {
ret = 1;
goto out;
}
if (c->is_defined(c)) {
goto out;
}
ret = create_ubuntu();
if (ret) {
goto out;
}
b = c->is_defined(c);
if (!b) {
goto out;
}
if (len >= 0) {
goto out;
}
if (b) {
goto out;
}
s = c->state(c);
if (!s || strcmp(s, "STOPPED")) {
fprintf(stderr, "%d: %s is in state %s, not in STOPPED.\n", __LINE__, c->name, s ? s : "undefined");
goto out;
}
b = c->load_config(c, NULL);
if (!b) {
goto out;
}
goto out;
}
printf("hit return to start container");
char mychar;
if (ret < 0)
goto out;
if (!lxc_container_get(c)) {
exit(1);
}
if (pid < 0) {
goto out;
}
if (pid == 0) {
if (!b)
exit(!b);
}
sleep(3);
s = c->state(c);
if (!s || strcmp(s, "RUNNING")) {
fprintf(stderr, "%d: %s is in state %s, not in RUNNING.\n", __LINE__, c->name, s ? s : "undefined");
goto out;
}
if (len <= 0) {
goto out;
}
goto out;
}
if (!b) {
goto out;
}
goto out;
}
printf("hit return to finish");
if (ret < 0)
goto out;
c->stop(c);
/* feh - multilib has moved the lxc-init crap */
#if 0
goto ok;
if (!ret)
if (!ret)
if (!ret)
if (!ret)
if (!ret)
if (!ret)
if (!ret)
if (ret) {
goto out;
}
// next write out the config file; does it match?
goto out;
}
// auto-check result? ('bobo' is printed on stdout)
ok:
#endif
ret = 0;
out:
if (c) {
c->stop(c);
}
}