Commit 28a4b0e5 by Daniel Lezcano Committed by Daniel Lezcano

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 80090207
...@@ -1093,6 +1093,7 @@ struct lxc_conf *lxc_conf_init(void) ...@@ -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;
......
...@@ -157,6 +157,7 @@ struct lxc_console { ...@@ -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;
}; };
......
...@@ -620,7 +620,7 @@ static int config_cap_drop(const char *key, char *value, ...@@ -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 ...@@ -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) {
......
...@@ -143,6 +143,7 @@ int lxc_create_console(struct lxc_conf *conf) ...@@ -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) ...@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment