return 0;
}
-static int setup_tty(const char *rootfs, const struct lxc_tty_info *tty_info)
+static int setup_tty(const struct lxc_rootfs *rootfs,
+ const struct lxc_tty_info *tty_info)
{
char path[MAXPATHLEN];
int i;
struct lxc_pty_info *pty_info = &tty_info->pty_info[i];
snprintf(path, sizeof(path), "%s/dev/tty%d",
- rootfs ? rootfs : "", i + 1);
+ rootfs->path ? rootfs->path : "", i + 1);
/* At this point I can not use the "access" function
* to check the file is present or not because it fails
return 0;
}
-static int setup_rootfs(const char *rootfs, const char *pivotdir)
+static int setup_rootfs(const struct lxc_rootfs *rootfs)
{
const char *tmpfs = "/tmp";
- if (!rootfs)
+ if (!rootfs->path)
return 0;
- if (mount(rootfs, tmpfs, "none", MS_BIND|MS_REC, NULL)) {
- SYSERROR("failed to mount '%s'->'%s'", rootfs, "/tmp");
+ if (mount(rootfs->path, tmpfs, "none", MS_BIND|MS_REC, NULL)) {
+ SYSERROR("failed to mount '%s'->'%s'", rootfs->path, "/tmp");
return -1;
}
- DEBUG("mounted '%s' on '%s'", rootfs, tmpfs);
+ DEBUG("mounted '%s' on '%s'", rootfs->path, tmpfs);
- if (setup_rootfs_pivot_root(tmpfs, pivotdir)) {
- ERROR("failed to pivot_root to '%s'", rootfs);
+ if (setup_rootfs_pivot_root(tmpfs, rootfs->pivot)) {
+ ERROR("failed to pivot_root to '%s'", rootfs->pivot);
return -1;
}
return 0;
}
-static int setup_console(const char *rootfs, const struct lxc_console *console)
+static int setup_console(const struct lxc_rootfs *rootfs,
+ const struct lxc_console *console)
{
char path[MAXPATHLEN];
struct stat s;
/* We don't have a rootfs, /dev/console will be shared */
- if (!rootfs)
+ if (!rootfs->path)
return 0;
- snprintf(path, sizeof(path), "%s/dev/console", rootfs);
+ snprintf(path, sizeof(path), "%s/dev/console", rootfs->path);
if (access(path, F_OK)) {
WARN("rootfs specified but no console found");
return -1;
}
- if (setup_console(lxc_conf->rootfs, &lxc_conf->console)) {
+ if (setup_console(&lxc_conf->rootfs, &lxc_conf->console)) {
ERROR("failed to setup the console for '%s'", name);
return -1;
}
- if (setup_tty(lxc_conf->rootfs, &lxc_conf->tty_info)) {
+ if (setup_tty(&lxc_conf->rootfs, &lxc_conf->tty_info)) {
ERROR("failed to setup the ttys for '%s'", name);
return -1;
}
- if (setup_rootfs(lxc_conf->rootfs, lxc_conf->pivotdir)) {
+ if (setup_rootfs(&lxc_conf->rootfs)) {
ERROR("failed to set rootfs for '%s'", name);
return -1;
}
struct termios *tios;
};
+/*
+ * Defines a structure to store the rootfs location, the
+ * optionals pivot_root, rootfs mount paths
+ * @rootfs : a path to the rootfs
+ * @pivot_root : a path to a pivot_root location to be used
+ */
+struct lxc_rootfs {
+ char *path;
+ char *pivot;
+};
+
/*
* Defines the global container configuration
* @rootfs : root directory to run the container
* @console : console data
*/
struct lxc_conf {
- char *rootfs;
- char *pivotdir;
char *fstab;
int tty;
int pts;
struct lxc_list caps;
struct lxc_tty_info tty_info;
struct lxc_console console;
+ struct lxc_rootfs rootfs;
};
/*
struct lxc_console *console = &conf->console;
int fd;
- if (!conf->rootfs)
+ if (!conf->rootfs.path)
return 0;
if (!console->path)
console->name, NULL, NULL)) {
SYSERROR("failed to allocate a pty");
return -1;
- }
+ }
if (fcntl(console->master, F_SETFD, FD_CLOEXEC)) {
SYSERROR("failed to set console master to close-on-exec");
struct lxc_conf *conf = handler->conf;
struct lxc_console *console = &conf->console;
- if (!conf->rootfs) {
+ if (!conf->rootfs.path) {
INFO("no rootfs, no console.");
return 0;
}
return -1;
}
- if (snprintf(path, MAXPATHLEN, "%s/var/run/utmp", conf->rootfs) >
+ if (snprintf(path, MAXPATHLEN, "%s/var/run/utmp", conf->rootfs.path) >
MAXPATHLEN) {
ERROR("path is too long");
return -1;
char path[MAXPATHLEN];
int fd, wd;
- if (!conf->rootfs)
+ if (!conf->rootfs.path)
return 0;
- if (snprintf(path, MAXPATHLEN, "%s/var/run/utmp", conf->rootfs) >
+ if (snprintf(path, MAXPATHLEN, "%s/var/run/utmp", conf->rootfs.path) >
MAXPATHLEN) {
ERROR("path is too long");
return -1;