lxcpath.c revision 8cd80b50efe2107ac351bfd0285050dd183398e7
168N/A/* liblxcapi
168N/A *
168N/A * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
168N/A * Copyright © 2012 Canonical Ltd.
168N/A *
168N/A * This program is free software; you can redistribute it and/or modify
168N/A * it under the terms of the GNU General Public License version 2, as
168N/A * published by the Free Software Foundation.
168N/A *
168N/A * This program is distributed in the hope that it will be useful,
168N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
168N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168N/A * GNU General Public License for more details.
168N/A *
168N/A * You should have received a copy of the GNU General Public License along
168N/A * with this program; if not, write to the Free Software Foundation, Inc.,
168N/A * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
168N/A */
168N/A#include <lxc/lxccontainer.h>
168N/A
168N/A#include <unistd.h>
168N/A#include <signal.h>
168N/A#include <stdio.h>
168N/A#include <sys/types.h>
168N/A#include <sys/wait.h>
168N/A#include <stdlib.h>
168N/A#include <errno.h>
168N/A
168N/A#define MYNAME "lxctest1"
168N/A
168N/A#define TSTERR(x) do { \
168N/A fprintf(stderr, "%d: %s\n", __LINE__, x); \
168N/A} while (0)
168N/A
168N/Aint main()
168N/A{
168N/A struct lxc_container *c;
168N/A const char *p1, *p2;
168N/A int retval = -1;
168N/A
168N/A c = lxc_container_new(MYNAME, NULL);
168N/A if (!c) {
168N/A TSTERR("create using default path");
168N/A goto err;
168N/A }
168N/A p1 = c->get_config_path(c);
168N/A p2 = c->config_file_name(c);
168N/A if (!p1 || !p2 || strncmp(p1, p2, strlen(p1))) {
168N/A TSTERR("Bad result for path names");
168N/A goto err;
168N/A }
168N/A
168N/A#define CPATH "/boo"
168N/A#define FPATH "/boo/lxctest1/config"
168N/A if (!c->set_config_path(c, "/boo")) {
168N/A TSTERR("Error setting custom path");
168N/A goto err;
168N/A }
168N/A p1 = c->get_config_path(c);
168N/A p2 = c->config_file_name(c);
168N/A if (strcmp(p1, CPATH) || strcmp(p2, FPATH)) {
168N/A TSTERR("Bad result for path names after set_config_path()");
168N/A goto err;
168N/A }
lxc_container_put(c);
c = lxc_container_new(MYNAME, CPATH);
if (!c) {
TSTERR("create using custom path");
goto err;
}
p1 = c->get_config_path(c);
p2 = c->config_file_name(c);
if (strcmp(p1, CPATH) || strcmp(p2, FPATH)) {
TSTERR("Bad result for path names after create with custom path");
goto err;
}
retval = 0;
err:
lxc_container_put(c);
return retval;
}