open the console later

Open the console at the setup time, otherwise the openeded
file descriptor will be considered as an inherited fd and the
startup will fail.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
Daniel Lezcano 2010-03-22 11:08:34 +01:00 committed by Daniel Lezcano
parent 80090207de
commit 28a4b0e55c
4 changed files with 28 additions and 1 deletions

View File

@ -1093,6 +1093,7 @@ struct lxc_conf *lxc_conf_init(void)
new->utsname = NULL; new->utsname = NULL;
new->tty = 0; new->tty = 0;
new->pts = 0; new->pts = 0;
new->console.path = NULL;
new->console.peer = -1; new->console.peer = -1;
new->console.master = -1; new->console.master = -1;
new->console.slave = -1; new->console.slave = -1;

View File

@ -157,6 +157,7 @@ struct lxc_console {
int slave; int slave;
int master; int master;
int peer; int peer;
char *path;
char name[MAXPATHLEN]; char name[MAXPATHLEN];
struct termios *tios; struct termios *tios;
}; };

View File

@ -620,7 +620,7 @@ static int config_cap_drop(const char *key, char *value,
return ret; return ret;
} }
static int config_console(const char *key, char *value, struct lxc_conf *lxc_conf) static int _config_console(const char *key, char *value, struct lxc_conf *lxc_conf)
{ {
int fd; int fd;
@ -635,6 +635,22 @@ static int config_console(const char *key, char *value, struct lxc_conf *lxc_con
return 0; return 0;
} }
static int config_console(const char *key, char *value,
struct lxc_conf *lxc_conf)
{
char *path;
path = strdup(value);
if (!path) {
SYSERROR("failed to strdup '%s': %m", value);
return -1;
}
lxc_conf->console.path = path;
return 0;
}
static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf)
{ {
if (strlen(value) >= MAXPATHLEN) { if (strlen(value) >= MAXPATHLEN) {

View File

@ -143,6 +143,7 @@ int lxc_create_console(struct lxc_conf *conf)
{ {
struct termios tios; struct termios tios;
struct lxc_console *console = &conf->console; struct lxc_console *console = &conf->console;
int fd;
if (!conf->rootfs) if (!conf->rootfs)
return 0; return 0;
@ -163,6 +164,14 @@ int lxc_create_console(struct lxc_conf *conf)
goto err; goto err;
} }
fd = open(console->path, O_CLOEXEC | O_RDWR | O_CREAT | O_APPEND, 0600);
if (fd < 0) {
SYSERROR("failed to open '%s'", console->path);
goto err;
}
console->peer = fd;
if (!isatty(console->peer)) if (!isatty(console->peer))
return 0; return 0;